-
Notifications
You must be signed in to change notification settings - Fork 26
/
pinyingo_test.go
83 lines (74 loc) · 1.94 KB
/
pinyingo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package pinyingo
import (
"testing"
)
func TestConvert(t *testing.T) {
pinyinMap := map[string][]string{
"hello中国": []string{"hello", "zhōng", "guó"},
"中国hello": []string{"zhōng", "guó", "hello"},
"中国": []string{"zhōng", "guó"},
"123qwe": []string{"123qwe"},
}
pinyinMap1 := map[string][]string{
"hello中国": []string{"hello", "zh", "g"},
"中国": []string{"zh", "g"},
"123qwe": []string{"123qwe"},
}
pinyinMap2 := map[string][]string{
"hello中国": []string{"hello", "zhong", "guo"},
"中国": []string{"zhong", "guo"},
"123qwe": []string{"123qwe"},
}
pinyinMap3 := map[string][]string{
"重阳": []string{"chóng", "yáng"},
"重点": []string{"zhòng", "diǎn"},
}
pinyinMap4 := map[string][]string{
"你好啊": []string{"n", "h", "a"},
}
for k, v := range pinyinMap {
py := NewPy(STYLE_TONE, NO_SEGMENT)
converted := py.Convert(k)
for i := 0; i < len(converted); i++ {
if converted[i] != v[i] {
t.Errorf("%s is not equal %s", converted, v)
}
}
}
for k, v := range pinyinMap1 {
py := NewPy(STYLE_INITIALS, NO_SEGMENT)
converted := py.Convert(k)
for i := 0; i < len(converted); i++ {
if converted[i] != v[i] {
t.Errorf("%s is not equal %s", converted, v)
}
}
}
for k, v := range pinyinMap2 {
py := NewPy(STYLE_NORMAL, NO_SEGMENT)
converted := py.Convert(k)
for i := 0; i < len(converted); i++ {
if converted[i] != v[i] {
t.Errorf("%s is not equal %s", converted, v)
}
}
}
for k, v := range pinyinMap3 {
py := NewPy(STYLE_TONE, USE_SEGMENT)
converted := py.Convert(k)
for i := 0; i < len(converted); i++ {
if converted[i] != v[i] {
t.Errorf("%s is not equal %s", converted, v)
}
}
}
for k, v := range pinyinMap4 {
py := NewPy(STYLE_FIRST_LETTER, USE_SEGMENT)
converted := py.Convert(k)
for i := 0; i < len(converted); i++ {
if converted[i] != v[i] {
t.Errorf("%s is not equal %s", converted, v)
}
}
}
}