1 package colltab
2
3 import (
4 "testing"
5
6 "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},
31 {3, language.English},
32 {4, language.AmericanEnglish},
33 {5, language.MustParse("en-US-u-va-posix")},
34 {4, language.MustParse("en-US-u-va-noposix")},
35 {3, language.MustParse("en-UK-u-va-noposix")},
36 {7, language.Serbian},
37 {0, language.Croatian},
38 {0, language.MustParse("gsw")},
39 {1, language.MustParse("bs-Cyrl")},
40 {1, language.MustParse("bs-Latn")},
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
47
48 {10, language.MustParse("zh-Hant-u-co-stroke")},
49
50 {12, language.MustParse("zh-Hant-u-co-phonebk")},
51 {10, language.MustParse("zh-u-co-stroke")},
52 {12, language.MustParse("und-TW")},
53 {12, language.MustParse("und-HK")},
54 {6, language.MustParse("und-BR")},
55 {6, language.MustParse("und-PT")},
56 {2, language.MustParse("und-Latn-DE")},
57 {0, language.MustParse("und-Jpan-BR")},
58 {0, language.MustParse("zu")},
59 } {
60 t.Run(tc.t.String(), func(t *testing.T) {
61 if x := MatchLang(tc.t, tags); x != tc.x {
62 t.Errorf("%d: MatchLang(%q, tags) = %d; want %d", i, tc.t, x, tc.x)
63 }
64 })
65 }
66 }
67
View as plain text