test/jdk/java/lang/Character/CheckProp.java
author mikael
Mon, 29 Jul 2019 09:59:04 -0700
changeset 57584 9d82a35b6ff7
parent 55013 8dae495a59e7
child 58028 7ac4273bb49b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     1
/*
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     4
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     8
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    13
 * accompanied this code).
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    14
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    18
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    21
 * questions.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    22
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    23
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    24
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    25
/**
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    26
 * @test
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 47216
diff changeset
    27
 * @bug 7037261 7070436 7198195 8032446 8072600 8221431
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    28
 * @summary  Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 47216
diff changeset
    29
 * @library /lib/testlibrary/java/lang
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    30
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    31
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    32
import java.util.regex.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    33
import java.util.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    34
import java.io.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    35
import static java.lang.Character.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    36
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    37
public class CheckProp {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    38
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    39
    public static void main(String[] args) throws IOException {
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 47216
diff changeset
    40
        File fPropList = UCDFiles.PROP_LIST.toFile();
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    41
        int i, j;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    42
        BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    43
        Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    44
        Map<String, ArrayList<Integer>> propMap =  new LinkedHashMap<>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    45
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    46
        String line = null;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    47
        int lineNo = 0;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    48
        while ((line = sbfr.readLine()) != null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    49
            lineNo++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    50
            if (line.length() <= 1 || line.charAt(0) == '#') {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    51
                continue;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    52
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    53
            m.reset(line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    54
            if (m.matches()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    55
                int start = Integer.parseInt(m.group(1), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    56
                int end = (m.group(2)==null)?start
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    57
                          :Integer.parseInt(m.group(2), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    58
                String name = m.group(3);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    59
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    60
                ArrayList<Integer> list = propMap.get(name);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    61
                if (list == null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    62
                    list = new ArrayList<Integer>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    63
                    propMap.put(name, list);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    64
                }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    65
                while (start <= end)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    66
                    list.add(start++);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    67
            } else {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    68
                System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    69
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    70
        }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    71
        sbfr.close();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    72
        //for (String name: propMap.keySet()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    73
        //    System.out.printf("%s    %d%n", name, propMap.get(name).size());
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    74
        //}
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    75
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    76
        Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    77
        Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    78
        Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    79
        Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    80
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    81
        int fails = 0;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    82
        for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    83
            int type = getType(cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    84
            if (isLowerCase(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    85
                (type == LOWERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    86
                 Arrays.binarySearch(otherLowercase, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    87
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    88
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    89
                System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    90
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    91
            if (isUpperCase(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    92
                (type == UPPERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    93
                 Arrays.binarySearch(otherUppercase, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    94
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    95
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    96
                System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    97
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    98
            if (isAlphabetic(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    99
                (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   100
                 type == TITLECASE_LETTER || type == MODIFIER_LETTER  ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   101
                 type == OTHER_LETTER     || type == OTHER_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   102
                 type == LETTER_NUMBER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   103
                 Arrays.binarySearch(otherAlphabetic, cp) >=0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   104
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   105
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   106
                System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   107
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   108
            if (isIdeographic(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   109
                (Arrays.binarySearch(ideographic, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   110
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   111
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   112
                System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   113
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   114
        }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   115
        if (fails != 0)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   116
            throw new RuntimeException("CheckProp failed=" + fails);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   117
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   118
}