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
24 /*
25 * @test
26 * @bug 8202771 8221431
27 * @summary Check j.l.Character.isDigit/isLetter/isLetterOrDigit/isSpaceChar
28 * /isWhitespace/isTitleCase/isISOControl/isIdentifierIgnorable
29 * /isJavaIdentifierStart/isJavaIdentifierPart/isUnicodeIdentifierStart
30 * /isUnicodeIdentifierPart
31 * @library /lib/testlibrary/java/lang
32 * @run main CharPropTest
33 */
34
35 import java.nio.file.Files;
36 import java.util.stream.Stream;
37
38 public class CharPropTest {
39 private static int diffs = 0;
40 private static int rangeStart = 0x0000;
41 private static boolean isRange = false;
42
43 public static void main(String[] args) throws Exception {
44 try (Stream<String> lines = Files.lines(UCDFiles.UNICODE_DATA)) {
45 lines.map(String::trim)
46 .filter(line -> line.length() != 0 && line.charAt(0) != '#')
165 }
166
167 private static void isJavaIdentifierStartTest(int codePoint, String category) {
168 boolean actual = Character.isJavaIdentifierStart(codePoint);
169 boolean expected = isJavaIdentifierStart(category);
170 if (actual != expected) {
171 printDiff(codePoint, "isJavaIdentifierStart", actual, expected);
172 }
173 }
174
175 private static void isJavaIdentifierPartTest(int codePoint, String category) {
176 boolean actual = Character.isJavaIdentifierPart(codePoint);
177 boolean expected = isJavaIdentifierPart(codePoint, category);
178 if (actual != expected) {
179 printDiff(codePoint, "isJavaIdentifierPart", actual, expected);
180 }
181 }
182
183 private static void isUnicodeIdentifierStartTest(int codePoint, String category) {
184 boolean actual = Character.isUnicodeIdentifierStart(codePoint);
185 boolean expected = isUnicodeIdentifierStart(category);
186 if (actual != expected) {
187 printDiff(codePoint, "isUnicodeIdentifierStart", actual, expected);
188 }
189 }
190
191 private static void isUnicodeIdentifierPartTest(int codePoint, String category) {
192 boolean actual = Character.isUnicodeIdentifierPart(codePoint);
193 boolean expected = isUnicodeIdentifierPart(codePoint, category);
194 if (actual != expected) {
195 printDiff(codePoint, "isUnicodeIdentifierPart", actual, expected);
196 }
197 }
198
199 private static boolean isLetter(String category) {
200 return category.equals("Lu") || category.equals("Ll")
201 || category.equals("Lt") || category.equals("Lm")
202 || category.equals("Lo");
203 }
204
205 private static boolean isSpaceChar(String category) {
249 || (codePoint > c1 && codePoint < c2) || (codePoint == a1 || codePoint == a2
250 || codePoint == b1 || codePoint == b2 || codePoint == c1 || codePoint == c2)) {
251 return true;
252 }
253 }
254 return false;
255 }
256
257 private static boolean isJavaIdentifierStart(String category) {
258 return isLetter(category) || category.equals("Nl") || category.equals("Sc")
259 || category.equals("Pc");
260 }
261
262 private static boolean isJavaIdentifierPart(int codePoint, String category) {
263 return isLetter(category) || category.equals("Sc") || category.equals("Pc")
264 || category.equals("Nd") || category.equals("Nl")
265 || category.equals("Mc") || category.equals("Mn")
266 || isIdentifierIgnorable(codePoint, category);
267 }
268
269 private static boolean isUnicodeIdentifierStart(String category) {
270 return isLetter(category) || category.equals("Nl");
271 }
272
273 private static boolean isUnicodeIdentifierPart(int codePoint, String category) {
274 return isLetter(category) || category.equals("Pc") || category.equals("Nd")
275 || category.equals("Nl") || category.equals("Mc") || category.equals("Mn")
276 || isIdentifierIgnorable(codePoint, category);
277 }
278
279 private static void printDiff(int codePoint, String method, boolean actual, boolean expected) {
280 System.out.println("Not equal at codePoint <" + Integer.toHexString(codePoint)
281 + ">, method: " + method
282 + ", actual: " + actual + ", expected: " + expected);
283 diffs++;
284 }
285 }
|
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
24 /*
25 * @test
26 * @bug 8202771 8221431 8229831
27 * @summary Check j.l.Character.isDigit/isLetter/isLetterOrDigit/isSpaceChar
28 * /isWhitespace/isTitleCase/isISOControl/isIdentifierIgnorable
29 * /isJavaIdentifierStart/isJavaIdentifierPart/isUnicodeIdentifierStart
30 * /isUnicodeIdentifierPart
31 * @library /lib/testlibrary/java/lang
32 * @run main CharPropTest
33 */
34
35 import java.nio.file.Files;
36 import java.util.stream.Stream;
37
38 public class CharPropTest {
39 private static int diffs = 0;
40 private static int rangeStart = 0x0000;
41 private static boolean isRange = false;
42
43 public static void main(String[] args) throws Exception {
44 try (Stream<String> lines = Files.lines(UCDFiles.UNICODE_DATA)) {
45 lines.map(String::trim)
46 .filter(line -> line.length() != 0 && line.charAt(0) != '#')
165 }
166
167 private static void isJavaIdentifierStartTest(int codePoint, String category) {
168 boolean actual = Character.isJavaIdentifierStart(codePoint);
169 boolean expected = isJavaIdentifierStart(category);
170 if (actual != expected) {
171 printDiff(codePoint, "isJavaIdentifierStart", actual, expected);
172 }
173 }
174
175 private static void isJavaIdentifierPartTest(int codePoint, String category) {
176 boolean actual = Character.isJavaIdentifierPart(codePoint);
177 boolean expected = isJavaIdentifierPart(codePoint, category);
178 if (actual != expected) {
179 printDiff(codePoint, "isJavaIdentifierPart", actual, expected);
180 }
181 }
182
183 private static void isUnicodeIdentifierStartTest(int codePoint, String category) {
184 boolean actual = Character.isUnicodeIdentifierStart(codePoint);
185 boolean expected = isUnicodeIdentifierStart(codePoint, category);
186 if (actual != expected) {
187 printDiff(codePoint, "isUnicodeIdentifierStart", actual, expected);
188 }
189 }
190
191 private static void isUnicodeIdentifierPartTest(int codePoint, String category) {
192 boolean actual = Character.isUnicodeIdentifierPart(codePoint);
193 boolean expected = isUnicodeIdentifierPart(codePoint, category);
194 if (actual != expected) {
195 printDiff(codePoint, "isUnicodeIdentifierPart", actual, expected);
196 }
197 }
198
199 private static boolean isLetter(String category) {
200 return category.equals("Lu") || category.equals("Ll")
201 || category.equals("Lt") || category.equals("Lm")
202 || category.equals("Lo");
203 }
204
205 private static boolean isSpaceChar(String category) {
249 || (codePoint > c1 && codePoint < c2) || (codePoint == a1 || codePoint == a2
250 || codePoint == b1 || codePoint == b2 || codePoint == c1 || codePoint == c2)) {
251 return true;
252 }
253 }
254 return false;
255 }
256
257 private static boolean isJavaIdentifierStart(String category) {
258 return isLetter(category) || category.equals("Nl") || category.equals("Sc")
259 || category.equals("Pc");
260 }
261
262 private static boolean isJavaIdentifierPart(int codePoint, String category) {
263 return isLetter(category) || category.equals("Sc") || category.equals("Pc")
264 || category.equals("Nd") || category.equals("Nl")
265 || category.equals("Mc") || category.equals("Mn")
266 || isIdentifierIgnorable(codePoint, category);
267 }
268
269 private static boolean isUnicodeIdentifierStart(int codePoint, String category) {
270 return isLetter(category) || category.equals("Nl")
271 || isOtherIDStart(codePoint);
272 }
273
274 private static boolean isUnicodeIdentifierPart(int codePoint, String category) {
275 return isLetter(category) || category.equals("Pc") || category.equals("Nd")
276 || category.equals("Nl") || category.equals("Mc") || category.equals("Mn")
277 || isIdentifierIgnorable(codePoint, category)
278 || isOtherIDStart(codePoint)
279 || isOtherIDContinue(codePoint);
280 }
281
282 private static boolean isOtherIDStart(int codePoint) {
283 return codePoint == 0x1885 ||
284 codePoint == 0x1886 ||
285 codePoint == 0x2118 ||
286 codePoint == 0x212E ||
287 codePoint == 0x309B ||
288 codePoint == 0x309C;
289 }
290
291 private static boolean isOtherIDContinue(int codePoint) {
292 return codePoint == 0x00B7 ||
293 codePoint == 0x0387 ||
294 (codePoint >= 0x1369 && codePoint <= 0x1371) ||
295 codePoint == 0x19DA;
296 }
297
298 private static void printDiff(int codePoint, String method, boolean actual, boolean expected) {
299 System.out.println("Not equal at codePoint <" + Integer.toHexString(codePoint)
300 + ">, method: " + method
301 + ", actual: " + actual + ", expected: " + expected);
302 diffs++;
303 }
304 }
|