test/jdk/java/lang/Character/CharPropTest.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:
50230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     1
/*
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 50230
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     4
 *
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     8
 *
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    13
 * accompanied this code).
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    14
 *
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    18
 *
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    21
 * questions.
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    22
 */
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    23
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    24
/*
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    25
 * @test
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 50230
diff changeset
    26
 * @bug 8202771 8221431
50230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    27
 * @summary Check j.l.Character.isDigit/isLetter/isLetterOrDigit/isSpaceChar
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    28
 * /isWhitespace/isTitleCase/isISOControl/isIdentifierIgnorable
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    29
 * /isJavaIdentifierStart/isJavaIdentifierPart/isUnicodeIdentifierStart
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    30
 * /isUnicodeIdentifierPart
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 50230
diff changeset
    31
 * @library /lib/testlibrary/java/lang
50230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    32
 * @run main CharPropTest
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    33
 */
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    34
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    35
import java.nio.file.Files;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    36
import java.util.stream.Stream;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    37
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    38
public class CharPropTest {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    39
    private static int diffs = 0;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    40
    private static int rangeStart = 0x0000;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    41
    private static boolean isRange = false;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    42
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
55013
8dae495a59e7 8221431: Support for Unicode 12.1
naoto
parents: 50230
diff changeset
    44
        try (Stream<String> lines = Files.lines(UCDFiles.UNICODE_DATA)) {
50230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    45
            lines.map(String::trim)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    46
                 .filter(line -> line.length() != 0 && line.charAt(0) != '#')
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    47
                 .forEach(line -> handleOneLine(line));
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    48
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    49
            if (diffs != 0) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    50
                throw new RuntimeException("Total differences: " + diffs);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    51
            }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    52
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    53
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    54
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    55
    private static void handleOneLine(String line) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    56
        String[] fields = line.split(";");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    57
        int currentCp = Integer.parseInt(fields[0], 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    58
        String name = fields[1];
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    59
        String category = fields[2];
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    60
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    61
        // Except single code point, also handle ranges like the following:
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    62
        // 3400;<CJK Ideograph Extension A, First>;Lo;0;L;;;;;N;;;;;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    63
        // 4DB5;<CJK Ideograph Extension A, Last>;Lo;0;L;;;;;N;;;;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    64
        if (isRange) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    65
            if (name.endsWith("Last>")) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    66
                for (int cp = rangeStart; cp <= currentCp; cp++) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    67
                    testCodePoint(cp, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    68
                }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    69
            } else {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    70
                throw new RuntimeException("Not a valid range, first range <"
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    71
                        + Integer.toHexString(rangeStart) + "> without last.");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    72
            }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    73
            isRange = false;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    74
        } else {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    75
            if (name.endsWith("First>")) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    76
                rangeStart = currentCp;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    77
                isRange = true;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    78
            } else {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    79
                testCodePoint(currentCp, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    80
            }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    81
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    82
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    83
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    84
    private static void testCodePoint(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    85
        isDigitTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    86
        isLetterTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    87
        isLetterOrDigitTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    88
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    89
        isSpaceCharTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    90
        isWhitespaceTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    91
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    92
        isTitleCaseTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    93
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    94
        isISOControlTest(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    95
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    96
        isIdentifierIgnorableTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    97
        isJavaIdentifierStartTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    98
        isJavaIdentifierPartTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
    99
        isUnicodeIdentifierStartTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   100
        isUnicodeIdentifierPartTest(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   101
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   102
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   103
    private static void isDigitTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   104
        boolean actual = Character.isDigit(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   105
        boolean expected = category.equals("Nd");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   106
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   107
            printDiff(codePoint, "isDigit", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   108
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   109
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   110
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   111
    private static void isLetterTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   112
        boolean actual = Character.isLetter(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   113
        boolean expected = isLetter(category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   114
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   115
            printDiff(codePoint, "isLetter", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   116
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   117
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   118
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   119
    private static void isLetterOrDigitTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   120
        boolean actual = Character.isLetterOrDigit(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   121
        boolean expected = isLetter(category) || category.equals("Nd");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   122
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   123
            printDiff(codePoint, "isLetterOrDigit", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   124
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   125
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   126
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   127
    private static void isSpaceCharTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   128
        boolean actual = Character.isSpaceChar(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   129
        boolean expected = isSpaceChar(category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   130
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   131
            printDiff(codePoint, "isSpaceChar", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   132
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   133
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   134
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   135
    private static void isWhitespaceTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   136
        boolean actual = Character.isWhitespace(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   137
        boolean expected = isWhitespace(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   138
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   139
            printDiff(codePoint, "isWhitespace", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   140
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   141
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   142
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   143
    private static void isTitleCaseTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   144
        boolean actual = Character.isTitleCase(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   145
        boolean expected = category.equals("Lt");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   146
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   147
            printDiff(codePoint, "isTitleCase", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   148
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   149
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   150
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   151
    private static void isISOControlTest(int codePoint) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   152
        boolean actual = Character.isISOControl(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   153
        boolean expected = isISOControl(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   154
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   155
            printDiff(codePoint, "isISOControl", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   156
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   157
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   158
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   159
    private static void isIdentifierIgnorableTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   160
        boolean actual = Character.isIdentifierIgnorable(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   161
        boolean expected = isIdentifierIgnorable(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   162
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   163
            printDiff(codePoint, "isIdentifierIgnorable", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   164
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   165
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   166
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   167
    private static void isJavaIdentifierStartTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   168
        boolean actual = Character.isJavaIdentifierStart(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   169
        boolean expected = isJavaIdentifierStart(category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   170
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   171
            printDiff(codePoint, "isJavaIdentifierStart", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   172
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   173
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   174
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   175
    private static void isJavaIdentifierPartTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   176
        boolean actual = Character.isJavaIdentifierPart(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   177
        boolean expected = isJavaIdentifierPart(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   178
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   179
            printDiff(codePoint, "isJavaIdentifierPart", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   180
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   181
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   182
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   183
    private static void isUnicodeIdentifierStartTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   184
        boolean actual = Character.isUnicodeIdentifierStart(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   185
        boolean expected = isUnicodeIdentifierStart(category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   186
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   187
            printDiff(codePoint, "isUnicodeIdentifierStart", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   188
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   189
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   190
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   191
    private static void isUnicodeIdentifierPartTest(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   192
        boolean actual = Character.isUnicodeIdentifierPart(codePoint);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   193
        boolean expected = isUnicodeIdentifierPart(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   194
        if (actual != expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   195
            printDiff(codePoint, "isUnicodeIdentifierPart", actual, expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   196
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   197
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   198
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   199
    private static boolean isLetter(String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   200
        return category.equals("Lu") || category.equals("Ll")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   201
               || category.equals("Lt") || category.equals("Lm")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   202
               || category.equals("Lo");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   203
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   204
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   205
    private static boolean isSpaceChar(String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   206
        return category.equals("Zs") || category.equals("Zl")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   207
               || category.equals("Zp");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   208
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   209
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   210
    private static boolean isWhitespace(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   211
        if (isSpaceChar(category) && codePoint != Integer.parseInt("00A0", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   212
                && codePoint != Integer.parseInt("2007", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   213
                && codePoint != Integer.parseInt("202F", 16)) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   214
            return true;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   215
        } else {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   216
            if (codePoint == Integer.parseInt("0009", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   217
                    || codePoint == Integer.parseInt("000A", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   218
                    || codePoint == Integer.parseInt("000B", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   219
                    || codePoint == Integer.parseInt("000C", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   220
                    || codePoint == Integer.parseInt("000D", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   221
                    || codePoint == Integer.parseInt("001C", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   222
                    || codePoint == Integer.parseInt("001D", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   223
                    || codePoint == Integer.parseInt("001E", 16)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   224
                    || codePoint == Integer.parseInt("001F", 16)) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   225
                return true;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   226
            }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   227
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   228
        return false;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   229
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   230
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   231
    private static boolean isISOControl(int codePoint) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   232
        return (codePoint > 0x00 && codePoint < 0x1f)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   233
               || (codePoint > 0x7f && codePoint < 0x9f)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   234
               || (codePoint == 0x00 || codePoint == 0x1f || codePoint == 0x7f || codePoint == 0x9f);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   235
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   236
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   237
    private static boolean isIdentifierIgnorable(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   238
        if (category.equals("Cf")) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   239
            return true;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   240
        } else {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   241
            int a1 = Integer.parseInt("0000", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   242
            int a2 = Integer.parseInt("0008", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   243
            int b1 = Integer.parseInt("000E", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   244
            int b2 = Integer.parseInt("001B", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   245
            int c1 = Integer.parseInt("007F", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   246
            int c2 = Integer.parseInt("009F", 16);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   247
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   248
            if ((codePoint > a1 && codePoint < a2) || (codePoint > b1 && codePoint < b2)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   249
                    || (codePoint > c1 && codePoint < c2) || (codePoint == a1 || codePoint == a2
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   250
                    || codePoint == b1 || codePoint == b2 || codePoint == c1 || codePoint == c2)) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   251
                return true;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   252
            }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   253
        }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   254
        return false;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   255
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   256
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   257
    private static boolean isJavaIdentifierStart(String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   258
        return isLetter(category) || category.equals("Nl") || category.equals("Sc")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   259
               || category.equals("Pc");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   260
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   261
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   262
    private static boolean isJavaIdentifierPart(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   263
        return isLetter(category) || category.equals("Sc") || category.equals("Pc")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   264
               || category.equals("Nd") || category.equals("Nl")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   265
               || category.equals("Mc") || category.equals("Mn")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   266
               || isIdentifierIgnorable(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   267
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   268
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   269
    private static boolean isUnicodeIdentifierStart(String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   270
        return isLetter(category) || category.equals("Nl");
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   271
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   272
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   273
    private static boolean isUnicodeIdentifierPart(int codePoint, String category) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   274
        return isLetter(category) || category.equals("Pc") || category.equals("Nd")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   275
               || category.equals("Nl") || category.equals("Mc") || category.equals("Mn")
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   276
               || isIdentifierIgnorable(codePoint, category);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   277
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   278
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   279
    private static void printDiff(int codePoint, String method, boolean actual, boolean expected) {
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   280
        System.out.println("Not equal at codePoint <" + Integer.toHexString(codePoint)
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   281
                + ">, method: " + method
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   282
                + ", actual: " + actual + ", expected: " + expected);
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   283
        diffs++;
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   284
    }
cae567ae015d 8202771: Migrate Unicode character tests to JDK Repo
mli
parents:
diff changeset
   285
}