예제 #1
0
        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" }, }
            };
            UCultureInfo        french = new UCultureInfo("fr");
            CultureDisplayNames names  = CultureDisplayNames.GetInstance(french,
                                                                         new DisplayContextOptions {
                Capitalization = Capitalization.UIListOrMenu
            });

            Logln("Contexts: " + names.DisplayContextOptions.ToString());

            Collator collator = Collator.GetInstance(french);

            foreach (String[][] test in tests)
            {
                var list = new JCG.LinkedHashSet <UCultureInfo>();
                IList <UiListItem> expected = new JCG.List <UiListItem>();
                foreach (String item in test[0])
                {
                    list.Add(new UCultureInfo(item));
                }
                for (int i = 1; i < test.Length; ++i)
                {
                    String[] rawRow = test[i];
                    expected.Add(new UiListItem(new UCultureInfo(rawRow[2]), new UCultureInfo(rawRow[3]), rawRow[0], rawRow[1]));
                }
                IList <UiListItem> newList = names.GetUiList(list, false, collator);
                if (!expected.Equals(newList)) // J2N's List compares the list contents
                {
                    if (expected.Count != newList.Count)
                    {
                        Errln(string.Format(StringFormatter.CurrentCulture, "{0}", list) + ": wrong size" + expected + ", " + newList);
                    }
                    else
                    {
                        Errln(string.Format(StringFormatter.CurrentCulture, "{0}", list));
                        for (int i = 0; i < expected.Count; ++i)
                        {
                            assertEquals(i + "", expected[i], newList[i]);
                        }
                    }
                }
                else
                {
                    assertEquals(string.Format(StringFormatter.CurrentCulture, "{0}", list), expected, newList);
                }
            }
        }