]> granicus.if.org Git - icu/commitdiff
ICU-10187 Fix test (regions that leaked () in CLDR).
authorMark Davis <mark@macchiato.com>
Mon, 15 Jul 2013 13:40:57 +0000 (13:40 +0000)
committerMark Davis <mark@macchiato.com>
Mon, 15 Jul 2013 13:40:57 +0000 (13:40 +0000)
X-SVN-Rev: 33923

icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java

index 24dfb17415557a5ccfcc511481715b4c650d1603..546a38f2bceef8be49b5e3630a61639c43976393 100644 (file)
@@ -337,23 +337,27 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
         }
 
         if (resultName == null) {
-            resultName = localeIdName(lang);
+            resultName = localeIdName(lang)
+                    .replace(formatOpenParen, formatReplaceOpenParen)
+                    .replace(formatCloseParen, formatReplaceCloseParen);
         }
 
         StringBuilder buf = new StringBuilder();
         if (hasScript) {
             // first element, don't need appendWithSep
-            buf.append(scriptDisplayNameInContext(script));
+            buf.append(scriptDisplayNameInContext(script)
+                    .replace(formatOpenParen, formatReplaceOpenParen)
+                    .replace(formatCloseParen, formatReplaceCloseParen));
         }
         if (hasCountry) {
-            String regionDisplayName = regionDisplayName(country);
-            regionDisplayName = regionDisplayName
+            appendWithSep(regionDisplayName(country)
                     .replace(formatOpenParen, formatReplaceOpenParen)
-                    .replace(formatCloseParen, formatReplaceCloseParen);
-            appendWithSep(regionDisplayName, buf);
+                    .replace(formatCloseParen, formatReplaceCloseParen), buf);
         }
         if (hasVariant) {
-            appendWithSep(variantDisplayName(variant), buf);
+            appendWithSep(variantDisplayName(variant)
+                    .replace(formatOpenParen, formatReplaceOpenParen)
+                    .replace(formatCloseParen, formatReplaceCloseParen), buf);
         }
 
         Iterator<String> keys = locale.getKeywords();
@@ -361,8 +365,12 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
             while (keys.hasNext()) {
                 String key = keys.next();
                 String value = locale.getKeywordValue(key);
-                String keyDisplayName = keyDisplayName(key);
-                String valueDisplayName = keyValueDisplayName(key, value);
+                String keyDisplayName = keyDisplayName(key)
+                        .replace(formatOpenParen, formatReplaceOpenParen)
+                        .replace(formatCloseParen, formatReplaceCloseParen);
+                String valueDisplayName = keyValueDisplayName(key, value)
+                        .replace(formatOpenParen, formatReplaceOpenParen)
+                        .replace(formatCloseParen, formatReplaceCloseParen);
                 if (!valueDisplayName.equals(value)) {
                     appendWithSep(valueDisplayName, buf);
                 } else if (!key.equals(keyDisplayName)) {
index ac89234de43cec991d6c6eecb42216e013d64a4e..83f74a3fe44ca46a8fd5b2a9065964ba033f4a43 100644 (file)
@@ -1084,27 +1084,31 @@ public class ULocaleTest extends TestFmwk {
     }
 
     private boolean checkName(String name, String language, String script, String country, String variant, ULocale dl) {
-        if (language.length() > 0 && name.indexOf(language) == -1) {
-            errln("loc: " + dl + " name '" + name + "' does not contain language '" + language + "'");
+        if (!checkInclusion(dl, name, language, "language")) {
             return false;
         }
-        if (script.length() > 0 && name.indexOf(script) == -1) {
-            errln("loc: " + dl + " name '" + name + "' does not contain script '" + script + "'");
+        if (!checkInclusion(dl, name, script, "script")) {
             return false;
         }
-        if (country.length() > 0 && name.indexOf(country) == -1) {
-            String country2 = country.replace('(', '[').replace(')',']').replace('(', '[').replace(')',']');
+        if (!checkInclusion(dl, name, country, "country")) {
+            return false;
+        }
+        if (!checkInclusion(dl, name, variant, "variant")) {
+            return false;
+        }
+        return true;
+    }
+
+    private boolean checkInclusion(ULocale dl, String name, String substring, String substringName) {
+        if (substring.length() > 0 && name.indexOf(substring) == -1) {
+            String country2 = substring.replace('(', '[').replace(')',']').replace('(', '[').replace(')',']');
             if (name.indexOf(country2) == -1) {
-                errln("loc: " + dl + " name '" + name + "' does not contain country '" + country + "'");
+                errln("loc: " + dl + " name '" + name + "' does not contain " +
+                               substringName +
+                               " '" + substring + "'");
                 return false;
-//            } else {
-//                System.out.println("loc: " + dl + " name '" + name + "' does not contain country '" + country + "'");
             }
         }
-        if (variant.length() > 0 && name.indexOf(variant) == -1) {
-            errln("loc: " + dl + " name '" + name + "' does not contain variant '" + variant + "'");
-            return false;
-        }
         return true;
     }
 
@@ -1125,7 +1129,6 @@ public class ULocaleTest extends TestFmwk {
                 script = ULocale.getDisplayScriptInContext(localeID, testLocale);
                 country = ULocale.getDisplayCountry(localeID, testLocale);
                 variant = ULocale.getDisplayVariant(localeID, testLocale);
-
                 if (!checkName(name, language, script, country, variant, new ULocale(testLocale))) {
                     break;
                 }