1
2
3
4
5
6
7 package cases
8
9 import (
10 "path"
11 "strings"
12 "testing"
13
14 "golang.org/x/text/language"
15 "golang.org/x/text/unicode/norm"
16 )
17
18 func TestICUConformance(t *testing.T) {
19
20 input := []string{
21 "a.a a_a",
22 "a\u05d0a",
23 "\u05d0'a",
24 "a\u03084a",
25 "a\u0308a",
26 "a3\u30a3a",
27 "a\u303aa",
28 "a_\u303a_a",
29 "1_a..a",
30 "1_a.a",
31 "a..a.",
32 "a--a-",
33 "a-a-",
34 "a\u200ba",
35 "a\u200b\u200ba",
36 "a\u00ad\u00ada",
37 "a\u00ada",
38 "a''a",
39 "a'a",
40 "a::a",
41 "a:a",
42 "a..a",
43 "a.a",
44 "a;;a",
45 "a;a",
46 "a__a",
47 "a_a",
48 "ΟΣ''a",
49 }
50 add := func(x interface{}) {
51 switch v := x.(type) {
52 case string:
53 input = append(input, v)
54 case []string:
55 for _, s := range v {
56 input = append(input, s)
57 }
58 }
59 }
60 for _, tc := range testCases {
61 add(tc.src)
62 add(tc.lower)
63 add(tc.upper)
64 add(tc.title)
65 }
66 for _, tc := range bufferTests {
67 add(tc.src)
68 }
69 for _, tc := range breakTest {
70 add(strings.Replace(tc, "|", "", -1))
71 }
72 for _, tc := range foldTestCases {
73 add(tc)
74 }
75
76
77 for _, c := range []string{"lower", "upper", "title", "fold"} {
78 for _, tag := range []string{
79 "und", "af", "az", "el", "lt", "nl", "tr",
80 } {
81 for _, s := range input {
82 if exclude(c, tag, s) {
83 continue
84 }
85 t.Run(path.Join(c, tag, s), func(t *testing.T) {
86 want := doICU(tag, c, s)
87 got := doGo(tag, c, s)
88 if norm.NFC.String(got) != norm.NFC.String(want) {
89 t.Errorf("\n in %[3]q (%+[3]q)\n got %[1]q (%+[1]q)\n want %[2]q (%+[2]q)", got, want, s)
90 }
91 })
92 }
93 }
94 }
95 }
96
97
98 func exclude(cm, tag, s string) bool {
99 list := []struct{ cm, tags, pattern string }{
100
101
102
103
104
105 {"title", "af nl", "a''a"},
106 {"", "", "א'a"},
107
108
109
110
111
112
113 {"title", "af nl", "'n"},
114 {"title", "af nl", "'N"},
115
116
117
118
119 {"lower title", "", "\u039f\u03a3...............................a"},
120
121
122
123
124
125 {"upper", "el", "\u03bf" + strings.Repeat("\u0321", 29) + "\u0313"},
126 {"lower", "az tr lt", "I" + strings.Repeat("\u0321", 30) + "\u0307\u0300"},
127 {"upper", "lt", "i" + strings.Repeat("\u0321", 30) + "\u0307\u0300"},
128 {"lower", "lt", "I" + strings.Repeat("\u0321", 30) + "\u0300"},
129
130
131
132
133
134 {"title", "az tr", "\u0307"},
135
136
137
138 {"upper title", "lt", "i\u0307"},
139 {"upper title", "lt", "i" + strings.Repeat("\u0321", 29) + "\u0307\u0300"},
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 {"lower title", "lt", "\u0130"},
157 {"lower title", "lt", "\u00cf"},
158
159
160
161
162
163
164
165 {"upper", "el", "\u0386"},
166 {"upper", "el", "\u0389"},
167 {"upper", "el", "\u038A"},
168
169 {"upper", "el", "\u0391"},
170 {"upper", "el", "\u0397"},
171 {"upper", "el", "\u0399"},
172
173 {"upper", "el", "\u03AC"},
174 {"upper", "el", "\u03AE"},
175 {"upper", "el", "\u03AF"},
176
177 {"upper", "el", "\u03B1"},
178 {"upper", "el", "\u03B7"},
179 {"upper", "el", "\u03B9"},
180 }
181 for _, x := range list {
182 if x.cm != "" && strings.Index(x.cm, cm) == -1 {
183 continue
184 }
185 if x.tags != "" && strings.Index(x.tags, tag) == -1 {
186 continue
187 }
188 if strings.Index(s, x.pattern) != -1 {
189 return true
190 }
191 }
192 return false
193 }
194
195 func doGo(tag, caser, input string) string {
196 var c Caser
197 t := language.MustParse(tag)
198 switch caser {
199 case "lower":
200 c = Lower(t)
201 case "upper":
202 c = Upper(t)
203 case "title":
204 c = Title(t)
205 case "fold":
206 c = Fold()
207 }
208 return c.String(input)
209 }
210
View as plain text