Path: blob/master/test/jdk/java/lang/Character/CheckProp.java
41149 views
/*1* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/**25* @test26* @bug 7037261 7070436 7198195 8032446 8072600 8221431 822983127* @summary Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic/28* isUnicodeIdentifierStart/isUnicodeIdentifierPart29* @library /lib/testlibrary/java/lang30*/3132import java.util.regex.*;33import java.util.*;34import java.io.*;35import static java.lang.Character.*;3637public class CheckProp {3839public static void main(String[] args) {40Map<String, List<Integer>> propMap = new LinkedHashMap<>();41List.of(UCDFiles.PROP_LIST.toFile(), UCDFiles.DERIVED_PROPS.toFile()).stream()42.forEach(f -> readPropMap(propMap, f));4344Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);45Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);46Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);47Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);48Integer[] IDStart = propMap.get("ID_Start").toArray(new Integer[0]);49Integer[] IDContinue = propMap.get("ID_Continue").toArray(new Integer[0]);5051int fails = 0;52for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {53int type = getType(cp);54if (isLowerCase(cp) !=55(type == LOWERCASE_LETTER ||56Arrays.binarySearch(otherLowercase, cp) >= 0))57{58fails++;59System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);60}61if (isUpperCase(cp) !=62(type == UPPERCASE_LETTER ||63Arrays.binarySearch(otherUppercase, cp) >= 0))64{65fails++;66System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);67}68if (isAlphabetic(cp) !=69(type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||70type == TITLECASE_LETTER || type == MODIFIER_LETTER ||71type == OTHER_LETTER || type == OTHER_LETTER ||72type == LETTER_NUMBER ||73Arrays.binarySearch(otherAlphabetic, cp) >=0))74{75fails++;76System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);77}78if (isIdeographic(cp) !=79(Arrays.binarySearch(ideographic, cp) >= 0))80{81fails++;82System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);83}84if (isUnicodeIdentifierStart(cp) !=85(cp == 0x2E2F ||86Arrays.binarySearch(IDStart, cp) >= 0))87{88fails++;89System.err.printf("Wrong isUnicodeIdentifierStart(U+%04x)\n", cp);90}91if (isUnicodeIdentifierPart(cp) !=92(isIdentifierIgnorable(cp) ||93cp == 0x2E2F ||94Arrays.binarySearch(IDContinue, cp) >= 0))95{96fails++;97System.err.printf("Wrong isUnicodeIdentifierPart(U+%04x)\n", cp);98}99}100if (fails != 0)101throw new RuntimeException("CheckProp failed=" + fails);102}103104private static void readPropMap(Map<String, List<Integer>> propMap, File fPropList) {105try {106BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));107Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");108109String line = null;110int lineNo = 0;111while ((line = sbfr.readLine()) != null) {112lineNo++;113if (line.length() <= 1 || line.charAt(0) == '#') {114continue;115}116m.reset(line);117if (m.matches()) {118int start = Integer.parseInt(m.group(1), 16);119int end = (m.group(2)==null)?start120:Integer.parseInt(m.group(2), 16);121String name = m.group(3);122123List<Integer> list = propMap.get(name);124if (list == null) {125list = new ArrayList<Integer>();126propMap.put(name, list);127}128while (start <= end)129list.add(start++);130} else {131System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);132}133}134sbfr.close();135} catch (IOException ioe) {136throw new UncheckedIOException(ioe);137}138139//for (String name: propMap.keySet()) {140// System.out.printf("%s %d%n", name, propMap.get(name).size());141//}142}143}144145146