1 /* 2 * Copyright (c) 2011, 2019, 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 27 * @bug 7037261 7070436 7198195 8032446 8072600 8221431 8229831 28 * @summary Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic/ 29 * isUnicodeIdentifierStart/isUnicodeIdentifierPart 30 * @library /lib/testlibrary/java/lang 31 */ 32 33 import java.util.regex.*; 34 import java.util.*; 35 import java.io.*; 36 import static java.lang.Character.*; 37 38 public class CheckProp { 39 40 public static void main(String[] args) { 41 Map<String, List<Integer>> propMap = new LinkedHashMap<>(); 42 List.of(UCDFiles.PROP_LIST.toFile(), UCDFiles.DERIVED_PROPS.toFile()).stream() 43 .forEach(f -> readPropMap(propMap, f)); 44 45 Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]); 46 Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]); 47 Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]); 48 Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]); 49 Integer[] IDStart = propMap.get("ID_Start").toArray(new Integer[0]); 50 Integer[] IDContinue = propMap.get("ID_Continue").toArray(new Integer[0]); 51 52 int fails = 0; 53 for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) { 54 int type = getType(cp); 55 if (isLowerCase(cp) != 56 (type == LOWERCASE_LETTER || 57 Arrays.binarySearch(otherLowercase, cp) >= 0)) 58 { 59 fails++; 60 System.err.printf("Wrong isLowerCase(U+%04x)\n", cp); 61 } 62 if (isUpperCase(cp) != 63 (type == UPPERCASE_LETTER || 64 Arrays.binarySearch(otherUppercase, cp) >= 0)) 65 { 66 fails++; 67 System.err.printf("Wrong isUpperCase(U+%04x)\n", cp); 68 } 69 if (isAlphabetic(cp) != 70 (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER || 71 type == TITLECASE_LETTER || type == MODIFIER_LETTER || 72 type == OTHER_LETTER || type == OTHER_LETTER || 73 type == LETTER_NUMBER || 74 Arrays.binarySearch(otherAlphabetic, cp) >=0)) 75 { 76 fails++; 77 System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp); 78 } 79 if (isIdeographic(cp) != 80 (Arrays.binarySearch(ideographic, cp) >= 0)) 81 { 82 fails++; 83 System.err.printf("Wrong isIdeographic(U+%04x)\n", cp); 84 } 85 if (isUnicodeIdentifierStart(cp) != 86 (cp == 0x2E2F || 87 Arrays.binarySearch(IDStart, cp) >= 0)) 88 { 89 fails++; 90 System.err.printf("Wrong isUnicodeIdentifierStart(U+%04x)\n", cp); 91 } 92 if (isUnicodeIdentifierPart(cp) != 93 (isIdentifierIgnorable(cp) || 94 cp == 0x2E2F || 95 Arrays.binarySearch(IDContinue, cp) >= 0)) 96 { 97 fails++; 98 System.err.printf("Wrong isUnicodeIdentifierPart(U+%04x)\n", cp); 99 } 100 } 101 if (fails != 0) 102 throw new RuntimeException("CheckProp failed=" + fails); 103 } 104 105 private static void readPropMap(Map<String, List<Integer>> propMap, File fPropList) { 106 try { 107 BufferedReader sbfr = new BufferedReader(new FileReader(fPropList)); 108 Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher(""); 109 110 String line = null; 111 int lineNo = 0; 112 while ((line = sbfr.readLine()) != null) { 113 lineNo++; 114 if (line.length() <= 1 || line.charAt(0) == '#') { 115 continue; 116 } 117 m.reset(line); 118 if (m.matches()) { 119 int start = Integer.parseInt(m.group(1), 16); 120 int end = (m.group(2)==null)?start 121 :Integer.parseInt(m.group(2), 16); 122 String name = m.group(3); 123 124 List<Integer> list = propMap.get(name); 125 if (list == null) { 126 list = new ArrayList<Integer>(); 127 propMap.put(name, list); 128 } 129 while (start <= end) 130 list.add(start++); 131 } else { 132 System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line); 133 } 134 } 135 sbfr.close(); 136 } catch (IOException ioe) { 137 throw new UncheckedIOException(ioe); 138 } 139 140 //for (String name: propMap.keySet()) { 141 // System.out.printf("%s %d%n", name, propMap.get(name).size()); 142 //} 143 } 144 }