-
Notifications
You must be signed in to change notification settings - Fork 11
/
kana_test.go
206 lines (183 loc) · 5.04 KB
/
kana_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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package kana
import "testing"
type kanaTest struct {
orig, want string
}
var hiraganaToRomajiTests = []kanaTest{
{"ああいうえお", "aaiueo"},
{"かんじ", "kanji"},
{"ちゃう", "chau"},
{"きょうじゅ", "kyouju"},
{"な\nに ぬ ね の", "na\nni nu ne no"},
{"ばか dog", "baka dog"},
{"きった", "kitta"},
{"はんのう", "hannnou"},
{"ぜんいん", "zennin"},
{"んい", "nni"},
{"はんのう", "hannnou"},
{"はんおう", "hannou"},
{"あうでぃ", "audexi"},
{"だぢづを", "dajiduwo"},
{"ぢゃぢょぢゅ", "jazoju"},
}
func TestHiraganaToRomaji(t *testing.T) {
for _, tt := range hiraganaToRomajiTests {
if got := KanaToRomaji(tt.orig); got != tt.want {
t.Errorf("KanaToRomaji(%q) = %q, want %q", tt.orig, got, tt.want)
}
}
}
var katakanaToRomajiTests = []kanaTest{
{"バナナ", "banana"},
{"カンジ", "kanji"},
{"テレビ", "terebi"},
{"baking バナナ pancakes", "baking banana pancakes"},
{"ベッド", "beddo"},
{"モーター", "mo-ta-"},
{"CDプレーヤー", "CDpure-ya-"},
{"オーバーヘッドキック", "o-ba-heddokikku"},
{"ハンノウ", "hannnou"},
{"アウディ", "audexi"},
{"ダヂヅヲ", "dajiduwo"},
{"ヂャヂョヂュ", "jazoju"},
}
func TestKatakanaToRomaji(t *testing.T) {
for _, tt := range katakanaToRomajiTests {
if got := KanaToRomaji(tt.orig); got != tt.want {
t.Errorf("KanaToRomaji(%q) = %q, want %q", tt.orig, got, tt.want)
}
}
}
var romajiToKatakanaTests = []kanaTest{
{"banana", "バナナ"},
{"rajio", "ラジオ"},
{"terebi", "テレビ"},
{"furi-ta-", "フリーター"},
{"fa-suto", "ファースト"},
{"fesutibaru", "フェスティバル"},
{"ryukkusakku", "リュックサック"},
{"myu-jikku", "ミュージック"},
{"nyanda", "ニャンダ"},
{"hyakumeootokage", "ヒャクメオオトカゲ"},
{"CDプレーヤー", "CDプレーヤー"},
{"cheri-", "チェリー"},
{"otukare", "オツカレ"},
}
func TestRomajiToKatakana(t *testing.T) {
for _, tt := range romajiToKatakanaTests {
if got := RomajiToKatakana(tt.orig); got != tt.want {
t.Errorf("RomajiToKatakana(%q) = %q, want %q", tt.orig, got, tt.want)
}
}
}
var romajiToHiraganaTests = []kanaTest{
{"banana", "ばなな"},
{"hiragana", "ひらがな"},
{"suppai", "すっぱい"},
{"konnnichiha", "こんにちは"},
{"zouryou", "ぞうりょう"},
{"myaku", "みゃく"},
{"nyanko", "にゃんこ"},
{"hyaku", "ひゃく"},
{"motoduku", "もとづく"},
{"zenin", "ぜにん"},
{"zennin", "ぜんいん"},
{"hannnou", "はんのう"},
{"hannou", "はんおう"},
{"chuutohanpa", "ちゅうとはんぱ"},
{"CDプレーヤー", "CDプレーヤー"},
{"meccha", "めっちゃ"},
{"che", "ちぇ"},
{"otukare", "おつかれ"},
}
func TestRomajiToHiragana(t *testing.T) {
for _, tt := range romajiToHiraganaTests {
if got := RomajiToHiragana(tt.orig); got != tt.want {
t.Errorf("RomajiToHiragana(%q) = %q, want %q", tt.orig, got, tt.want)
}
}
}
type typeTest struct {
text string
valid bool
}
var isLatinTests = []typeTest{
{"banana", true},
{"a sd ds ds", true},
{"ばなな", false},
{"ファースト", false},
{"myu-jikku", true},
{"CDプレーヤー", false},
}
func TestIsLatin(t *testing.T) {
for _, tt := range isLatinTests {
if got := IsLatin(tt.text); got != tt.valid {
t.Errorf("IsLatin(%q) = %t, want %t", tt.text, got, tt.valid)
}
}
}
var isKanaTests = []typeTest{
{"ばなな", true},
{"ファースト", true},
{"test", false},
}
func TestIsKana(t *testing.T) {
for _, tt := range isKanaTests {
if got := IsKana(tt.text); got != tt.valid {
t.Errorf("IsKana(%q) = %t, want %t", tt.text, got, tt.valid)
}
}
}
var isHiraganaTests = []typeTest{
{"ばなな", true},
{"ファースト", false},
{"test", false},
}
func TestIsHiragana(t *testing.T) {
for _, tt := range isHiraganaTests {
if got := IsHiragana(tt.text); got != tt.valid {
t.Errorf("IsHiragana(%q) = %t, want %t", tt.text, got, tt.valid)
}
}
}
var isKatakanaTests = []typeTest{
{"ばなな", false},
{"ファースト", true},
{"test", false},
}
func TestIsKatakana(t *testing.T) {
for _, tt := range isKatakanaTests {
if got := IsKatakana(tt.text); got != tt.valid {
t.Errorf("IsKatakana(%q) = %t, want %t", tt.text, got, tt.valid)
}
}
}
var isKanjiTests = []typeTest{
{"ばなな", false},
{"ファースト", false},
{"test", false},
{"路加", true},
{"減少", true},
}
func TestIsKanji(t *testing.T) {
for _, tt := range isKanjiTests {
if got := IsKanji(tt.text); got != tt.valid {
t.Errorf("IsKanji(%q) = %t, want %t", tt.text, got, tt.valid)
}
}
}
var normalizeRomajiTests = []kanaTest{
{"myuujikku", "myu-jikku"},
{"Myūjikku", "myu-jikku"},
{"Banana", "banana"},
{"shitsuree", "shitsurei"},
{"減少", "減少"},
{"myuujikku Myūjikku Banana shitsuree", "myu-jikku myu-jikku banana shitsurei"},
}
func TestNormalizeRomaji(t *testing.T) {
for _, tt := range normalizeRomajiTests {
if got := NormalizeRomaji(tt.orig); got != tt.want {
t.Errorf("NormalizeRomaji(%q) = %q, want %q", tt.orig, got, tt.want)
}
}
}