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