github.com/go-xe2/third@v1.0.3/golang.org/x/text/internal/colltab/colltab_test.go (about) 1 package colltab 2 3 import ( 4 "testing" 5 6 "github.com/go-xe2/third/golang.org/x/text/language" 7 ) 8 9 func TestMatchLang(t *testing.T) { 10 tags := []language.Tag{ 11 0: language.Und, 12 1: language.MustParse("bs"), 13 2: language.German, 14 3: language.English, 15 4: language.AmericanEnglish, 16 5: language.MustParse("en-US-u-va-posix"), 17 6: language.Portuguese, 18 7: language.Serbian, 19 8: language.MustParse("sr-Latn"), 20 9: language.Chinese, 21 10: language.MustParse("zh-u-co-stroke"), 22 11: language.MustParse("zh-Hant-u-co-pinyin"), 23 12: language.TraditionalChinese, 24 } 25 for i, tc := range []struct { 26 x int 27 t language.Tag 28 }{ 29 {0, language.Und}, 30 {0, language.Persian}, // Default to first element when no match. 31 {3, language.English}, 32 {4, language.AmericanEnglish}, 33 {5, language.MustParse("en-US-u-va-posix")}, // Ext. variant match. 34 {4, language.MustParse("en-US-u-va-noposix")}, // Ext. variant mismatch. 35 {3, language.MustParse("en-UK-u-va-noposix")}, // Ext. variant mismatch. 36 {7, language.Serbian}, 37 {0, language.Croatian}, // Don't match to close language! 38 {0, language.MustParse("gsw")}, // Don't match to close language! 39 {1, language.MustParse("bs-Cyrl")}, // Odd, but correct. 40 {1, language.MustParse("bs-Latn")}, // Estimated script drops. 41 {8, language.MustParse("sr-Latn")}, 42 {9, language.Chinese}, 43 {9, language.SimplifiedChinese}, 44 {12, language.TraditionalChinese}, 45 {11, language.MustParse("zh-Hant-u-co-pinyin")}, 46 // TODO: should this be 12? Either inherited value (10) or default is 47 // fine in this case, though. Other locales are not affected. 48 {10, language.MustParse("zh-Hant-u-co-stroke")}, 49 // There is no "phonebk" sorting order for zh-Hant, so use default. 50 {12, language.MustParse("zh-Hant-u-co-phonebk")}, 51 {10, language.MustParse("zh-u-co-stroke")}, 52 {12, language.MustParse("und-TW")}, // Infer script and language. 53 {12, language.MustParse("und-HK")}, // Infer script and language. 54 {6, language.MustParse("und-BR")}, // Infer script and language. 55 {6, language.MustParse("und-PT")}, // Infer script and language. 56 {2, language.MustParse("und-Latn-DE")}, // Infer language. 57 {0, language.MustParse("und-Jpan-BR")}, // Infers "ja", so no match. 58 {0, language.MustParse("zu")}, // No match past index. 59 } { 60 if x := MatchLang(tc.t, tags); x != tc.x { 61 t.Errorf("%d: MatchLang(%q, tags) = %d; want %d", i, tc.t, x, tc.x) 62 } 63 } 64 }