public void TestIllformedLocale() { ULocale french = ULocale.FRENCH; Collator collator = Collator.GetInstance(french); LocaleDisplayNames names = LocaleDisplayNames.GetInstance(french, DisplayContext.CapitalizationForUIListOrMenu); foreach (String malformed in new string[] { "en-a", "$", "ü--a", "en--US" }) { try { ISet <ULocale> supported = ImmutableHashSet.Create(new ULocale(malformed)); //Collections.singleton(new ULocale(malformed)); names.GetUiList(supported, false, collator); assertNull("Failed to detect bogus locale «" + malformed + "»", supported); } catch (IllformedLocaleException e) { Logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.ToString()); } } }
public void TestNameList() { string[][][] tests = { /* name in French, name in self, minimized, modified */ new string[][] { new string[] { "fr-Cyrl-BE", "fr-Cyrl-CA" }, new string[] { "Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE" }, new string[] { "Français (cyrillique, Canada)", "Français (cyrillique, Canada)", "fr_Cyrl_CA", "fr_Cyrl_CA" }, }, new string[][] { new string[] { "en", "de", "fr", "zh"}, new string[] { "Allemand", "Deutsch", "de", "de" }, new string[] { "Anglais", "English", "en", "en" }, new string[] { "Chinois", "中文", "zh", "zh" }, new string[] { "Français", "Français", "fr", "fr" }, }, // some non-canonical names new string[][] { new string[] { "iw", "iw-US", "no", "no-Cyrl", "in", "in-YU"}, new string[] { "Hébreu (États-Unis)", "עברית (ארצות הברית)", "iw_US", "iw_US" }, new string[] { "Hébreu (Israël)", "עברית (ישראל)", "iw", "iw_IL" }, new string[] { "Indonésien (Indonésie)", "Indonesia (Indonesia)", "in", "in_ID" }, new string[] { "Indonésien (Serbie)", "Indonesia (Serbia)", "in_YU", "in_YU" }, new string[] { "Norvégien (cyrillique)", "Norsk (kyrillisk)", "no_Cyrl", "no_Cyrl" }, new string[] { "Norvégien (latin)", "Norsk (latinsk)", "no", "no_Latn" }, }, new string[][] { new string[] { "zh-Hant-TW", "en", "en-gb", "fr", "zh-Hant", "de", "de-CH", "zh-TW"}, new string[] { "Allemand (Allemagne)", "Deutsch (Deutschland)", "de", "de_DE" }, new string[] { "Allemand (Suisse)", "Deutsch (Schweiz)", "de_CH", "de_CH" }, new string[] { "Anglais (États-Unis)", "English (United States)", "en", "en_US" }, new string[] { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, new string[] { "Chinois (traditionnel)", "中文(繁體)", "zh_Hant", "zh_Hant" }, new string[] { "Français", "Français", "fr", "fr" }, }, new string[][] { new string[] { "zh", "en-gb", "en-CA", "fr-Latn-FR"}, new string[] { "Anglais (Canada)", "English (Canada)", "en_CA", "en_CA" }, new string[] { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, new string[] { "Chinois", "中文", "zh", "zh" }, new string[] { "Français", "Français", "fr", "fr" }, }, new string[][] { new string[] { "en-gb", "fr", "zh-Hant", "zh-SG", "sr", "sr-Latn"}, new string[] { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, new string[] { "Chinois (simplifié, Singapour)", "中文(简体,新加坡)", "zh_SG", "zh_Hans_SG" }, new string[] { "Chinois (traditionnel, Taïwan)", "中文(繁體,台灣)", "zh_Hant", "zh_Hant_TW" }, new string[] { "Français", "Français", "fr", "fr" }, new string[] { "Serbe (cyrillique)", "Српски (ћирилица)", "sr", "sr_Cyrl" }, new string[] { "Serbe (latin)", "Srpski (latinica)", "sr_Latn", "sr_Latn" }, }, new string[][] { new string[] { "fr-Cyrl", "fr-Arab" }, new string[] { "Français (arabe)", "Français (arabe)", "fr_Arab", "fr_Arab" }, new string[] { "Français (cyrillique)", "Français (cyrillique)", "fr_Cyrl", "fr_Cyrl" }, }, new string[][] { new string[] { "fr-Cyrl-BE", "fr-Arab-CA" }, new string[] { "Français (arabe, Canada)", "Français (arabe, Canada)", "fr_Arab_CA", "fr_Arab_CA" }, new string[] { "Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE" }, } }; ULocale french = ULocale.FRENCH; LocaleDisplayNames names = LocaleDisplayNames.GetInstance(french, DisplayContext.CapitalizationForUIListOrMenu); foreach (DisplayContextType type in Enum.GetValues(typeof(DisplayContextType))) { Logln("Contexts: " + names.GetContext(type).ToString()); } Collator collator = Collator.GetInstance(french); foreach (String[][] test in tests) { // ICU4N TODO: LinkedHashSet needed ? ISet <ULocale> list = new HashSet <ULocale>(); // LinkedHashSet<ULocale>(); List <UiListItem> expected = new List <UiListItem>(); foreach (String item in test[0]) { list.Add(new ULocale(item)); } for (int i = 1; i < test.Length; ++i) { String[] rawRow = test[i]; expected.Add(new UiListItem(new ULocale(rawRow[2]), new ULocale(rawRow[3]), rawRow[0], rawRow[1])); } IList <UiListItem> newList = names.GetUiList(list, false, collator); if (!expected.SequenceEqual(newList)) { if (expected.Count != newList.Count) { Errln(CollectionUtil.ToString(list) + ": wrong size" + expected + ", " + newList); } else { Errln(CollectionUtil.ToString(list)); for (int i = 0; i < expected.Count; ++i) { assertEquals(i + "", expected[i], newList[i]); } } } else { assertEquals(CollectionUtil.ToString(list), expected, newList); } } }