J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | @test |
| 26 | @bug 4219630 4304573 4533872 4900935 |
| 27 | @summary toUpperCase should upper-case German sharp s correctly even if |
| 28 | it's the only character in the string. should also uppercase |
| 29 | all of the 1:M char mappings correctly. Also it should handle |
| 30 | Locale specific (lt, tr, and az) uppercasings and supplementary |
| 31 | characters correctly. |
| 32 | */ |
| 33 | |
| 34 | import java.util.Locale; |
| 35 | |
| 36 | public class ToUpperCase { |
| 37 | |
| 38 | public static void main(String[] args) { |
| 39 | Locale turkish = new Locale("tr", "TR"); |
| 40 | Locale lt = new Locale("lt"); // Lithanian |
| 41 | Locale az = new Locale("az"); // Azeri |
| 42 | |
| 43 | test("\u00DF", turkish, "SS"); |
| 44 | test("a\u00DF", turkish, "ASS"); |
| 45 | test("i", turkish, "\u0130"); |
| 46 | test("i", az, "\u0130"); |
| 47 | test("\u0131", turkish, "I"); |
| 48 | test("\u00DF", Locale.GERMANY, "SS"); |
| 49 | test("a\u00DF", Locale.GERMANY, "ASS"); |
| 50 | test("i", Locale.GERMANY, "I"); |
| 51 | |
| 52 | // test some of the 1:M uppercase mappings |
| 53 | test("abc\u00DF", Locale.US, "ABC\u0053\u0053"); |
| 54 | test("\u0149abc", Locale.US, "\u02BC\u004EABC"); |
| 55 | test("\u0149abc", turkish, "\u02BC\u004EABC"); |
| 56 | test("\u1F52", Locale.US, "\u03A5\u0313\u0300"); |
| 57 | test("\u0149\u1F52", Locale.US, "\u02BC\u004E\u03A5\u0313\u0300"); |
| 58 | test("\u1F54ZZZ", Locale.US, "\u03A5\u0313\u0301ZZZ"); |
| 59 | test("\u1F54ZZZ", turkish, "\u03A5\u0313\u0301ZZZ"); |
| 60 | test("a\u00DF\u1F56", Locale.US, "ASS\u03A5\u0313\u0342"); |
| 61 | test("\u1FAD", turkish, "\u1F6D\u0399"); |
| 62 | test("i\u1FC7", turkish, "\u0130\u0397\u0342\u0399"); |
| 63 | test("i\u1FC7", az, "\u0130\u0397\u0342\u0399"); |
| 64 | test("i\u1FC7", Locale.US, "I\u0397\u0342\u0399"); |
| 65 | test("\uFB04", Locale.US, "\u0046\u0046\u004C"); |
| 66 | test("\uFB17AbCdEfi", turkish, "\u0544\u053DABCDEF\u0130"); |
| 67 | test("\uFB17AbCdEfi", az, "\u0544\u053DABCDEF\u0130"); |
| 68 | |
| 69 | // Remove DOT ABOVE after "i" in Lithuanian |
| 70 | test("i\u0307", lt, "I"); |
| 71 | test("\u0307", lt, "\u0307"); |
| 72 | test("\u0307i", lt, "\u0307I"); |
| 73 | test("j\u0307", lt, "J"); |
| 74 | test("abci\u0307def", lt, "ABCIDEF"); |
| 75 | test("a\u0307", lt, "A\u0307"); |
| 76 | test("abc\u0307def", lt, "ABC\u0307DEF"); |
| 77 | test("i\u0307", Locale.US, "I\u0307"); |
| 78 | test("i\u0307", turkish, "\u0130\u0307"); |
| 79 | |
| 80 | // Supplementary character tests |
| 81 | // |
| 82 | // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I |
| 83 | // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E |
| 84 | // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A |
| 85 | // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I |
| 86 | // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E |
| 87 | // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A |
| 88 | // |
| 89 | // valid code point tests: |
| 90 | test("\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "\uD801\uDC00\uD801\uDC01\uD801\uDC02"); |
| 91 | test("\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C"); |
| 92 | // invalid code point tests: |
| 93 | test("\uD800\uD800\uD801a\uDC00\uDC00\uDC00b", Locale.US, "\uD800\uD800\uD801A\uDC00\uDC00\uDC00B"); |
| 94 | } |
| 95 | |
| 96 | static void test(String in, Locale locale, String expected) { |
| 97 | String result = in.toUpperCase(locale); |
| 98 | if (!result.equals(expected)) { |
| 99 | System.err.println("input: " + in + ", locale: " + locale + |
| 100 | ", expected: " + expected + ", actual: " + result); |
| 101 | throw new RuntimeException(); |
| 102 | } |
| 103 | } |
| 104 | } |