jdk/test/java/util/Locale/LocaleEnhanceTest.java
author okutsu
Thu, 14 Apr 2011 15:59:47 +0900
changeset 9224 75c0420badef
parent 8780 c88e159a3e5c
child 9232 9e29d6359705
permissions -rw-r--r--
7028818: (lc) Lazily initialize locale extension 7029740: (lc) New Locale class implementation doesn't follow the Java coding conventions 7032820: (lc) sun.util.locale.InternalLocaleBuilder.CaseInsensitiveChar.equals problems 7033503: (lc) Restore optimization code for Locale class initialization 7033504: (lc) incompatible behavior change for ja_JP_JP and th_TH_TH locales Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     1
/*
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     4
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    10
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    15
 * accompanied this code).
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    16
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    20
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    23
 * questions.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    24
 */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    25
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    26
import java.io.BufferedReader;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    27
import java.io.ByteArrayInputStream;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    29
import java.io.File;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    30
import java.io.FileInputStream;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    31
import java.io.InputStreamReader;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    32
import java.io.ObjectInputStream;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    33
import java.io.ObjectOutputStream;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    34
import java.net.URISyntaxException;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    35
import java.net.URL;
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
    36
import java.text.DecimalFormatSymbols;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    37
import java.util.ArrayList;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    38
import java.util.Arrays;
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
    39
import java.util.Calendar;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    40
import java.util.IllformedLocaleException;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    41
import java.util.List;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    42
import java.util.Locale;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    43
import java.util.Locale.Builder;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    44
import java.util.Set;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    45
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    46
/**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    47
 * @test
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
    48
 * @bug 6875847 6992272 7002320 7015500 7023613 7032820 7033504
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    49
 * @summary test API changes to Locale
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
    50
 * @compile LocaleEnhanceTest.java
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
    51
 * @run main/othervm -esa LocaleEnhanceTest
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    52
 */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    53
