Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/Character/CheckProp.java
38813 views
/*1* Copyright (c) 2011, 2012, 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 719819527* @summary Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic28*/2930import java.util.regex.*;31import java.util.*;32import java.io.*;33import static java.lang.Character.*;3435public class CheckProp {3637public static void main(String[] args) throws IOException {38File fPropList = new File(System.getProperty("test.src", "."), "PropList.txt");39int i, j;40BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));41Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");42Map<String, ArrayList<Integer>> propMap = new LinkedHashMap<>();4344String line = null;45int lineNo = 0;46while ((line = sbfr.readLine()) != null) {47lineNo++;48if (line.length() <= 1 || line.charAt(0) == '#') {49continue;50}51m.reset(line);52if (m.matches()) {53int start = Integer.parseInt(m.group(1), 16);54int end = (m.group(2)==null)?start55:Integer.parseInt(m.group(2), 16);56String name = m.group(3);5758ArrayList<Integer> list = propMap.get(name);59if (list == null) {60list = new ArrayList<Integer>();61propMap.put(name, list);62}63while (start <= end)64list.add(start++);65} else {66System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);67}68}69sbfr.close();70//for (String name: propMap.keySet()) {71// System.out.printf("%s %d%n", name, propMap.get(name).size());72//}7374Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);75Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);76Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);77Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);7879int fails = 0;80for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {81int type = getType(cp);82if (isLowerCase(cp) !=83(type == LOWERCASE_LETTER ||84Arrays.binarySearch(otherLowercase, cp) >= 0))85{86fails++;87System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);88}89if (isUpperCase(cp) !=90(type == UPPERCASE_LETTER ||91Arrays.binarySearch(otherUppercase, cp) >= 0))92{93fails++;94System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);95}96if (isAlphabetic(cp) !=97(type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||98type == TITLECASE_LETTER || type == MODIFIER_LETTER ||99type == OTHER_LETTER || type == OTHER_LETTER ||100type == LETTER_NUMBER ||101Arrays.binarySearch(otherAlphabetic, cp) >=0))102{103fails++;104System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);105}106if (isIdeographic(cp) !=107(Arrays.binarySearch(ideographic, cp) >= 0))108{109fails++;110System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);111}112}113if (fails != 0)114throw new RuntimeException("CheckProp failed=" + fails);115}116}117118119