func TestLanguage(t *testing.T) { tests := []struct { dict string tag string name string }{ {"agq", "sr", ""}, // sr is in Value.Languages(), but is not supported by agq. // CLDR 30 dropped Vlaams as the word for nl-BE. It is still called // Flemish in English, though. TODO: this is probably incorrect. // West-Vlaams (vls) is not Vlaams. West-Vlaams could be considered its // own language, whereas Vlaams is generally Dutch. So expect to have // to change these tests back. {"nl", "nl", "Nederlands"}, {"nl", "vls", "West-Vlaams"}, {"nl", "nl-BE", "Nederlands"}, {"en", "pt", "Portuguese"}, {"en", "pt-PT", "European Portuguese"}, {"en", "pt-BR", "Brazilian Portuguese"}, {"en", "en", "English"}, {"en", "en-GB", "British English"}, {"en", "en-US", "American English"}, // American English in CLDR 24+ {"en", lastLang2zu.String(), "Zulu"}, {"en", firstLang2aa.String(), "Afar"}, {"en", lastLang3zza.String(), "Zaza"}, {"en", firstLang3ace.String(), "Achinese"}, {"en", firstTagAr001.String(), "Modern Standard Arabic"}, {"en", lastTagZhHant.String(), "Traditional Chinese"}, {"en", "aaa", ""}, {"en", "zzj", ""}, // If full tag doesn't match, try without script or region. {"en", "aa-Hans", "Afar"}, {"en", "af-Arab", "Afrikaans"}, {"en", "zu-Cyrl", "Zulu"}, {"en", "aa-GB", "Afar"}, {"en", "af-NA", "Afrikaans"}, {"en", "zu-BR", "Zulu"}, {"agq", "zh-Hant", ""}, // Canonical equivalents. {"ro", "ro-MD", "moldovenească"}, {"ro", "mo", "moldovenească"}, {"en", "sh", "Serbo-Croatian"}, {"en", "sr-Latn", "Serbo-Croatian"}, {"en", "sr", "Serbian"}, {"en", "sr-ME", "Serbian"}, {"en", "sr-Latn-ME", "Serbo-Croatian"}, // See comments in TestTag. } for i, tt := range tests { testtext.Run(t, tt.dict+"/"+tt.tag, func(t *testing.T) { d := Languages(language.Raw.MustParse(tt.dict)) if n := d.Name(language.Raw.MustParse(tt.tag)); n != tt.name { t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.tag, n, tt.name) } if len(tt.tag) <= 3 { if n := d.Name(language.MustParseBase(tt.tag)); n != tt.name { t.Errorf("%d:%s:base(%s): was %q; want %q", i, tt.dict, tt.tag, n, tt.name) } } }) } }
func TestLanguage(t *testing.T) { tests := []struct { dict string tag string name string }{ {"agq", "sr", ""}, // sr is in Value.Languages(), but is not supported by agq. {"nl", "nl", "Nederlands"}, {"nl", "nl-BE", "Vlaams"}, {"en", "pt", "Portuguese"}, {"en", "pt-PT", "European Portuguese"}, {"en", "pt-BR", "Brazilian Portuguese"}, {"en", "en", "English"}, {"en", "en-GB", "British English"}, {"en", "en-US", "American English"}, // American English in CLDR 24+ {"en", lastLang2zu.String(), "Zulu"}, {"en", firstLang2aa.String(), "Afar"}, {"en", lastLang3zza.String(), "Zaza"}, {"en", firstLang3ace.String(), "Achinese"}, {"en", firstTagAr001.String(), "Modern Standard Arabic"}, {"en", lastTagZhHant.String(), "Traditional Chinese"}, {"en", "aaa", ""}, {"en", "zzj", ""}, // If full tag doesn't match, try without script or region. {"en", "aa-Hans", "Afar"}, {"en", "af-Arab", "Afrikaans"}, {"en", "zu-Cyrl", "Zulu"}, {"en", "aa-GB", "Afar"}, {"en", "af-NA", "Afrikaans"}, {"en", "zu-BR", "Zulu"}, {"agq", "zh-Hant", ""}, // Canonical equivalents. {"ro", "ro-MD", "moldovenească"}, {"ro", "mo", "moldovenească"}, {"en", "sh", "Serbo-Croatian"}, {"en", "sr-Latn", "Serbo-Croatian"}, {"en", "sr", "Serbian"}, {"en", "sr-ME", "Serbian"}, {"en", "sr-Latn-ME", "Serbo-Croatian"}, // See comments in TestTag. } for i, tt := range tests { d := Languages(language.Raw.MustParse(tt.dict)) if n := d.Name(language.Raw.MustParse(tt.tag)); n != tt.name { t.Errorf("%d:%s:%s: was %q; want %q", i, tt.dict, tt.tag, n, tt.name) } if len(tt.tag) <= 3 { if n := d.Name(language.MustParseBase(tt.tag)); n != tt.name { t.Errorf("%d:%s:base(%s): was %q; want %q", i, tt.dict, tt.tag, n, tt.name) } } } }
func ExampleTag_values() { us := language.MustParseRegion("US") en := language.MustParseBase("en") lang, _, region := language.AmericanEnglish.Raw() fmt.Println(lang == en, region == us) lang, _, region = language.BritishEnglish.Raw() fmt.Println(lang == en, region == us) // Tags can be compared for exact equivalence using '=='. en_us, _ := language.Compose(en, us) fmt.Println(en_us == language.AmericanEnglish) // Output: // true true // true false // true }
package display import ( "reflect" "testing" "unicode" "golang.org/x/text/language" ) // TODO: test that tables are properly dropped by the linker for various use // cases. var ( firstLang2aa = language.MustParseBase("aa") lastLang2zu = language.MustParseBase("zu") firstLang3ace = language.MustParseBase("ace") lastLang3zza = language.MustParseBase("zza") firstTagAr001 = language.MustParse("ar-001") lastTagZhHant = language.MustParse("zh-Hant") ) // TestValues tests that for all languages, regions, and scripts in Values, at // least one language has a name defined for it by checking it exists in // English, which is assumed to be the most comprehensive. It is also tested // that a Namer returns "" for unsupported values. func TestValues(t *testing.T) { type testcase struct { kind string n Namer