...
1
2
3
4
5 package message
6
7 import (
8 "strings"
9 "testing"
10
11 "golang.org/x/text/language"
12 "golang.org/x/text/message/catalog"
13 )
14
15 func TestMatchLanguage(t *testing.T) {
16 c := catalog.NewBuilder(catalog.Fallback(language.English))
17 c.SetString(language.Bengali, "", "")
18 c.SetString(language.English, "", "")
19 c.SetString(language.German, "", "")
20
21 saved := DefaultCatalog
22 defer func() { DefaultCatalog = saved }()
23 DefaultCatalog = c
24
25 testCases := []struct {
26 args string
27 want string
28 }{{
29 args: "de-CH",
30 want: "de-u-rg-chzzzz",
31 }, {
32 args: "bn-u-nu-latn|en-US,en;q=0.9,de;q=0.8,nl;q=0.7",
33 want: "bn-u-nu-latn",
34 }, {
35 args: "gr",
36 want: "en",
37 }}
38 for _, tc := range testCases {
39 t.Run(tc.args, func(t *testing.T) {
40 got := MatchLanguage(strings.Split(tc.args, "|")...)
41 if got != language.Make(tc.want) {
42 t.Errorf("got %q; want %q", got, tc.want)
43 }
44 })
45 }
46 }
47
View as plain text