Path: blob/master/test/jdk/java/lang/Character/CheckUnicode.java
41149 views
/*1* Copyright (c) 2018, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* @test27* @bug 4114080 6565620 6959267 7070436 7198195 8032446 8072600 822143128* @summary Make sure the attributes of Unicode characters, as29* returned by the Character API, are as expected. Do this by30* comparing them to a baseline file together with a list of31* known diffs.32* @library /lib/testlibrary/java/lang33* @build UnicodeSpec CharCheck34* @run main CheckUnicode35* @author Alan Liu36* @author John O'Conner37*/3839import java.io.*;4041public class CheckUnicode {42public static void main(String args[]) throws Exception {4344// 1. Check that the current 12.1 spec file is handled by the current45// version of Character.46File unicodeSpec = UCDFiles.UNICODE_DATA.toFile();47for (int x = 0; x < 16; ++x) {48int diffs = CharCheck.check(x, unicodeSpec);49if (diffs != 0) {50throw new RuntimeException("Unicode properties have changed " +51"in an unexpected way");52}53}5455// 2. Check that Java identifiers are recognized correctly.56// test a few characters that are good id starts57char[] idStartChar = {'$', '\u20AC', 'a', 'A', 'z', 'Z', '_', '\u0E3F',58'\u1004', '\u10A0', '\u3400', '\u4E00', '\uAC00' };59for (int x = 0; x < idStartChar.length; x++) {60if (Character.isJavaIdentifierStart(idStartChar[x]) != true) {61throw new RuntimeException("Java id start characters are not recognized.");62}63}6465// test a few characters that are good id parts66char[] idPartChar = {'0', '9', '\u0000', '\u0008', '\u000E', '\u007F'};67for (int x=0; x< idStartChar.length; x++) {68if (Character.isJavaIdentifierPart(idStartChar[x]) != true) {69throw new RuntimeException("Java id part characters are not recognized.");70}71}72for (int x=0; x<idPartChar.length; x++) {73if (Character.isJavaIdentifierPart(idPartChar[x]) != true) {74throw new RuntimeException("Java id part characters are not recognized.");75}76}7778// now do some negative checks79for (int x=0; x< idPartChar.length; x++) {80if (Character.isJavaIdentifierStart(idPartChar[x]) != false) {81throw new RuntimeException("These Java id part characters" +82"should not be start characters.");83}84}85}86}878889