-
Notifications
You must be signed in to change notification settings - Fork 1
/
py_test.go
65 lines (50 loc) · 1.41 KB
/
py_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
package py_test
import (
"fmt"
"testing"
"github.com/xuender/go-py"
"github.com/xuender/oils/assert"
)
func ExamplePinyin() {
fmt.Println(py.Pinyin("特长"))
fmt.Println(py.Pinyin("长相"))
fmt.Println(py.Pinyin("阿弥陀佛"))
fmt.Println(py.Pinyin("阿弥陀佛", py.Tone))
fmt.Println(py.Pinyin("阿弥陀佛", py.NoTone))
fmt.Println(py.Pinyin("阿弥陀佛", py.Init))
fmt.Println(py.Initials("阿弥陀佛"))
// output:
// [te4 cha2ng]
// [zha3ng xia1ng]
// [a1 mi2 tuo2 fu2]
// [ā mí tuó fú]
// [a mi tuo fu]
// [a m t f]
// amtf
}
func TestInitials(t *testing.T) {
t.Parallel()
assert.Equal(t, "zs", py.Initials("张三"))
assert.Equal(t, "123", py.Initials("123"))
}
func TestPinyin(t *testing.T) {
t.Parallel()
assert.Equals(t, []string{"1", "2", "3"}, py.Pinyin("123"))
assert.Equals(t, []string{"zha3ng"}, py.Pinyin("长"))
assert.Equals(t, []string{"zhang"}, py.Pinyin("长", py.NoTone))
}
func TestPinyins(t *testing.T) {
t.Parallel()
assert.Equal(t, "1", py.Pinyins("123")[0][0])
assert.Equals(t, []string{"zha3ng", "cha2ng"}, py.Pinyins("长")[0])
assert.Equals(t, []string{"zhang", "chang"}, py.Pinyins("长", py.NoTone)[0])
}
func TestPy(t *testing.T) {
t.Parallel()
assert.Equal(t, "chang zhang", py.Py("厂长", " ", py.NoTone))
}
func TestToneIndex(t *testing.T) {
t.Parallel()
assert.Equal(t, 1, py.ToneIndex("a1"))
assert.Equal(t, 904, py.ToneIndex("pu1"))
}