blob: db511f9cc6b27e4498584f96c371bcaf5a48cddf [file] [log] [blame]
sherman47083992011-04-28 20:18:57 -07001/*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
24
25/**
26 * @test
peytoiaf693e4d2012-03-29 18:02:36 +090027 * @bug 7037261 7070436
sherman47083992011-04-28 20:18:57 -070028 * @summary Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic
29 */
30
31import java.util.regex.*;
32import java.util.*;
33import java.io.*;
34import static java.lang.Character.*;
35
36public class CheckProp {
37
38 public static void main(String[] args) throws IOException {
39 File fPropList = new File(System.getProperty("test.src", "."), "PropList.txt");
40 int i, j;
41 BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));
42 Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
43 Map<String, ArrayList<Integer>> propMap = new LinkedHashMap<>();
44
45 String line = null;
46 int lineNo = 0;
47 while ((line = sbfr.readLine()) != null) {
48 lineNo++;
49 if (line.length() <= 1 || line.charAt(0) == '#') {
50 continue;
51 }
52 m.reset(line);
53 if (m.matches()) {
54 int start = Integer.parseInt(m.group(1), 16);
55 int end = (m.group(2)==null)?start
56 :Integer.parseInt(m.group(2), 16);
57 String name = m.group(3);
58
59 ArrayList<Integer> list = propMap.get(name);
60 if (list == null) {
61 list = new ArrayList<Integer>();
62 propMap.put(name, list);
63 }
64 while (start <= end)
65 list.add(start++);
66 } else {
67 System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
68 }
69 }
70 sbfr.close();
71 //for (String name: propMap.keySet()) {
72 // System.out.printf("%s %d%n", name, propMap.get(name).size());
73 //}
74
75 Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);
76 Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);
77 Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);
78 Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);
79
80 int fails = 0;
81 for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {
82 int type = getType(cp);
83 if (isLowerCase(cp) !=
84 (type == LOWERCASE_LETTER ||
85 Arrays.binarySearch(otherLowercase, cp) >= 0))
86 {
87 fails++;
88 System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);
89 }
90 if (isUpperCase(cp) !=
91 (type == UPPERCASE_LETTER ||
92 Arrays.binarySearch(otherUppercase, cp) >= 0))
93 {
94 fails++;
95 System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);
96 }
97 if (isAlphabetic(cp) !=
98 (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||
99 type == TITLECASE_LETTER || type == MODIFIER_LETTER ||
100 type == OTHER_LETTER || type == OTHER_LETTER ||
101 type == LETTER_NUMBER ||
102 Arrays.binarySearch(otherAlphabetic, cp) >=0))
103 {
104 fails++;
105 System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);
106 }
107 if (isIdeographic(cp) !=
108 (Arrays.binarySearch(ideographic, cp) >= 0))
109 {
110 fails++;
111 System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);
112 }
113 }
114 if (fails != 0)
115 throw new RuntimeException("CheckProp failed=" + fails);
116 }
117}