public class LocaleEnhanceTest extends LocaleTestFmwk {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    54
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    55
    public static void main(String[] args) throws Exception {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    56
        List<String> argList = new ArrayList<String>();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    57
        argList.addAll(Arrays.asList(args));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    58
        argList.add("-nothrow");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    59
        new LocaleEnhanceTest().run(argList.toArray(new String[argList.size()]));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    60
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    61
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    62
    public LocaleEnhanceTest() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    63
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    64
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    65
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    66
    /// Generic sanity tests
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    67
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    68
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    69
    /** A canonical language code. */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    70
    private static final String l = "en";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    71
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    72
    /** A canonical script code.. */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    73
    private static final String s = "Latn";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    74
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    75
    /** A canonical region code. */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    76
    private static final String c = "US";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    77
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    78
    /** A canonical variant code. */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    79
    private static final String v = "NewYork";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    80
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    81
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    82
     * Ensure that Builder builds locales that have the expected
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    83
     * tag and java6 ID.  Note the odd cases for the ID.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    84
     */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    85
    public void testCreateLocaleCanonicalValid() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    86
        String[] valids = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    87
            "en-Latn-US-NewYork", "en_US_NewYork_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    88
            "en-Latn-US", "en_US_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    89
            "en-Latn-NewYork", "en__NewYork_#Latn", // double underscore
8780
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
    90
            "en-Latn", "en__#Latn", // double underscore
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    91
            "en-US-NewYork", "en_US_NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    92
            "en-US", "en_US",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    93
            "en-NewYork", "en__NewYork", // double underscore
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    94
            "en", "en",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    95
            "und-Latn-US-NewYork", "_US_NewYork_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    96
            "und-Latn-US", "_US_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    97
            "und-Latn-NewYork", "", // variant only not supported
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    98
            "und-Latn", "",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    99
            "und-US-NewYork", "_US_NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   100
            "und-US", "_US",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   101
            "und-NewYork", "", // variant only not supported
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   102
            "und", ""
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   103
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   104
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   105
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   106
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   107
        for (int i = 0; i < valids.length; i += 2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   108
            String tag = valids[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   109
            String id = valids[i+1];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   110
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   111
            String idl = (i & 16) == 0 ? l : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   112
            String ids = (i & 8) == 0 ? s : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   113
            String idc = (i & 4) == 0 ? c : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   114
            String idv = (i & 2) == 0 ? v : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   115
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   116
            String msg = String.valueOf(i/2) + ": '" + tag + "' ";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   117
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   118
            try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   119
                Locale l = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   120
                    .setLanguage(idl)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   121
                    .setScript(ids)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   122
                    .setRegion(idc)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   123
                    .setVariant(idv)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   124
                    .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   125
                assertEquals(msg + "language", idl, l.getLanguage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   126
                assertEquals(msg + "script", ids, l.getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   127
                assertEquals(msg + "country", idc, l.getCountry());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   128
                assertEquals(msg + "variant", idv, l.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   129
                assertEquals(msg + "tag", tag, l.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   130
                assertEquals(msg + "id", id, l.toString());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   131
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   132
            catch (IllegalArgumentException e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   133
                errln(msg + e.getMessage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   134
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   135
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   136
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   137
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   138
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   139
     * Test that locale construction works with 'multiple variants'.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   140
     * <p>
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   141
     * The string "Newer__Yorker" is treated as three subtags,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   142
     * "Newer", "", and "Yorker", and concatenated into one
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   143
     * subtag by omitting empty subtags and joining the remainer
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   144
     * with underscores.  So the resulting variant tag is "Newer_Yorker".
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   145
     * Note that 'New' and 'York' are invalid BCP47 variant subtags
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   146
     * because they are too short.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   147
     */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   148
    public void testCreateLocaleMultipleVariants() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   149
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   150
        String[] valids = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   151
            "en-Latn-US-Newer-Yorker",  "en_US_Newer_Yorker_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   152
            "en-Latn-Newer-Yorker",     "en__Newer_Yorker_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   153
            "en-US-Newer-Yorker",       "en_US_Newer_Yorker",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   154
            "en-Newer-Yorker",          "en__Newer_Yorker",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   155
            "und-Latn-US-Newer-Yorker", "_US_Newer_Yorker_#Latn",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   156
            "und-Latn-Newer-Yorker",    "",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   157
            "und-US-Newer-Yorker",      "_US_Newer_Yorker",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   158
            "und-Newer-Yorker",         "",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   159
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   160
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   161
        Builder builder = new Builder(); // lenient variant
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   162
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   163
        final String idv = "Newer_Yorker";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   164
        for (int i = 0; i < valids.length; i += 2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   165
            String tag = valids[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   166
            String id = valids[i+1];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   167
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   168
            String idl = (i & 8) == 0 ? l : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   169
            String ids = (i & 4) == 0 ? s : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   170
            String idc = (i & 2) == 0 ? c : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   171
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   172
            String msg = String.valueOf(i/2) + ": " + tag + " ";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   173
            try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   174
                Locale l = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   175
                    .setLanguage(idl)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   176
                    .setScript(ids)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   177
                    .setRegion(idc)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   178
                    .setVariant(idv)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   179
                    .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   180
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   181
                assertEquals(msg + " language", idl, l.getLanguage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   182
                assertEquals(msg + " script", ids, l.getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   183
                assertEquals(msg + " country", idc, l.getCountry());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   184
                assertEquals(msg + " variant", idv, l.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   185
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   186
                assertEquals(msg + "tag", tag, l.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   187
                assertEquals(msg + "id", id, l.toString());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   188
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   189
            catch (IllegalArgumentException e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   190
                errln(msg + e.getMessage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   191
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   192
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   193
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   194
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   195
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   196
     * Ensure that all these invalid formats are not recognized by
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   197
     * forLanguageTag.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   198
     */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   199
    public void testCreateLocaleCanonicalInvalidSeparator() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   200
        String[] invalids = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   201
            // trailing separator
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   202
            "en_Latn_US_NewYork_",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   203
            "en_Latn_US_",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   204
            "en_Latn_",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   205
            "en_",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   206
            "_",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   207
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   208
            // double separator
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   209
            "en_Latn_US__NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   210
            "_Latn_US__NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   211
            "en_US__NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   212
            "_US__NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   213
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   214
            // are these OK?
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   215
            // "en_Latn__US_NewYork", // variant is 'US_NewYork'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   216
            // "_Latn__US_NewYork", // variant is 'US_NewYork'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   217
            // "en__Latn_US_NewYork", // variant is 'Latn_US_NewYork'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   218
            // "en__US_NewYork", // variant is 'US_NewYork'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   219
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   220
            // double separator without language or script
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   221
            "__US",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   222
            "__NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   223
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   224
            // triple separator anywhere except within variant
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   225
            "en___NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   226
            "en_Latn___NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   227
            "_Latn___NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   228
            "___NewYork",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   229
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   230
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   231
        for (int i = 0; i < invalids.length; ++i) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   232
            String id = invalids[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   233
            Locale l = Locale.forLanguageTag(id);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   234
            assertEquals(id, "und", l.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   235
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   236
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   237
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   238
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   239
     * Ensure that all current locale ids parse.  Use DateFormat as a proxy
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   240
     * for all current locale ids.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   241
     */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   242
    public void testCurrentLocales() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   243
        Locale[] locales = java.text.DateFormat.getAvailableLocales();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   244
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   245
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   246
        for (Locale target : locales) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   247
            String tag = target.toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   248
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   249
            // the tag recreates the original locale,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   250
            // except no_NO_NY
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   251
            Locale tagResult = Locale.forLanguageTag(tag);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   252
            if (!target.getVariant().equals("NY")) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   253
                assertEquals("tagResult", target, tagResult);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   254
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   255
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   256
            // the builder also recreates the original locale,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   257
            // except ja_JP_JP, th_TH_TH and no_NO_NY
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   258
            Locale builderResult = builder.setLocale(target).build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   259
            if (target.getVariant().length() != 2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   260
                assertEquals("builderResult", target, builderResult);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   261
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   262
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   263
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   264
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   265
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   266
     * Ensure that all icu locale ids parse.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   267
     */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   268
    public void testIcuLocales() throws Exception {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   269
        BufferedReader br = new BufferedReader(
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   270
            new InputStreamReader(
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   271
                LocaleEnhanceTest.class.getResourceAsStream("icuLocales.txt"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   272
                "UTF-8"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   273
        String id = null;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   274
        while (null != (id = br.readLine())) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   275
            Locale result = Locale.forLanguageTag(id);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   276
            assertEquals("ulocale", id, result.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   277
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   278
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   279
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   280
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   281
    /// Compatibility tests
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   282
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   283
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   284
    public void testConstructor() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   285
        // all the old weirdness still holds, no new weirdness
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   286
        String[][] tests = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   287
            // language to lower case, region to upper, variant unchanged
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   288
            // short
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   289
            { "X", "y", "z", "x", "Y" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   290
            // long
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   291
            { "xXxXxXxXxXxX", "yYyYyYyYyYyYyYyY", "zZzZzZzZzZzZzZzZ",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   292
              "xxxxxxxxxxxx", "YYYYYYYYYYYYYYYY" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   293
            // mapped language ids
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   294
            { "he", "IW", "", "iw" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   295
            { "iw", "IW", "", "iw" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   296
            { "yi", "DE", "", "ji" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   297
            { "ji", "DE", "", "ji" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   298
            { "id", "ID", "", "in" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   299
            { "in", "ID", "", "in" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   300
            // special variants
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   301
            { "ja", "JP", "JP" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   302
            { "th", "TH", "TH" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   303
            { "no", "NO", "NY" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   304
            { "no", "NO", "NY" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   305
            // no canonicalization of 3-letter language codes
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   306
            { "eng", "US", "" }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   307
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   308
        for (int i = 0; i < tests.length; ++ i) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   309
            String[] test = tests[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   310
            String id = String.valueOf(i);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   311
            Locale locale = new Locale(test[0], test[1], test[2]);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   312
            assertEquals(id + " lang", test.length > 3 ? test[3] : test[0], locale.getLanguage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   313
            assertEquals(id + " region", test.length > 4 ? test[4] : test[1], locale.getCountry());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   314
            assertEquals(id + " variant", test.length > 5 ? test[5] : test[2], locale.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   315
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   316
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   317
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   318
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   319
    /// Locale API tests.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   320
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   321
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   322
    public void testGetScript() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   323
        // forLanguageTag normalizes case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   324
        Locale locale = Locale.forLanguageTag("und-latn");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   325
        assertEquals("forLanguageTag", "Latn", locale.getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   326
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   327
        // Builder normalizes case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   328
        locale = new Builder().setScript("LATN").build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   329
        assertEquals("builder", "Latn", locale.getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   330
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   331
        // empty string is returned, not null, if there is no script
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   332
        locale = Locale.forLanguageTag("und");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   333
        assertEquals("script is empty string", "", locale.getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   334
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   335
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   336
    public void testGetExtension() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   337
        // forLanguageTag does NOT normalize to hyphen
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   338
        Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   339
        assertEquals("some_ex-tension", null, locale.getExtension('a'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   340
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   341
        // regular extension
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   342
        locale = new Builder().setExtension('a', "some-ex-tension").build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   343
        assertEquals("builder", "some-ex-tension", locale.getExtension('a'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   344
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   345
        // returns null if extension is not present
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   346
        assertEquals("empty b", null, locale.getExtension('b'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   347
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   348
        // throws exception if extension tag is illegal
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   349
        new ExpectIAE() { public void call() { Locale.forLanguageTag("").getExtension('\uD800'); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   350
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   351
        // 'x' is not an extension, it's a private use tag, but it's accessed through this API
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   352
        locale = Locale.forLanguageTag("x-y-z-blork");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   353
        assertEquals("x", "y-z-blork", locale.getExtension('x'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   354
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   355
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   356
    public void testGetExtensionKeys() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   357
        Locale locale = Locale.forLanguageTag("und-a-xx-yy-b-zz-ww");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   358
        Set<Character> result = locale.getExtensionKeys();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   359
        assertEquals("result size", 2, result.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   360
        assertTrue("'a','b'", result.contains('a') && result.contains('b'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   361
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   362
        // result is not mutable
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   363
        try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   364
            result.add('x');
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   365
            errln("expected exception on add to extension key set");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   366
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   367
        catch (UnsupportedOperationException e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   368
            // ok
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   369
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   370
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   371
        // returns empty set if no extensions
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   372
        locale = Locale.forLanguageTag("und");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   373
        assertTrue("empty result", locale.getExtensionKeys().isEmpty());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   374
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   375
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   376
    public void testGetUnicodeLocaleAttributes() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   377
        Locale locale = Locale.forLanguageTag("en-US-u-abc-def");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   378
        Set<String> attributes = locale.getUnicodeLocaleAttributes();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   379
        assertEquals("number of attributes", 2, attributes.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   380
        assertTrue("attribute abc", attributes.contains("abc"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   381
        assertTrue("attribute def", attributes.contains("def"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   382
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   383
        locale = Locale.forLanguageTag("en-US-u-ca-gregory");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   384
        attributes = locale.getUnicodeLocaleAttributes();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   385
        assertTrue("empty attributes", attributes.isEmpty());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   386
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   387
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   388
    public void testGetUnicodeLocaleType() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   389
        Locale locale = Locale.forLanguageTag("und-u-co-japanese-nu-thai");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   390
        assertEquals("collation", "japanese", locale.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   391
        assertEquals("numbers", "thai", locale.getUnicodeLocaleType("nu"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   392
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   393
        // Unicode locale extension key is case insensitive
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   394
        assertEquals("key case", "japanese", locale.getUnicodeLocaleType("Co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   395
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   396
        // if keyword is not present, returns null
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   397
        assertEquals("locale keyword not present", null, locale.getUnicodeLocaleType("xx"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   398
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   399
        // if no locale extension is set, returns null
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   400
        locale = Locale.forLanguageTag("und");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   401
        assertEquals("locale extension not present", null, locale.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   402
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   403
        // typeless keyword
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   404
        locale = Locale.forLanguageTag("und-u-kn");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   405
        assertEquals("typeless keyword", "", locale.getUnicodeLocaleType("kn"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   406
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   407
        // invalid keys throw exception
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   408
        new ExpectIAE() { public void call() { Locale.forLanguageTag("").getUnicodeLocaleType("q"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   409
        new ExpectIAE() { public void call() { Locale.forLanguageTag("").getUnicodeLocaleType("abcdefghi"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   410
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   411
        // null argument throws exception
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   412
        new ExpectNPE() { public void call() { Locale.forLanguageTag("").getUnicodeLocaleType(null); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   413
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   414
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   415
    public void testGetUnicodeLocaleKeys() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   416
        Locale locale = Locale.forLanguageTag("und-u-co-japanese-nu-thai");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   417
        Set<String> result = locale.getUnicodeLocaleKeys();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   418
        assertEquals("two keys", 2, result.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   419
        assertTrue("co and nu", result.contains("co") && result.contains("nu"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   420
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   421
        // result is not modifiable
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   422
        try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   423
            result.add("frobozz");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   424
            errln("expected exception when add to locale key set");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   425
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   426
        catch (UnsupportedOperationException e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   427
            // ok
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   428
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   429
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   430
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   431
    public void testPrivateUseExtension() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   432
        Locale locale = Locale.forLanguageTag("x-y-x-blork-");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   433
        assertEquals("blork", "y-x-blork", locale.getExtension(Locale.PRIVATE_USE_EXTENSION));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   434
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   435
        locale = Locale.forLanguageTag("und");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   436
        assertEquals("no privateuse", null, locale.getExtension(Locale.PRIVATE_USE_EXTENSION));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   437
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   438
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   439
    public void testToLanguageTag() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   440
        // lots of normalization to test here
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   441
        // test locales created using the constructor
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   442
        String[][] tests = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   443
            // empty locale canonicalizes to 'und'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   444
            { "", "", "", "und" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   445
            // variant alone is not a valid Locale, but has a valid language tag
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   446
            { "", "", "NewYork", "und-NewYork" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   447
            // standard valid locales
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   448
            { "", "Us", "", "und-US" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   449
            { "", "US", "NewYork", "und-US-NewYork" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   450
            { "EN", "", "", "en" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   451
            { "EN", "", "NewYork", "en-NewYork" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   452
            { "EN", "US", "", "en-US" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   453
            { "EN", "US", "NewYork", "en-US-NewYork" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   454
            // underscore in variant will be emitted as multiple variant subtags
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   455
            { "en", "US", "Newer_Yorker", "en-US-Newer-Yorker" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   456
            // invalid variant subtags are appended as private use
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   457
            { "en", "US", "new_yorker", "en-US-x-lvariant-new-yorker" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   458
            // the first invalid variant subtags and following variant subtags are appended as private use
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   459
            { "en", "US", "Windows_XP_Home", "en-US-Windows-x-lvariant-XP-Home" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   460
            // too long variant and following variant subtags disappear
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   461
            { "en", "US", "WindowsVista_SP2", "en-US" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   462
            // invalid region subtag disappears
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   463
            { "en", "USA", "", "en" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   464
            // invalid language tag disappears
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   465
            { "e", "US", "", "und-US" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   466
            // three-letter language tags are not canonicalized
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   467
            { "Eng", "", "", "eng" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   468
            // legacy languages canonicalize to modern equivalents
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   469
            { "he", "IW", "", "he-IW" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   470
            { "iw", "IW", "", "he-IW" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   471
            { "yi", "DE", "", "yi-DE" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   472
            { "ji", "DE", "", "yi-DE" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   473
            { "id", "ID", "", "id-ID" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   474
            { "in", "ID", "", "id-ID" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   475
            // special values are converted on output
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   476
            { "ja", "JP", "JP", "ja-JP-u-ca-japanese-x-lvariant-JP" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   477
            { "th", "TH", "TH", "th-TH-u-nu-thai-x-lvariant-TH" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   478
            { "no", "NO", "NY", "nn-NO" }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   479
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   480
        for (int i = 0; i < tests.length; ++i) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   481
            String[] test = tests[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   482
            Locale locale = new Locale(test[0], test[1], test[2]);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   483
            assertEquals("case " + i, test[3], locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   484
        }
8149
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   485
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   486
        // test locales created from forLanguageTag
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   487
        String[][] tests1 = {
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   488
            // case is normalized during the round trip
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   489
            { "EN-us", "en-US" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   490
            { "en-Latn-US", "en-Latn-US" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   491
            // reordering Unicode locale extensions
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   492
            { "de-u-co-phonebk-ca-gregory", "de-u-ca-gregory-co-phonebk" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   493
            // private use only language tag is preserved (no extra "und")
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   494
            { "x-elmer", "x-elmer" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   495
            { "x-lvariant-JP", "x-lvariant-JP" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   496
        };
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   497
        for (String[] test : tests1) {
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   498
            Locale locale = Locale.forLanguageTag(test[0]);
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   499
            assertEquals("case " + test[0], test[1], locale.toLanguageTag());
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   500
        }
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   501
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   502
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   503
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   504
    public void testForLanguageTag() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   505
        // forLanguageTag implements the 'Language-Tag' production of
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   506
        // BCP47, so it handles private use and grandfathered tags,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   507
        // unlike locale builder.  Tags listed below (except for the
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   508
        // sample private use tags) come from 4646bis Feb 29, 2009.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   509
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   510
        String[][] tests = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   511
            // private use tags only
8149
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   512
            { "x-abc", "x-abc" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   513
            { "x-a-b-c", "x-a-b-c" },
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   514
            { "x-a-12345678", "x-a-12345678" },
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   515
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   516
            // grandfathered tags with preferred mappings
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   517
            { "i-ami", "ami" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   518
            { "i-bnn", "bnn" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   519
            { "i-hak", "hak" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   520
            { "i-klingon", "tlh" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   521
            { "i-lux", "lb" }, // two-letter tag
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   522
            { "i-navajo", "nv" }, // two-letter tag
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   523
            { "i-pwn", "pwn" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   524
            { "i-tao", "tao" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   525
            { "i-tay", "tay" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   526
            { "i-tsu", "tsu" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   527
            { "art-lojban", "jbo" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   528
            { "no-bok", "nb" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   529
            { "no-nyn", "nn" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   530
            { "sgn-BE-FR", "sfb" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   531
            { "sgn-BE-NL", "vgt" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   532
            { "sgn-CH-DE", "sgg" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   533
            { "zh-guoyu", "cmn" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   534
            { "zh-hakka", "hak" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   535
            { "zh-min-nan", "nan" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   536
            { "zh-xiang", "hsn" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   537
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   538
            // grandfathered irregular tags, no preferred mappings, drop illegal fields
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   539
            // from end.  If no subtag is mappable, fallback to 'und'
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   540
            { "i-default", "en-x-i-default" },
8149
768769e3cddd 7015500: Locale.toLanguageTag() uses "und" as lang subtag for private use only Locale
naoto
parents: 7513
diff changeset
   541
            { "i-enochian", "x-i-enochian" },
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   542
            { "i-mingo", "see-x-i-mingo" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   543
            { "en-GB-oed", "en-GB-x-oed" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   544
            { "zh-min", "nan-x-zh-min" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   545
            { "cel-gaulish", "xtg-x-cel-gaulish" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   546
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   547
        for (int i = 0; i < tests.length; ++i) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   548
            String[] test = tests[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   549
            Locale locale = Locale.forLanguageTag(test[0]);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   550
            assertEquals("grandfathered case " + i, test[1], locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   551
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   552
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   553
        // forLanguageTag ignores everything past the first place it encounters
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   554
        // a syntax error
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   555
        tests = new String[][] {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   556
            { "valid",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   557
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   558
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-12345678-z" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   559
            { "segment of private use tag too long",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   560
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-123456789-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   561
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   562
            { "segment of private use tag is empty",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   563
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y--12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   564
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   565
            { "first segment of private use tag is empty",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   566
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x--y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   567
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   568
            { "illegal extension tag",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   569
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-\uD800-y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   570
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   571
            { "locale subtag with no value",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   572
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-x-y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   573
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-x-y-12345678-z" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   574
            { "locale key subtag invalid",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   575
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-123456789-def-x-y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   576
              "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   577
            // locale key subtag invalid in earlier position, all following subtags
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   578
            // dropped (and so the locale extension dropped as well)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   579
            { "locale key subtag invalid in earlier position",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   580
              "en-US-Newer-Yorker-a-bb-cc-dd-u-123456789-abc-bb-def-x-y-12345678-z",
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   581
              "en-US-Newer-Yorker-a-bb-cc-dd" },
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   582
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   583
        for (int i = 0; i < tests.length; ++i) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   584
            String[] test = tests[i];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   585
            String msg = "syntax error case " + i + " " + test[0];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   586
            try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   587
                Locale locale = Locale.forLanguageTag(test[1]);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   588
                assertEquals(msg, test[2], locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   589
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   590
            catch (IllegalArgumentException e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   591
                errln(msg + " caught exception: " + e);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   592
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   593
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   594
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   595
        // duplicated extension are just ignored
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   596
        Locale locale = Locale.forLanguageTag("und-d-aa-00-bb-01-D-AA-10-cc-11-c-1234");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   597
        assertEquals("extension", "aa-00-bb-01", locale.getExtension('d'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   598
        assertEquals("extension c", "1234", locale.getExtension('c'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   599
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
   600
        locale = Locale.forLanguageTag("und-U-ca-gregory-u-ca-japanese");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
   601
        assertEquals("Unicode extension", "ca-gregory", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION));
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
   602
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   603
        // redundant Unicode locale keys in an extension are ignored
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   604
        locale = Locale.forLanguageTag("und-u-aa-000-bb-001-bB-002-cc-003-c-1234");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   605
        assertEquals("Unicode keywords", "aa-000-bb-001-cc-003", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   606
        assertEquals("Duplicated Unicode locake key followed by an extension", "1234", locale.getExtension('c'));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   607
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   608
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   609
    public void testGetDisplayScript() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   610
        Locale latnLocale = Locale.forLanguageTag("und-latn");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   611
        Locale hansLocale = Locale.forLanguageTag("und-hans");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   612
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   613
        Locale oldLocale = Locale.getDefault();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   614
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   615
        Locale.setDefault(Locale.US);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   616
        assertEquals("latn US", "Latin", latnLocale.getDisplayScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   617
        assertEquals("hans US", "Simplified Han", hansLocale.getDisplayScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   618
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   619
        // note, no localization data yet other than US
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   620
        // this should break when we have localization data for DE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   621
        Locale.setDefault(Locale.GERMANY);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   622
        assertEquals("latn DE", "Latin", latnLocale.getDisplayScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   623
        assertEquals("hans DE", "Simplified Han", hansLocale.getDisplayScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   624
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   625
        Locale.setDefault(oldLocale);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   626
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   627
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   628
    public void testGetDisplayScriptWithLocale() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   629
        Locale latnLocale = Locale.forLanguageTag("und-latn");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   630
        Locale hansLocale = Locale.forLanguageTag("und-hans");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   631
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   632
        assertEquals("latn US", "Latin", latnLocale.getDisplayScript(Locale.US));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   633
        assertEquals("hans US", "Simplified Han", hansLocale.getDisplayScript(Locale.US));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   634
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   635
        // note, no localization data yet other than US
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   636
        // this should break when we have localization data for DE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   637
        assertEquals("latn DE", "Latin", latnLocale.getDisplayScript(Locale.GERMANY));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   638
        assertEquals("hans DE", "Simplified Han", hansLocale.getDisplayScript(Locale.GERMANY));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   639
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   640
6843
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   641
    public void testGetDisplayName() {
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   642
        final Locale[] testLocales = {
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   643
                Locale.ROOT,
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   644
                new Locale("en"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   645
                new Locale("en", "US"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   646
                new Locale("", "US"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   647
                new Locale("no", "NO", "NY"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   648
                new Locale("", "", "NY"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   649
                Locale.forLanguageTag("zh-Hans"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   650
                Locale.forLanguageTag("zh-Hant"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   651
                Locale.forLanguageTag("zh-Hans-CN"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   652
                Locale.forLanguageTag("und-Hans"),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   653
        };
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   654
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   655
        final String[] displayNameEnglish = {
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   656
                "",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   657
                "English",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   658
                "English (United States)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   659
                "United States",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   660
                "Norwegian (Norway,Nynorsk)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   661
                "Nynorsk",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   662
                "Chinese (Simplified Han)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   663
                "Chinese (Traditional Han)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   664
                "Chinese (Simplified Han,China)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   665
                "Simplified Han",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   666
        };
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   667
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   668
        final String[] displayNameSimplifiedChinese = {
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   669
                "",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   670
                "\u82f1\u6587",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   671
                "\u82f1\u6587 (\u7f8e\u56fd)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   672
                "\u7f8e\u56fd",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   673
                "\u632a\u5a01\u6587 (\u632a\u5a01,Nynorsk)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   674
                "Nynorsk",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   675
                "\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   676
                "\u4e2d\u6587 (\u7e41\u4f53\u4e2d\u6587)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   677
                "\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587,\u4e2d\u56fd)",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   678
                "\u7b80\u4f53\u4e2d\u6587",
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   679
        };
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   680
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   681
        for (int i = 0; i < testLocales.length; i++) {
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   682
            Locale loc = testLocales[i];
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   683
            assertEquals("English display name for " + loc.toLanguageTag(),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   684
                    displayNameEnglish[i], loc.getDisplayName(Locale.ENGLISH));
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   685
            assertEquals("Simplified Chinese display name for " + loc.toLanguageTag(),
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   686
                    displayNameSimplifiedChinese[i], loc.getDisplayName(Locale.CHINA));
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   687
        }
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   688
    }
6ab7e78c51eb 6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
naoto
parents: 6501
diff changeset
   689
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   690
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   691
    /// Builder tests
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   692
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   693
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   694
    public void testBuilderSetLocale() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   695
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   696
        Builder lenientBuilder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   697
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   698
        String languageTag = "en-Latn-US-NewYork-a-bb-ccc-u-co-japanese-x-y-z";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   699
        String target = "en-Latn-US-NewYork-a-bb-ccc-u-co-japanese-x-y-z";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   700
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   701
        Locale locale = Locale.forLanguageTag(languageTag);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   702
        Locale result = lenientBuilder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   703
            .setLocale(locale)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   704
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   705
        assertEquals("long tag", target, result.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   706
        assertEquals("long tag", locale, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   707
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   708
        // null is illegal
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   709
        new BuilderNPE("locale") {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   710
            public void call() { b.setLocale(null); }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   711
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   712
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   713
        // builder canonicalizes the three legacy locales:
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   714
        // ja_JP_JP, th_TH_TH, no_NY_NO.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   715
        locale = builder.setLocale(new Locale("ja", "JP", "JP")).build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   716
        assertEquals("ja_JP_JP languagetag", "ja-JP-u-ca-japanese", locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   717
        assertEquals("ja_JP_JP variant", "", locale.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   718
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   719
        locale = builder.setLocale(new Locale("th", "TH", "TH")).build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   720
        assertEquals("th_TH_TH languagetag", "th-TH-u-nu-thai", locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   721
        assertEquals("th_TH_TH variant", "", locale.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   722
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   723
        locale = builder.setLocale(new Locale("no", "NO", "NY")).build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   724
        assertEquals("no_NO_NY languagetag", "nn-NO", locale.toLanguageTag());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   725
        assertEquals("no_NO_NY language", "nn", locale.getLanguage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   726
        assertEquals("no_NO_NY variant", "", locale.getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   727
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   728
        // non-canonical, non-legacy locales are invalid
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   729
        new BuilderILE("123_4567_89") {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   730
            public void call() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   731
                b.setLocale(new Locale("123", "4567", "89"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   732
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   733
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   734
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   735
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   736
    public void testBuilderSetLanguageTag() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   737
        String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   738
        String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   739
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   740
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   741
            .setLanguageTag(source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   742
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   743
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   744
        assertEquals("language", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   745
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   746
        // redundant extensions cause a failure
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   747
        new BuilderILE() { public void call() { b.setLanguageTag("und-a-xx-yy-b-ww-A-00-11-c-vv"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   748
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   749
        // redundant Unicode locale extension keys within an Unicode locale extension cause a failure
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   750
        new BuilderILE() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   751
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   752
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   753
    public void testBuilderSetLanguage() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   754
        // language is normalized to lower case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   755
        String source = "eN";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   756
        String target = "en";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   757
        String defaulted = "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   758
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   759
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   760
            .setLanguage(source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   761
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   762
            .getLanguage();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   763
        assertEquals("en", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   764
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   765
        // setting with empty resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   766
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   767
            .setLanguage(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   768
            .setLanguage("")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   769
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   770
            .getLanguage();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   771
        assertEquals("empty", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   772
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   773
        // setting with null resets too
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   774
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   775
                .setLanguage(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   776
                .setLanguage(null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   777
                .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   778
                .getLanguage();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   779
        assertEquals("null", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   780
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   781
        // language codes must be 2-8 alpha
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   782
        // for forwards compatibility, 4-alpha and 5-8 alpha (registered)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   783
        // languages are accepted syntax
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   784
        new BuilderILE("q", "abcdefghi", "13") { public void call() { b.setLanguage(arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   785
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   786
        // language code validation is NOT performed, any 2-8-alpha passes
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   787
        assertNotNull("2alpha", builder.setLanguage("zz").build());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   788
        assertNotNull("8alpha", builder.setLanguage("abcdefgh").build());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   789
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   790
        // three-letter language codes are NOT canonicalized to two-letter
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   791
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   792
            .setLanguage("eng")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   793
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   794
            .getLanguage();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   795
        assertEquals("eng", "eng", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   796
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   797
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   798
    public void testBuilderSetScript() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   799
        // script is normalized to title case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   800
        String source = "lAtN";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   801
        String target = "Latn";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   802
        String defaulted = "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   803
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   804
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   805
            .setScript(source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   806
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   807
            .getScript();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   808
        assertEquals("script", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   809
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   810
        // setting with empty resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   811
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   812
            .setScript(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   813
            .setScript("")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   814
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   815
            .getScript();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   816
        assertEquals("empty", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   817
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   818
        // settting with null also resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   819
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   820
                .setScript(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   821
                .setScript(null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   822
                .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   823
                .getScript();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   824
        assertEquals("null", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   825
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   826
        // ill-formed script codes throw IAE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   827
        // must be 4alpha
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   828
        new BuilderILE("abc", "abcde", "l3tn") { public void call() { b.setScript(arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   829
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   830
        // script code validation is NOT performed, any 4-alpha passes
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   831
        assertEquals("4alpha", "Wxyz", builder.setScript("wxyz").build().getScript());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   832
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   833
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   834
    public void testBuilderSetRegion() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   835
        // region is normalized to upper case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   836
        String source = "uS";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   837
        String target = "US";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   838
        String defaulted = "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   839
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   840
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   841
            .setRegion(source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   842
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   843
            .getCountry();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   844
        assertEquals("us", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   845
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   846
        // setting with empty resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   847
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   848
            .setRegion(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   849
            .setRegion("")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   850
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   851
            .getCountry();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   852
        assertEquals("empty", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   853
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   854
        // setting with null also resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   855
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   856
                .setRegion(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   857
                .setRegion(null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   858
                .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   859
                .getCountry();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   860
        assertEquals("null", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   861
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   862
        // ill-formed region codes throw IAE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   863
        // 2 alpha or 3 numeric
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   864
        new BuilderILE("q", "abc", "12", "1234", "a3", "12a") { public void call() { b.setRegion(arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   865
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   866
        // region code validation is NOT performed, any 2-alpha or 3-digit passes
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   867
        assertEquals("2alpha", "ZZ", builder.setRegion("ZZ").build().getCountry());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   868
        assertEquals("3digit", "000", builder.setRegion("000").build().getCountry());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   869
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   870
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   871
    public void testBuilderSetVariant() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   872
        // Variant case is not normalized in lenient variant mode
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   873
        String source = "NewYork";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   874
        String target = source;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   875
        String defaulted = "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   876
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   877
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   878
            .setVariant(source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   879
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   880
            .getVariant();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   881
        assertEquals("NewYork", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   882
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   883
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   884
            .setVariant("NeWeR_YoRkEr")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   885
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   886
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   887
        assertEquals("newer yorker", "und-NeWeR-YoRkEr", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   888
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   889
        // subtags of variant are NOT reordered
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   890
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   891
            .setVariant("zzzzz_yyyyy_xxxxx")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   892
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   893
            .getVariant();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   894
        assertEquals("zyx", "zzzzz_yyyyy_xxxxx", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   895
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   896
        // setting to empty resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   897
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   898
            .setVariant(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   899
            .setVariant("")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   900
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   901
            .getVariant();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   902
        assertEquals("empty", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   903
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   904
        // setting to null also resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   905
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   906
                .setVariant(target)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   907
                .setVariant(null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   908
                .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   909
                .getVariant();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   910
        assertEquals("null", defaulted, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   911
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   912
        // ill-formed variants throw IAE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   913
        // digit followed by 3-7 characters, or alpha followed by 4-8 characters.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   914
        new BuilderILE("abcd", "abcdefghi", "1ab", "1abcdefgh") { public void call() { b.setVariant(arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   915
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   916
        // 4 characters is ok as long as the first is a digit
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   917
        assertEquals("digit+3alpha", "1abc", builder.setVariant("1abc").build().getVariant());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   918
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   919
        // all subfields must conform
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   920
        new BuilderILE("abcde-fg") { public void call() { b.setVariant(arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   921
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   922
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   923
    public void testBuilderSetExtension() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   924
        // upper case characters are normalized to lower case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   925
        final char sourceKey = 'a';
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   926
        final String sourceValue = "aB-aBcdefgh-12-12345678";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   927
        String target = "ab-abcdefgh-12-12345678";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   928
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   929
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   930
            .setExtension(sourceKey, sourceValue)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   931
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   932
            .getExtension(sourceKey);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   933
        assertEquals("extension", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   934
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   935
        // setting with empty resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   936
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   937
            .setExtension(sourceKey, sourceValue)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   938
            .setExtension(sourceKey, "")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   939
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   940
            .getExtension(sourceKey);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   941
        assertEquals("empty", null, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   942
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   943
        // setting with null also resets
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   944
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   945
                .setExtension(sourceKey, sourceValue)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   946
                .setExtension(sourceKey, null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   947
                .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   948
                .getExtension(sourceKey);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   949
        assertEquals("null", null, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   950
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   951
        // ill-formed extension keys throw IAE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   952
        // must be in [0-9a-ZA-Z]
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   953
        new BuilderILE("$") { public void call() { b.setExtension('$', sourceValue); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   954
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   955
        // each segment of value must be 2-8 alphanum
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   956
        new BuilderILE("ab-cd-123456789") { public void call() { b.setExtension(sourceKey, arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   957
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   958
        // no multiple hyphens.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   959
        new BuilderILE("ab--cd") { public void call() { b.setExtension(sourceKey, arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   960
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   961
        // locale extension key has special handling
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   962
        Locale locale = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   963
            .setExtension('u', "co-japanese")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   964
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   965
        assertEquals("locale extension", "japanese", locale.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   966
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   967
        // locale extension has same behavior with set locale keyword
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   968
        Locale locale2 = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   969
            .setUnicodeLocaleKeyword("co", "japanese")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   970
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   971
        assertEquals("locales with extension", locale, locale2);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   972
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   973
        // setting locale extension overrides all previous calls to setLocaleKeyword
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   974
        Locale locale3 = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   975
            .setExtension('u', "xxx-nu-thai")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   976
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   977
        assertEquals("remove co", null, locale3.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   978
        assertEquals("override thai", "thai", locale3.getUnicodeLocaleType("nu"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   979
        assertEquals("override attribute", 1, locale3.getUnicodeLocaleAttributes().size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   980
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   981
        // setting locale keyword extends values already set by the locale extension
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   982
        Locale locale4 = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   983
            .setUnicodeLocaleKeyword("co", "japanese")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   984
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   985
        assertEquals("extend", "japanese", locale4.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   986
        assertEquals("extend", "thai", locale4.getUnicodeLocaleType("nu"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   987
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   988
        // locale extension subtags are reordered
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   989
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   990
            .clear()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   991
            .setExtension('u', "456-123-zz-123-yy-456-xx-789")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   992
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   993
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   994
        assertEquals("reorder", "und-u-123-456-xx-789-yy-456-zz-123", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   995
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   996
        // multiple keyword types
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   997
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   998
            .clear()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   999
            .setExtension('u', "nu-thai-foobar")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1000
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1001
            .getUnicodeLocaleType("nu");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1002
        assertEquals("multiple types", "thai-foobar", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1003
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1004
        // redundant locale extensions are ignored
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1005
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1006
            .clear()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1007
            .setExtension('u', "nu-thai-NU-chinese-xx-1234")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1008
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1009
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1010
        assertEquals("duplicate keys", "und-u-nu-thai-xx-1234", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1011
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1012
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1013
    public void testBuilderAddUnicodeLocaleAttribute() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1014
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1015
        Locale locale = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1016
            .addUnicodeLocaleAttribute("def")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1017
            .addUnicodeLocaleAttribute("abc")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1018
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1019
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1020
        Set<String> uattrs = locale.getUnicodeLocaleAttributes();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1021
        assertEquals("number of attributes", 2, uattrs.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1022
        assertTrue("attribute abc", uattrs.contains("abc"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1023
        assertTrue("attribute def", uattrs.contains("def"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1024
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1025
        // remove attribute
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1026
        locale = builder.removeUnicodeLocaleAttribute("xxx")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1027
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1028
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1029
        assertEquals("remove bogus", 2, uattrs.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1030
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1031
        // add duplicate
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1032
        locale = builder.addUnicodeLocaleAttribute("abc")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1033
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1034
        assertEquals("add duplicate", 2, uattrs.size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1035
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1036
        // null attribute throws NPE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1037
        new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1038
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1039
        // illformed attribute throws IllformedLocaleException
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1040
        new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1041
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1042
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1043
    public void testBuildersetUnicodeLocaleKeyword() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1044
        // Note: most behavior is tested in testBuilderSetExtension
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1045
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1046
        Locale locale = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1047
            .setUnicodeLocaleKeyword("co", "japanese")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1048
            .setUnicodeLocaleKeyword("nu", "thai")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1049
            .build();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1050
        assertEquals("co", "japanese", locale.getUnicodeLocaleType("co"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1051
        assertEquals("nu", "thai", locale.getUnicodeLocaleType("nu"));
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1052
        assertEquals("keys", 2, locale.getUnicodeLocaleKeys().size());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1053
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1054
        // can clear a keyword by setting to null, others remain
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1055
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1056
            .setUnicodeLocaleKeyword("co", null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1057
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1058
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1059
        assertEquals("empty co", "und-u-nu-thai", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1060
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1061
        // locale keyword extension goes when all keywords are gone
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1062
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1063
            .setUnicodeLocaleKeyword("nu", null)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1064
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1065
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1066
        assertEquals("empty nu", "und", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1067
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1068
        // locale keywords are ordered independent of order of addition
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1069
        result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1070
            .setUnicodeLocaleKeyword("zz", "012")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1071
            .setUnicodeLocaleKeyword("aa", "345")
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1072
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1073
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1074
        assertEquals("reordered", "und-u-aa-345-zz-012", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1075
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1076
        // null keyword throws NPE
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1077
        new BuilderNPE("keyword") { public void call() { b.setUnicodeLocaleKeyword(null, "thai"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1078
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1079
        // well-formed keywords are two alphanum
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1080
        new BuilderILE("a", "abc") { public void call() { b.setUnicodeLocaleKeyword(arg, "value"); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1081
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1082
        // well-formed values are 3-8 alphanum
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1083
        new BuilderILE("ab", "abcdefghi") { public void call() { b.setUnicodeLocaleKeyword("ab", arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1084
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1085
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1086
    public void testBuilderPrivateUseExtension() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1087
        // normalizes hyphens to underscore, case to lower
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1088
        String source = "c-B-a";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1089
        String target = "c-b-a";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1090
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1091
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1092
            .setExtension(Locale.PRIVATE_USE_EXTENSION, source)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1093
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1094
            .getExtension(Locale.PRIVATE_USE_EXTENSION);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1095
        assertEquals("abc", target, result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1096
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1097
        // multiple hyphens are ill-formed
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1098
        new BuilderILE("a--b") { public void call() { b.setExtension(Locale.PRIVATE_USE_EXTENSION, arg); }};
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1099
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1100
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1101
    public void testBuilderClear() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1102
        String monster = "en-latn-US-NewYork-a-bb-cc-u-co-japanese-x-z-y-x-x";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1103
        Builder builder = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1104
        Locale locale = Locale.forLanguageTag(monster);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1105
        String result = builder
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1106
            .setLocale(locale)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1107
            .clear()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1108
            .build()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1109
            .toLanguageTag();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1110
        assertEquals("clear", "und", result);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1111
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1112
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1113
    public void testBuilderRemoveUnicodeAttribute() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1114
        // tested in testBuilderAddUnicodeAttribute
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1115
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1116
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1117
    public void testBuilderBuild() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1118
        // tested in other test methods
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1119
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1120
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1121
    public void testSerialize() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1122
        final Locale[] testLocales = {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1123
            Locale.ROOT,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1124
            new Locale("en"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1125
            new Locale("en", "US"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1126
            new Locale("en", "US", "Win"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1127
            new Locale("en", "US", "Win_XP"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1128
            new Locale("ja", "JP"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1129
            new Locale("ja", "JP", "JP"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1130
            new Locale("th", "TH"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1131
            new Locale("th", "TH", "TH"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1132
            new Locale("no", "NO"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1133
            new Locale("nb", "NO"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1134
            new Locale("nn", "NO"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1135
            new Locale("no", "NO", "NY"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1136
            new Locale("nn", "NO", "NY"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1137
            new Locale("he", "IL"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1138
            new Locale("he", "IL", "var"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1139
            new Locale("Language", "Country", "Variant"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1140
            new Locale("", "US"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1141
            new Locale("", "", "Java"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1142
            Locale.forLanguageTag("en-Latn-US"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1143
            Locale.forLanguageTag("zh-Hans"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1144
            Locale.forLanguageTag("zh-Hant-TW"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1145
            Locale.forLanguageTag("ja-JP-u-ca-japanese"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1146
            Locale.forLanguageTag("und-Hant"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1147
            Locale.forLanguageTag("und-a-123-456"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1148
            Locale.forLanguageTag("en-x-java"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1149
            Locale.forLanguageTag("th-TH-u-ca-buddist-nu-thai-x-lvariant-TH"),
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1150
        };
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1151
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1152
        for (Locale locale : testLocales) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1153
            try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1154
                // write
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1155
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1156
                ObjectOutputStream oos = new ObjectOutputStream(bos);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1157
                oos.writeObject(locale);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1158
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1159
                // read
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1160
                ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1161
                ObjectInputStream ois = new ObjectInputStream(bis);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1162
                Object o = ois.readObject();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1163
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1164
                assertEquals("roundtrip " + locale, locale, o);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1165
            } catch (Exception e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1166
                errln(locale + " encountered exception:" + e.getLocalizedMessage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1167
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1168
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1169
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1170
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1171
    public void testDeserialize6() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1172
        final String TESTFILEPREFIX = "java6locale_";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1173
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1174
        File dataDir = null;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1175
        String dataDirName = System.getProperty("serialized.data.dir");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1176
        if (dataDirName == null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1177
            URL resdirUrl = getClass().getClassLoader().getResource("serialized");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1178
            if (resdirUrl != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1179
                try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1180
                    dataDir = new File(resdirUrl.toURI());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1181
                } catch (URISyntaxException urie) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1182
                }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1183
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1184
        } else {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1185
            dataDir = new File(dataDirName);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1186
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1187
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1188
        if (dataDir == null || !dataDir.isDirectory()) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1189
            errln("Could not locate the serialized test case data location");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1190
            return;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1191
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1192
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1193
        File[] files = dataDir.listFiles();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1194
        for (File testfile : files) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1195
            if (testfile.isDirectory()) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1196
                continue;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1197
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1198
            String name = testfile.getName();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1199
            if (!name.startsWith(TESTFILEPREFIX)) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1200
                continue;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1201
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1202
            Locale locale;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1203
            String locStr = name.substring(TESTFILEPREFIX.length());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1204
            if (locStr.equals("ROOT")) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1205
                locale = Locale.ROOT;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1206
            } else {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1207
                String[] fields = locStr.split("_", 3);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1208
                String lang = fields[0];
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1209
                String country = (fields.length >= 2) ? fields[1] : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1210
                String variant = (fields.length == 3) ? fields[2] : "";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1211
                locale = new Locale(lang, country, variant);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1212
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1213
8543
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7513
diff changeset
  1214
            // deserialize
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7513
diff changeset
  1215
            try (FileInputStream fis = new FileInputStream(testfile);
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7513
diff changeset
  1216
                 ObjectInputStream ois = new ObjectInputStream(fis))
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7513
diff changeset
  1217
            {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1218
                Object o = ois.readObject();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1219
                assertEquals("Deserialize Java 6 Locale " + locale, o, locale);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1220
            } catch (Exception e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1221
                errln("Exception while reading " + testfile.getAbsolutePath() + " - " + e.getMessage());
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1222
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1223
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1224
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1225
7513
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1226
    public void testBug7002320() {
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1227
        // forLanguageTag() and Builder.setLanguageTag(String)
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1228
        // should add a location extension for following two cases.
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1229
        //
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1230
        // 1. language/country are "ja"/"JP" and the resolved variant (x-lvariant-*)
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1231
        //    is exactly "JP" and no BCP 47 extensions are available, then add
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1232
        //    a Unicode locale extension "ca-japanese".
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1233
        // 2. language/country are "th"/"TH" and the resolved variant is exactly
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1234
        //    "TH" and no BCP 47 extensions are available, then add a Unicode locale
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1235
        //    extension "nu-thai".
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1236
        //
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1237
        String[][] testdata = {
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1238
            {"ja-JP-x-lvariant-JP", "ja-JP-u-ca-japanese-x-lvariant-JP"},   // special case 1
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1239
            {"ja-JP-x-lvariant-JP-XXX"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1240
            {"ja-JP-u-ca-japanese-x-lvariant-JP"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1241
            {"ja-JP-u-ca-gregory-x-lvariant-JP"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1242
            {"ja-JP-u-cu-jpy-x-lvariant-JP"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1243
            {"ja-x-lvariant-JP"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1244
            {"th-TH-x-lvariant-TH", "th-TH-u-nu-thai-x-lvariant-TH"},   // special case 2
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1245
            {"th-TH-u-nu-thai-x-lvariant-TH"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1246
            {"en-US-x-lvariant-JP"},
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1247
        };
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1248
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1249
        Builder bldr = new Builder();
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1250
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1251
        for (String[] data : testdata) {
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1252
            String in = data[0];
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1253
            String expected = (data.length == 1) ? data[0] : data[1];
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1254
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1255
            // forLanguageTag
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1256
            Locale loc = Locale.forLanguageTag(in);
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1257
            String out = loc.toLanguageTag();
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1258
            assertEquals("Language tag roundtrip by forLanguageTag with input: " + in, expected, out);
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1259
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1260
            // setLanguageTag
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1261
            bldr.clear();
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1262
            bldr.setLanguageTag(in);
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1263
            loc = bldr.build();
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1264
            out = loc.toLanguageTag();
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1265
            assertEquals("Language tag roundtrip by Builder.setLanguageTag with input: " + in, expected, out);
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1266
        }
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1267
    }
7091fccbc86d 7002320: Locale.forLanguageTag()/toLanguageTag() not working properly with ja_JP_JP locale
naoto
parents: 6843
diff changeset
  1268
8780
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1269
    public void testBug7023613() {
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1270
        String[][] testdata = {
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1271
            {"en-Latn", "en__#Latn"},
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1272
            {"en-u-ca-japanese", "en__#u-ca-japanese"},
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1273
        };
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1274
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1275
        for (String[] data : testdata) {
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1276
            String in = data[0];
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1277
            String expected = (data.length == 1) ? data[0] : data[1];
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1278
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1279
            Locale loc = Locale.forLanguageTag(in);
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1280
            String out = loc.toString();
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1281
            assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out);
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1282
        }
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1283
    }
c88e159a3e5c 7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
naoto
parents: 8545
diff changeset
  1284
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1285
    /*
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1286
     * 7033504: (lc) incompatible behavior change for ja_JP_JP and th_TH_TH locales
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1287
     */
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1288
    public void testBug7033504() {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1289
        checkCalendar(new Locale("ja", "JP", "jp"), "java.util.GregorianCalendar");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1290
        checkCalendar(new Locale("ja", "jp", "jp"), "java.util.GregorianCalendar");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1291
        checkCalendar(new Locale("ja", "JP", "JP"), "java.util.JapaneseImperialCalendar");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1292
        checkCalendar(new Locale("ja", "jp", "JP"), "java.util.JapaneseImperialCalendar");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1293
        checkCalendar(Locale.forLanguageTag("en-u-ca-japanese"),
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1294
                      "java.util.JapaneseImperialCalendar");
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1295
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1296
        checkDigit(new Locale("th", "TH", "th"), '0');
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1297
        checkDigit(new Locale("th", "th", "th"), '0');
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1298
        checkDigit(new Locale("th", "TH", "TH"), '\u0e50');
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1299
        checkDigit(new Locale("th", "TH", "TH"), '\u0e50');
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1300
        checkDigit(Locale.forLanguageTag("en-u-nu-thai"), '\u0e50');
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1301
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1302
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1303
    private void checkCalendar(Locale loc, String expected) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1304
        Calendar cal = Calendar.getInstance(loc);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1305
        assertEquals("Wrong calendar", expected, cal.getClass().getName());
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1306
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1307
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1308
    private void checkDigit(Locale loc, Character expected) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1309
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1310
        Character zero = dfs.getZeroDigit();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1311
        assertEquals("Wrong digit zero char", expected, zero);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1312
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 8780
diff changeset
  1313
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1314
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1315
    /// utility asserts
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1316
    ///
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1317
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1318
    private void assertTrue(String msg, boolean v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1319
        if (!v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1320
            errln(msg + ": expected true");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1321
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1322
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1323
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1324
    private void assertFalse(String msg, boolean v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1325
        if (v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1326
            errln(msg + ": expected false");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1327
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1328
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1329
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1330
    private void assertEquals(String msg, Object e, Object v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1331
        if (e == null ? v != null : !e.equals(v)) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1332
            if (e != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1333
                e = "'" + e + "'";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1334
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1335
            if (v != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1336
                v = "'" + v + "'";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1337
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1338
            errln(msg + ": expected " + e + " but got " + v);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1339
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1340
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1341
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1342
    private void assertNotEquals(String msg, Object e, Object v) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1343
        if (e == null ? v == null : e.equals(v)) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1344
            if (e != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1345
                e = "'" + e + "'";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1346
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1347
            errln(msg + ": expected not equal " + e);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1348
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1349
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1350
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1351
    private void assertNull(String msg, Object o) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1352
        if (o != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1353
            errln(msg + ": expected null but got '" + o + "'");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1354
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1355
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1356
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1357
    private void assertNotNull(String msg, Object o) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1358
        if (o == null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1359
            errln(msg + ": expected non null");
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1360
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1361
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1362
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1363
    // not currently used, might get rid of exceptions from the API
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1364
    private abstract class ExceptionTest {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1365
        private final Class<? extends Exception> exceptionClass;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1366
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1367
        ExceptionTest(Class<? extends Exception> exceptionClass) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1368
            this.exceptionClass = exceptionClass;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1369
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1370
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1371
        public void run() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1372
            String failMsg = null;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1373
            try {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1374
                call();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1375
                failMsg = "expected " + exceptionClass.getName() + "  but no exception thrown.";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1376
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1377
            catch (Exception e) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1378
                if (!exceptionClass.isAssignableFrom(e.getClass())) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1379
                    failMsg = "expected " + exceptionClass.getName() + " but caught " + e;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1380
                }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1381
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1382
            if (failMsg != null) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1383
                String msg = message();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1384
                msg = msg == null ? "" : msg + " ";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1385
                errln(msg + failMsg);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1386
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1387
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1388
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1389
        public String message() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1390
            return null;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1391
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1392
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1393
        public abstract void call();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1394
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1395
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1396
    private abstract class ExpectNPE extends ExceptionTest {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1397
        ExpectNPE() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1398
            super(NullPointerException.class);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1399
            run();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1400
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1401
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1402
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1403
    private abstract class BuilderNPE extends ExceptionTest {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1404
        protected final String msg;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1405
        protected final Builder b = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1406
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1407
        BuilderNPE(String msg) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1408
            super(NullPointerException.class);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1409
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1410
            this.msg = msg;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1411
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1412
            run();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1413
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1414
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1415
        public String message() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1416
            return msg;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1417
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1418
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1419
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1420
    private abstract class ExpectIAE extends ExceptionTest {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1421
        ExpectIAE() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1422
            super(IllegalArgumentException.class);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1423
            run();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1424
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1425
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1426
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1427
    private abstract class BuilderILE extends ExceptionTest {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1428
        protected final String[] args;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1429
        protected final Builder b = new Builder();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1430
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1431
        protected String arg; // mutates during call
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1432
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1433
        BuilderILE(String... args) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1434
            super(IllformedLocaleException.class);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1435
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1436
            this.args = args;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1437
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1438
            run();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1439
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1440
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1441
        public void run() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1442
            for (String arg : args) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1443
                this.arg = arg;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1444
                super.run();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1445
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1446
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1447
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1448
        public String message() {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1449
            return "arg: '" + arg + "'";
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1450
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1451
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
  1452
}