...
1
2
3
4
5 package internal
6
7 import (
8 "fmt"
9 "strings"
10 "testing"
11
12 "golang.org/x/text/language"
13 )
14
15 func TestUnique(t *testing.T) {
16 testCases := []struct {
17 in, want string
18 }{
19 {"", "[]"},
20 {"en", "[en]"},
21 {"en en", "[en]"},
22 {"en en en", "[en]"},
23 {"en-u-cu-eur en", "[en en-u-cu-eur]"},
24 {"nl en", "[en nl]"},
25 {"pt-Pt pt", "[pt pt-PT]"},
26 }
27 for _, tc := range testCases {
28 tags := []language.Tag{}
29 for _, s := range strings.Split(tc.in, " ") {
30 if s != "" {
31 tags = append(tags, language.MustParse(s))
32 }
33 }
34 if got := fmt.Sprint(UniqueTags(tags)); got != tc.want {
35 t.Errorf("Unique(%s) = %s; want %s", tc.in, got, tc.want)
36 }
37 }
38 }
39
View as plain text