@@ -11,14 +11,13 @@ type testCase struct {
11
11
result [][]string
12
12
}
13
13
14
- func testPinyin (s string , d []testCase , f pinyinFunc ) ( t * testing. T ) {
14
+ func testPinyin (t * testing. T , s string , d []testCase , f pinyinFunc ) {
15
15
for _ , tc := range d {
16
16
v := f (s , tc .args )
17
17
if ! reflect .DeepEqual (v , tc .result ) {
18
18
t .Errorf ("Expected %s, got %s" , tc .result , v )
19
19
}
20
20
}
21
- return t
22
21
}
23
22
24
23
func TestPinyin (t * testing.T ) {
@@ -125,7 +124,7 @@ func TestPinyin(t *testing.T) {
125
124
},
126
125
}
127
126
128
- testPinyin (hans , testData , Pinyin )
127
+ testPinyin (t , hans , testData , Pinyin )
129
128
130
129
// 测试不是多音字的 Heteronym
131
130
hans = "你"
@@ -143,7 +142,7 @@ func TestPinyin(t *testing.T) {
143
142
},
144
143
},
145
144
}
146
- testPinyin (hans , testData , Pinyin )
145
+ testPinyin (t , hans , testData , Pinyin )
147
146
}
148
147
149
148
func TestNoneHans (t * testing.T ) {
@@ -208,43 +207,6 @@ func TestFinal(t *testing.T) {
208
207
}
209
208
}
210
209
211
- // `yu`, `y`, `w` 不是声母
212
- func TestNewInitials (t * testing.T ) {
213
- hans := "鱼"
214
- testData := []testCase {
215
- testCase {
216
- Args {Style : Initials },
217
- [][]string {
218
- []string {"" },
219
- },
220
- },
221
- testCase {
222
- Args {Style : Finals },
223
- [][]string {
224
- []string {"yu" },
225
- },
226
- },
227
- }
228
- testPinyin (hans , testData , Pinyin )
229
-
230
- hans = "五"
231
- testData = []testCase {
232
- testCase {
233
- Args {Style : Initials },
234
- [][]string {
235
- []string {"" },
236
- },
237
- },
238
- testCase {
239
- Args {Style : Finals },
240
- [][]string {
241
- []string {"wu" },
242
- },
243
- },
244
- }
245
- testPinyin (hans , testData , Pinyin )
246
- }
247
-
248
210
func TestFallback (t * testing.T ) {
249
211
hans := "中国人abc"
250
212
testData := []testCase {
@@ -291,5 +253,72 @@ func TestFallback(t *testing.T) {
291
253
},
292
254
},
293
255
}
294
- testPinyin (hans , testData , Pinyin )
256
+ testPinyin (t , hans , testData , Pinyin )
257
+ }
258
+
259
+ type testItem struct {
260
+ hans string
261
+ args Args
262
+ result [][]string
263
+ }
264
+
265
+ func testPinyinUpdate (t * testing.T , d []testItem , f pinyinFunc ) {
266
+ for _ , tc := range d {
267
+ v := f (tc .hans , tc .args )
268
+ if ! reflect .DeepEqual (v , tc .result ) {
269
+ t .Errorf ("Expected %s, got %s" , tc .result , v )
270
+ }
271
+ }
272
+ }
273
+
274
+ func TestUpdated (t * testing.T ) {
275
+ testData := []testItem {
276
+ // 误把 yu 放到声母列表了
277
+ testItem {"鱼" , Args {Style : Tone2 }, [][]string {[]string {"yu2" }}},
278
+ testItem {"鱼" , Args {Style : Finals }, [][]string {[]string {"v" }}},
279
+ testItem {"雨" , Args {Style : Tone2 }, [][]string {[]string {"yu3" }}},
280
+ testItem {"雨" , Args {Style : Finals }, [][]string {[]string {"v" }}},
281
+ testItem {"元" , Args {Style : Tone2 }, [][]string {[]string {"yua2n" }}},
282
+ testItem {"元" , Args {Style : Finals }, [][]string {[]string {"van" }}},
283
+ // y, w 也不是拼音, yu的韵母是v, yi的韵母是i, wu的韵母是u
284
+ testItem {"呀" , Args {Style : Initials }, [][]string {[]string {"" }}},
285
+ testItem {"呀" , Args {Style : Tone2 }, [][]string {[]string {"ya" }}},
286
+ testItem {"呀" , Args {Style : Finals }, [][]string {[]string {"ia" }}},
287
+ testItem {"无" , Args {Style : Initials }, [][]string {[]string {"" }}},
288
+ testItem {"无" , Args {Style : Tone2 }, [][]string {[]string {"wu2" }}},
289
+ testItem {"无" , Args {Style : Finals }, [][]string {[]string {"u" }}},
290
+ testItem {"衣" , Args {Style : Tone2 }, [][]string {[]string {"yi1" }}},
291
+ testItem {"衣" , Args {Style : Finals }, [][]string {[]string {"i" }}},
292
+ testItem {"万" , Args {Style : Tone2 }, [][]string {[]string {"wa4n" }}},
293
+ testItem {"万" , Args {Style : Finals }, [][]string {[]string {"uan" }}},
294
+ // ju, qu, xu 的韵母应该是 v
295
+ testItem {"具" , Args {Style : FinalsTone }, [][]string {[]string {"ǜ" }}},
296
+ testItem {"具" , Args {Style : FinalsTone2 }, [][]string {[]string {"v4" }}},
297
+ testItem {"具" , Args {Style : Finals }, [][]string {[]string {"v" }}},
298
+ testItem {"取" , Args {Style : FinalsTone }, [][]string {[]string {"ǚ" }}},
299
+ testItem {"取" , Args {Style : FinalsTone2 }, [][]string {[]string {"v3" }}},
300
+ testItem {"取" , Args {Style : Finals }, [][]string {[]string {"v" }}},
301
+ testItem {"徐" , Args {Style : FinalsTone }, [][]string {[]string {"ǘ" }}},
302
+ testItem {"徐" , Args {Style : FinalsTone2 }, [][]string {[]string {"v2" }}},
303
+ testItem {"徐" , Args {Style : Finals }, [][]string {[]string {"v" }}},
304
+ // # ń
305
+ testItem {"嗯" , Args {Style : Normal }, [][]string {[]string {"n" }}},
306
+ testItem {"嗯" , Args {Style : Tone }, [][]string {[]string {"ń" }}},
307
+ testItem {"嗯" , Args {Style : Tone2 }, [][]string {[]string {"n2" }}},
308
+ testItem {"嗯" , Args {Style : Initials }, [][]string {[]string {"" }}},
309
+ testItem {"嗯" , Args {Style : FirstLetter }, [][]string {[]string {"n" }}},
310
+ testItem {"嗯" , Args {Style : Finals }, [][]string {[]string {"n" }}},
311
+ testItem {"嗯" , Args {Style : FinalsTone }, [][]string {[]string {"ń" }}},
312
+ testItem {"嗯" , Args {Style : FinalsTone2 }, [][]string {[]string {"n2" }}},
313
+ // # ḿ \u1e3f U+1E3F
314
+ testItem {"呣" , Args {Style : Normal }, [][]string {[]string {"m" }}},
315
+ testItem {"呣" , Args {Style : Tone }, [][]string {[]string {"ḿ" }}},
316
+ testItem {"呣" , Args {Style : Tone2 }, [][]string {[]string {"m2" }}},
317
+ testItem {"呣" , Args {Style : Initials }, [][]string {[]string {"" }}},
318
+ testItem {"呣" , Args {Style : FirstLetter }, [][]string {[]string {"m" }}},
319
+ testItem {"呣" , Args {Style : Finals }, [][]string {[]string {"m" }}},
320
+ testItem {"呣" , Args {Style : FinalsTone }, [][]string {[]string {"ḿ" }}},
321
+ testItem {"呣" , Args {Style : FinalsTone2 }, [][]string {[]string {"m2" }}},
322
+ }
323
+ testPinyinUpdate (t , testData , Pinyin )
295
324
}
0 commit comments