Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/String/ToUpperCase.java
38812 views
/*1* Copyright (c) 2000, 2003, 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@bug 4219630 4304573 4533872 490093526@summary toUpperCase should upper-case German sharp s correctly even if27it's the only character in the string. should also uppercase28all of the 1:M char mappings correctly. Also it should handle29Locale specific (lt, tr, and az) uppercasings and supplementary30characters correctly.31*/3233import java.util.Locale;3435public class ToUpperCase {3637public static void main(String[] args) {38Locale turkish = new Locale("tr", "TR");39Locale lt = new Locale("lt"); // Lithanian40Locale az = new Locale("az"); // Azeri4142test("\u00DF", turkish, "SS");43test("a\u00DF", turkish, "ASS");44test("i", turkish, "\u0130");45test("i", az, "\u0130");46test("\u0131", turkish, "I");47test("\u00DF", Locale.GERMANY, "SS");48test("a\u00DF", Locale.GERMANY, "ASS");49test("i", Locale.GERMANY, "I");5051// test some of the 1:M uppercase mappings52test("abc\u00DF", Locale.US, "ABC\u0053\u0053");53test("\u0149abc", Locale.US, "\u02BC\u004EABC");54test("\u0149abc", turkish, "\u02BC\u004EABC");55test("\u1F52", Locale.US, "\u03A5\u0313\u0300");56test("\u0149\u1F52", Locale.US, "\u02BC\u004E\u03A5\u0313\u0300");57test("\u1F54ZZZ", Locale.US, "\u03A5\u0313\u0301ZZZ");58test("\u1F54ZZZ", turkish, "\u03A5\u0313\u0301ZZZ");59test("a\u00DF\u1F56", Locale.US, "ASS\u03A5\u0313\u0342");60test("\u1FAD", turkish, "\u1F6D\u0399");61test("i\u1FC7", turkish, "\u0130\u0397\u0342\u0399");62test("i\u1FC7", az, "\u0130\u0397\u0342\u0399");63test("i\u1FC7", Locale.US, "I\u0397\u0342\u0399");64test("\uFB04", Locale.US, "\u0046\u0046\u004C");65test("\uFB17AbCdEfi", turkish, "\u0544\u053DABCDEF\u0130");66test("\uFB17AbCdEfi", az, "\u0544\u053DABCDEF\u0130");6768// Remove DOT ABOVE after "i" in Lithuanian69test("i\u0307", lt, "I");70test("\u0307", lt, "\u0307");71test("\u0307i", lt, "\u0307I");72test("j\u0307", lt, "J");73test("abci\u0307def", lt, "ABCIDEF");74test("a\u0307", lt, "A\u0307");75test("abc\u0307def", lt, "ABC\u0307DEF");76test("i\u0307", Locale.US, "I\u0307");77test("i\u0307", turkish, "\u0130\u0307");7879// Supplementary character tests80//81// U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I82// U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E83// U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A84// U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I85// U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E86// U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A87//88// valid code point tests:89test("\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "\uD801\uDC00\uD801\uDC01\uD801\uDC02");90test("\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");91// invalid code point tests:92test("\uD800\uD800\uD801a\uDC00\uDC00\uDC00b", Locale.US, "\uD800\uD800\uD801A\uDC00\uDC00\uDC00B");93}9495static void test(String in, Locale locale, String expected) {96String result = in.toUpperCase(locale);97if (!result.equals(expected)) {98System.err.println("input: " + in + ", locale: " + locale +99", expected: " + expected + ", actual: " + result);100throw new RuntimeException();101}102}103}104105106