Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/Character/TestIsJavaIdentifierMethods.java
38812 views
/*1* Copyright (c) 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*/2223/**24* @test25* @summary Test behavior of isJavaIdentifierXX, testIsJavaLetter, and26* testIsJavaLetterOrDigit methods for all code points.27* @bug 821891528*/2930import java.util.List;31import java.util.ArrayList;3233public class TestIsJavaIdentifierMethods {3435// List of new code points are not present in Unicode 6.2.36private static final List<Integer> UNASSIGNED_CODEPOINTS_IN_6_237= new ArrayList<Integer>()38{{39add(0x20BB); // NORDIC MARK SIGN40add(0x20BC); // MANAT SIGN41add(0x20BD); // RUBLE SIGN42add(0x20BE); // LARI SIGN43add(0x20BF); // BITCOIN SIGN44add(0x32FF); // SQUARE ERA NAME NEWERA45}};4647public static void main(String[] args) {48testIsJavaIdentifierPart_int();49testIsJavaIdentifierPart_char();50testIsJavaIdentifierStart_int();51testIsJavaIdentifierStart_char();52testIsJavaLetter();53testIsJavaLetterOrDigit();54}5556/**57* Assertion testing for public static boolean isJavaIdentifierPart(int58* codePoint), A character may be part of a Java identifier if any of the59* following are true:60* <ul>61* <li>it is a letter</li>62* <li>it is a currency symbol (such as <code>'$'</code>)</li>63* <li>it is a connecting punctuation character (such as <code>'_'</code>)64* </li>65* <li>it is a digit</li>66* <li>it is a numeric letter (such as a Roman numeral character)</li>67* <li>it is a combining mark</li>68* <li>it is a non-spacing mark</li>69* <li><code>isIdentifierIgnorable</code> returns <code>true</code> for the70* character</li>71* </ul>72* All code points from (0x0000..0x10FFFF) are tested.73*/74public static void testIsJavaIdentifierPart_int() {75for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) {76boolean expected = false;7778// Since Character.isJavaIdentifierPart(int) strictly conforms to79// character information from version 6.2 of the Unicode Standard,80// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"81// list. If the code point is found in list82// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable83// "expected" is considered false.84if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) {85byte type = (byte) Character.getType(cp);86expected = Character.isLetter(cp)87|| type == Character.CURRENCY_SYMBOL88|| type == Character.CONNECTOR_PUNCTUATION89|| Character.isDigit(cp)90|| type == Character.LETTER_NUMBER91|| type == Character.COMBINING_SPACING_MARK92|| type == Character.NON_SPACING_MARK93|| Character.isIdentifierIgnorable(cp);94}9596if (Character.isJavaIdentifierPart(cp) != expected) {97throw new RuntimeException(98"Character.isJavaIdentifierPart(int) failed for codepoint "99+ Integer.toHexString(cp));100}101}102}103104/**105* Assertion testing for public static boolean isJavaIdentifierPart(char106* ch), A character may be part of a Java identifier if any of the107* following are true:108* <ul>109* <li>it is a letter;110* <li>it is a currency symbol (such as "$");111* <li>it is a connecting punctuation character (such as "_");112* <li>it is a digit;113* <li>it is a numeric letter (such as a Roman numeral character);114* <li>it is a combining mark;115* <li>it is a non-spacing mark;116* <li>isIdentifierIgnorable returns true for the character.117* </ul>118* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.119*/120public static void testIsJavaIdentifierPart_char() {121for (int i = 0; i <= Character.MAX_VALUE; ++i) {122char ch = (char) i;123boolean expected = false;124// Since Character.isJavaIdentifierPart(char) strictly conforms to125// character information from version 6.2 of the Unicode Standard,126// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"127// list. If the code point is found in list128// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable129// "expected" is considered false.130if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {131byte type = (byte) Character.getType(ch);132expected = Character.isLetter(ch)133|| type == Character.CURRENCY_SYMBOL134|| type == Character.CONNECTOR_PUNCTUATION135|| Character.isDigit(ch)136|| type == Character.LETTER_NUMBER137|| type == Character.COMBINING_SPACING_MARK138|| type == Character.NON_SPACING_MARK139|| Character.isIdentifierIgnorable(ch);140}141142if (Character.isJavaIdentifierPart((char) i) != expected) {143throw new RuntimeException(144"Character.isJavaIdentifierPart(char) failed for codepoint "145+ Integer.toHexString(i));146}147}148}149150/**151* Assertion testing for public static boolean isJavaIdentifierStart(int152* codePoint), A character may start a Java identifier if and only if it is153* one of the following:154* <ul>155* <li>it is a letter;</li>156* <li>getType(ch) returns LETTER_NUMBER;</li>157* <li>it is a currency symbol (such as "$");</li>158* <li>it is a connecting punctuation character (such as "_");</li>159* </ul>160* All Code points from (0x0000..0x10FFFF) are tested.161*/162public static void testIsJavaIdentifierStart_int() {163for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) {164boolean expected = false;165// Since Character.isJavaIdentifierStart(int) strictly conforms to166// character information from version 6.2 of the Unicode Standard,167// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"168// list. If the code point is found in list169// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable170// "expected" is considered false.171if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) {172byte type = (byte) Character.getType(cp);173expected = Character.isLetter(cp)174|| type == Character.LETTER_NUMBER175|| type == Character.CURRENCY_SYMBOL176|| type == Character.CONNECTOR_PUNCTUATION;177}178179if (Character.isJavaIdentifierStart(cp) != expected) {180throw new RuntimeException(181"Character.isJavaIdentifierStart(int) failed for codepoint "182+ Integer.toHexString(cp));183}184}185}186187/**188* Assertion testing for public static boolean isJavaIdentifierStart(char),189* A character may start a Java identifier if and only if it is190* one of the following:191* <ul>192* <li>it is a letter;</li>193* <li>getType(ch) returns LETTER_NUMBER;</li>194* <li>it is a currency symbol (such as "$");</li>195* <li>it is a connecting punctuation character (such as "_");</li>196* </ul>197* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.198*/199public static void testIsJavaIdentifierStart_char() {200for (int i = 0; i <= Character.MAX_VALUE; i++) {201char ch = (char) i;202boolean expected = false;203// Since Character.isJavaIdentifierStart(char) strictly conforms to204// character information from version 6.2 of the Unicode Standard,205// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"206// list. If the code point is found in list207// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable208// "expected" is considered false.209if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {210byte type = (byte) Character.getType(ch);211expected = Character.isLetter(ch)212|| type == Character.LETTER_NUMBER213|| type == Character.CURRENCY_SYMBOL214|| type == Character.CONNECTOR_PUNCTUATION;215}216217if (Character.isJavaIdentifierStart(ch) != expected) {218throw new RuntimeException(219"Character.isJavaIdentifierStart(char) failed for codepoint "220+ Integer.toHexString(i));221}222}223}224225/**226* Assertion testing for public static boolean isJavaLetter(char ch), A227* character may start a Java identifier if and only if one of the228* following is true:229* <ul>230* <li>isLetter(ch) returns true231* <li>getType(ch) returns LETTER_NUMBER232* <li>ch is a currency symbol (such as "$")233* <li>ch is a connecting punctuation character (such as "_").234* </ul>235* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.236*/237public static void testIsJavaLetter() {238for (int i = 0; i <= Character.MAX_VALUE; ++i) {239char ch = (char) i;240boolean expected = false;241// Since Character.isJavaLetter(char) strictly conforms to242// character information from version 6.2 of the Unicode Standard,243// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"244// list. If the code point is found in list245// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable246// "expected" is considered false.247if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {248byte type = (byte) Character.getType(ch);249expected = Character.isLetter(ch)250|| type == Character.LETTER_NUMBER251|| type == Character.CURRENCY_SYMBOL252|| type == Character.CONNECTOR_PUNCTUATION;253}254255if (Character.isJavaLetter(ch) != expected) {256throw new RuntimeException(257"Character.isJavaLetter(ch) failed for codepoint "258+ Integer.toHexString(i));259}260}261}262263/**264* Assertion testing for public static boolean isJavaLetterOrDigit(char265* ch), A character may be part of a Java identifier if and only if any266* of the following are true:267* <ul>268* <li>it is a letter269* <li>it is a currency symbol (such as '$')270* <li>it is a connecting punctuation character (such as '_')271* <li>it is a digit272* <li>it is a numeric letter (such as a Roman numeral character)273* <li>it is a combining mark274* <li>it is a non-spacing mark275* <li>isIdentifierIgnorable returns true for the character.276* </ul>277* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.278*/279public static void testIsJavaLetterOrDigit() {280for (int i = 0; i <= Character.MAX_VALUE; ++i) {281char ch = (char) i;282boolean expected = false;283// Since Character.isJavaLetterOrDigit(char) strictly conforms to284// character information from version 6.2 of the Unicode Standard,285// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"286// list. If the code point is found in list287// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable288// "expected" is considered false.289if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {290byte type = (byte) Character.getType(ch);291expected = Character.isLetter(ch)292|| type == Character.CURRENCY_SYMBOL293|| type == Character.CONNECTOR_PUNCTUATION294|| Character.isDigit(ch)295|| type == Character.LETTER_NUMBER296|| type == Character.COMBINING_SPACING_MARK297|| type == Character.NON_SPACING_MARK298|| Character.isIdentifierIgnorable(ch);299}300301if (Character.isJavaLetterOrDigit(ch) != expected) {302throw new RuntimeException(303"Character.isJavaLetterOrDigit(ch) failed for codepoint "304+ Integer.toHexString(i));305}306}307}308}309310311