-
Notifications
You must be signed in to change notification settings - Fork 37
/
example_test.go
executable file
·132 lines (113 loc) · 2.7 KB
/
example_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package gpy_test
import (
"fmt"
"github.com/go-ego/gpy"
)
var hans = "中国话"
func ExampleConvert() {
fmt.Println("default:", gpy.Convert(hans, nil))
// Output: default: [[zhong] [guo] [hua]]
}
func ExamplePinyin_default() {
a := gpy.NewArgs()
fmt.Println("default:", gpy.Pinyin(hans, a))
// Output: default: [[zhong] [guo] [hua]]
}
func ExampleHanPinyin_default() {
a := gpy.NewArgs()
fmt.Println("default:", gpy.HanPinyin(hans, a))
// Output: default: [[zhong] [guo] [hua]]
}
func ExamplePinyin_normal() {
a := gpy.NewArgs()
a.Style = gpy.Normal
fmt.Println("Normal:", gpy.Pinyin(hans, a))
// Output: Normal: [[zhong] [guo] [hua]]
}
func ExamplePinyin_tone() {
a := gpy.NewArgs()
a.Style = gpy.Tone
fmt.Println("Tone:", gpy.Pinyin(hans, a))
// Output: Tone: [[zhōng] [guó] [huà]]
}
func ExamplePinyin_tone2() {
a := gpy.NewArgs()
a.Style = gpy.Tone2
fmt.Println("Tone2:", gpy.Pinyin(hans, a))
// Output: Tone2: [[zho1ng] [guo2] [hua4]]
}
func ExamplePinyin_initials() {
a := gpy.NewArgs()
a.Style = gpy.Initials
fmt.Println("Initials:", gpy.Pinyin(hans, a))
// Output: Initials: [[zh] [g] [h]]
}
func ExamplePinyin_firstLetter() {
a := gpy.NewArgs()
a.Style = gpy.FirstLetter
fmt.Println(gpy.Pinyin(hans, a))
// Output: [[z] [g] [h]]
}
func ExamplePinyin_finals() {
a := gpy.NewArgs()
a.Style = gpy.Finals
fmt.Println(gpy.Pinyin(hans, a))
// Output: [[ong] [uo] [ua]]
}
func ExamplePinyin_finalsTone() {
a := gpy.NewArgs()
a.Style = gpy.FinalsTone
fmt.Println(gpy.Pinyin(hans, a))
// Output: [[ōng] [uó] [uà]]
}
func ExamplePinyin_finalsTone2() {
a := gpy.NewArgs()
a.Style = gpy.FinalsTone2
fmt.Println(gpy.Pinyin(hans, a))
// Output: [[o1ng] [uo2] [ua4]]
}
func ExamplePinyin_heteronym() {
a := gpy.NewArgs()
a.Heteronym = true
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// Output: [[zho1ng zho4ng] [guo2] [hua4]]
}
func ExamplePinyin_fallbackCustom1() {
hans := "中国话abc"
a := gpy.NewArgs()
a.Fallback = func(r rune, a gpy.Args) []string {
return []string{string(r + 1)}
}
fmt.Println(gpy.HanPinyin(hans, a))
// Output: [[zhong] [guo] [hua] [b] [c] [d]]
}
func ExamplePinyin_fallbackCustom2() {
hans := "中国话アイウ"
a := gpy.NewArgs()
a.Fallback = func(r rune, a gpy.Args) []string {
data := map[rune][]string{
'ア': {"a"},
'イ': {"i"},
'ウ': {"u"},
}
s, ok := data[r]
if ok {
return s
} else {
return []string{}
}
}
fmt.Println(gpy.HanPinyin(hans, a))
// Output: [[zhong] [guo] [hua] [a] [i] [u]]
}
func ExampleLazyPinyin() {
a := gpy.NewArgs()
fmt.Println(gpy.LazyPinyin(hans, a))
// Output: [zhong guo hua]
}
func ExampleSlug() {
a := gpy.NewArgs()
fmt.Println(gpy.Slug(hans, a))
// Output: zhong-guo-hua
}