author | jlaskey |
Thu, 14 Nov 2019 12:33:47 -0400 | |
branch | jlaskey-prng |
changeset 59084 | b8fb85ee91e9 |
parent 55013 | 8dae495a59e7 |
permissions | -rw-r--r-- |
9250 | 1 |
/* |
55013 | 2 |
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. |
9250 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
5610 | 24 |
/** |
25 |
* @test |
|
55013 | 26 |
* @bug 6945564 6959267 7033561 7070436 7198195 8032446 8072600 8221431 |
5610 | 27 |
* @summary Check that the j.l.Character.UnicodeScript |
55013 | 28 |
* @library /lib/testlibrary/java/lang |
5610 | 29 |
*/ |
30 |
||
31 |
import java.io.*; |
|
32 |
import java.util.*; |
|
33 |
import java.util.regex.*; |
|
34 |
import java.lang.Character.UnicodeScript; |
|
35 |
||
36 |
public class CheckScript { |
|
37 |
||
9250 | 38 |
public static void main(String[] args) throws Exception { |
39 |
File fScripts; |
|
40 |
File fAliases; |
|
7247 | 41 |
if (args.length == 0) { |
55013 | 42 |
fScripts = UCDFiles.SCRIPTS.toFile(); |
43 |
fAliases = UCDFiles.PROPERTY_VALUE_ALIASES.toFile(); |
|
9250 | 44 |
} else if (args.length == 2) { |
45 |
fScripts = new File(args[0]); |
|
46 |
fAliases = new File(args[1]); |
|
7247 | 47 |
} else { |
9250 | 48 |
System.out.println("java CharacterScript Scripts.txt PropertyValueAliases.txt"); |
7247 | 49 |
throw new RuntimeException("Datafile name should be specified."); |
5610 | 50 |
} |
8543
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
51 |
|
5610 | 52 |
Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s+;\\s+(\\w+)\\s+#.*").matcher(""); |
53 |
String line = null; |
|
54 |
HashMap<String,ArrayList<Integer>> scripts = new HashMap<>(); |
|
9250 | 55 |
try (BufferedReader sbfr = new BufferedReader(new FileReader(fScripts))) { |
8543
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
56 |
while ((line = sbfr.readLine()) != null) { |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
57 |
if (line.length() <= 1 || line.charAt(0) == '#') { |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
58 |
continue; |
5610 | 59 |
} |
8543
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
60 |
m.reset(line); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
61 |
if (m.matches()) { |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
62 |
int start = Integer.parseInt(m.group(1), 16); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
63 |
int end = (m.group(2)==null)?start |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
64 |
:Integer.parseInt(m.group(2), 16); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
65 |
String name = m.group(3).toLowerCase(Locale.ENGLISH); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
66 |
ArrayList<Integer> ranges = scripts.get(name); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
67 |
if (ranges == null) { |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
68 |
ranges = new ArrayList<Integer>(); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
69 |
scripts.put(name, ranges); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
70 |
} |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
71 |
ranges.add(start); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
72 |
ranges.add(end); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7247
diff
changeset
|
73 |
} |
5610 | 74 |
} |
75 |
} |
|
76 |
// check all defined ranges |
|
77 |
Integer[] ZEROSIZEARRAY = new Integer[0]; |
|
78 |
for (String name : scripts.keySet()) { |
|
79 |
System.out.println("Checking " + name + "..."); |
|
80 |
Integer[] ranges = scripts.get(name).toArray(ZEROSIZEARRAY); |
|
81 |
Character.UnicodeScript expected = |
|
82 |
Character.UnicodeScript.forName(name); |
|
83 |
||
84 |
int off = 0; |
|
85 |
while (off < ranges.length) { |
|
86 |
int start = ranges[off++]; |
|
87 |
int end = ranges[off++]; |
|
88 |
for (int cp = start; cp <= end; cp++) { |
|
89 |
Character.UnicodeScript script = |
|
90 |
Character.UnicodeScript.of(cp); |
|
91 |
if (script != expected) { |
|
92 |
throw new RuntimeException( |
|
93 |
"UnicodeScript failed: cp=" + |
|
94 |
Integer.toHexString(cp) + |
|
95 |
", of(cp)=<" + script + "> but <" + |
|
96 |
expected + "> is expected"); |
|
97 |
} |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
// check all codepoints |
|
102 |
for (int cp = 0; cp < Character.MAX_CODE_POINT; cp++) { |
|
103 |
Character.UnicodeScript script = Character.UnicodeScript.of(cp); |
|
104 |
if (script == Character.UnicodeScript.UNKNOWN) { |
|
105 |
if (Character.getType(cp) != Character.UNASSIGNED && |
|
106 |
Character.getType(cp) != Character.SURROGATE && |
|
107 |
Character.getType(cp) != Character.PRIVATE_USE) |
|
108 |
throw new RuntimeException( |
|
109 |
"UnicodeScript failed: cp=" + |
|
110 |
Integer.toHexString(cp) + |
|
111 |
", of(cp)=<" + script + "> but UNKNOWN is expected"); |
|
112 |
} else { |
|
113 |
Integer[] ranges = |
|
114 |
scripts.get(script.name().toLowerCase(Locale.ENGLISH)) |
|
115 |
.toArray(ZEROSIZEARRAY); |
|
116 |
int off = 0; |
|
117 |
boolean found = false; |
|
118 |
while (off < ranges.length) { |
|
119 |
int start = ranges[off++]; |
|
120 |
int end = ranges[off++]; |
|
121 |
if (cp >= start && cp <= end) |
|
122 |
found = true; |
|
123 |
} |
|
124 |
if (!found) { |
|
125 |
throw new RuntimeException( |
|
126 |
"UnicodeScript failed: cp=" + |
|
127 |
Integer.toHexString(cp) + |
|
128 |
", of(cp)=<" + script + |
|
129 |
"> but NOT in ranges of this script"); |
|
130 |
||
131 |
} |
|
132 |
} |
|
133 |
} |
|
9250 | 134 |
// check all aliases |
135 |
m = Pattern.compile("sc\\s*;\\s*(\\p{Alpha}{4})\\s*;\\s*([\\p{Alpha}|_]+)\\s*.*").matcher(""); |
|
136 |
line = null; |
|
137 |
try (BufferedReader sbfr = new BufferedReader(new FileReader(fAliases))) { |
|
138 |
while ((line = sbfr.readLine()) != null) { |
|
139 |
if (line.length() <= 1 || line.charAt(0) == '#') { |
|
140 |
continue; |
|
141 |
} |
|
142 |
m.reset(line); |
|
143 |
if (m.matches()) { |
|
144 |
String alias = m.group(1); |
|
145 |
String name = m.group(2); |
|
146 |
// HRKT -> Katakana_Or_Hiragana not supported |
|
147 |
if ("HRKT".equals(alias.toUpperCase(Locale.ENGLISH))) |
|
148 |
continue; |
|
149 |
if (Character.UnicodeScript.forName(alias) != |
|
150 |
Character.UnicodeScript.forName(name)) { |
|
151 |
throw new RuntimeException( |
|
152 |
"UnicodeScript failed: alias<" + alias + |
|
153 |
"> does not map to <" + name + ">"); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
5610 | 158 |
} |
159 |
} |