-
Notifications
You must be signed in to change notification settings - Fork 0
/
r2k_test.go
81 lines (76 loc) · 2.57 KB
/
r2k_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
package nihon_test
import (
"testing"
"github.com/kinbiko/nihon-go"
)
func TestRomaji2Kana(t *testing.T) {
t.Run("hiragana", func(st *testing.T) {
for _, tc := range []struct{ exp, in string }{
{in: "", exp: ""},
{in: "a", exp: "あ"},
{in: "ka", exp: "か"},
{in: "tsu", exp: "つ"},
{in: "shi", exp: "し"},
{in: "nani", exp: "なに"},
{
// Kana pangram/isogram. Only uses basic forms of hiragana (i.e. no 'ga' and no 'gya', 'ttsu', 'nma')
in: "irohanihohetochirinuruwowakayotaresotsunenaramuuwinookuyamakefukoeteasakiyumemishiwehimosesu",
exp: "いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす",
},
{in: "nandeyanen", exp: "なんでやねん"},
{in: "chuushajou", exp: "ちゅうしゃじょう"},
{in: "chottomatte", exp: "ちょっとまって"},
{in: "sakki", exp: "さっき"},
{in: "massugu", exp: "まっすぐ"},
{in: "mettani", exp: "めったに"},
{in: "happyou", exp: "はっぴょう"},
{in: "joji", exp: "じょじ"},
} {
st.Run(tc.in, func(sst *testing.T) {
got, err := nihon.RomajiToKana(tc.in)
if err != nil {
sst.Fatalf("Unexpected error: %s", err.Error())
}
if tc.exp != got {
sst.Fatalf("expected '%s' but got '%s'", tc.exp, got)
}
})
}
})
t.Run("katakana", func(st *testing.T) {
for _, tc := range []struct{ exp, in string }{
{in: "A", exp: "ア"},
{in: "AKA", exp: "アカ"},
{in: "BAAGENSEERU", exp: "バーゲンセール"},
{in: "GURUDOBURANDOSEN", exp: "グルドブランドセン"},
{in: "PYUU", exp: "ピュー"},
{in: "TOUKYOU", exp: "トーキョー"},
} {
st.Run(tc.in, func(sst *testing.T) {
got, err := nihon.RomajiToKana(tc.in)
if err != nil {
sst.Fatalf("Unexpected error: %s", err.Error())
}
if tc.exp != got {
sst.Fatalf("expected '%s' but got '%s'", tc.exp, got)
}
})
}
})
t.Run("negative cases", func(st *testing.T) {
for _, tc := range []struct{ exp, in string }{
{in: "fishu", exp: "parse error: parsed up until 'しゅい' when getting 'could not find right-most kana for 'f''"},
{in: "-", exp: "parse error: parsed up until '' when getting 'could not find right-most kana for '-''"},
} {
st.Run(tc.in, func(sst *testing.T) {
got, err := nihon.RomajiToKana(tc.in)
if err == nil {
sst.Fatalf("Expected error but successfully parsed '%s' as '%s'", tc.in, got)
}
if err.Error() != tc.exp {
sst.Fatalf("Expected error '%s' but got '%s'", tc.exp, err.Error())
}
})
}
})
}