-
Notifications
You must be signed in to change notification settings - Fork 0
/
mojimoji_test.go
117 lines (106 loc) · 3.18 KB
/
mojimoji_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
// Package mojimoji is a port of mojimoji package to Go.
// Original: https://github.com/studio-ousia/mojimoji
package gomojimoji
import (
"fmt"
"strings"
"testing"
"time"
)
func TestZenToHan(t *testing.T) {
type args struct {
text string
opt []Option
}
tests := []struct {
name string
args args
want string
}{
{"kana", args{"アイウエオ", nil}, "アイウエオ"},
{"ten", args{"ガギグゲゴ", nil}, "ガギグゲゴ"},
{"maru", args{"パピプペポ", nil}, "パピプペポ"},
{"digits", args{"0123", nil}, "0123"},
{"ASCII", args{"abcABC", nil}, "abcABC"},
{"symbols", args{"#?!¥", nil}, "#?!¥"},
{"hiragana", args{"あいうえお", nil}, "あいうえお"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ZenToHan(tt.args.text, tt.args.opt...); got != tt.want {
t.Errorf("ZenToHan() = %v, want %v", got, tt.want)
}
})
}
}
func TestHanToZen(t *testing.T) {
type args struct {
text string
opt []Option
}
tests := []struct {
name string
args args
want string
}{
{"kana", args{"アイウエオ", nil}, "アイウエオ"},
{"ten", args{"ガギグゲゴ", nil}, "ガギグゲゴ"},
{"maru", args{"パピプペポ", nil}, "パピプペポ"},
{"digits", args{"0123", nil}, "0123"},
{"ascii", args{"abcABC", nil}, "abcABC"},
{"symbols", args{"#?!¥", nil}, "#?!¥"},
{"hiragana", args{"あいうえお", nil}, "あいうえお"},
{"mixed", args{"ア゙イ゙ヴエ゙オ゙", nil}, "ア゛イ゛ヴエ゛オ゛"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HanToZen(tt.args.text, tt.args.opt...); got != tt.want {
t.Errorf("HanToZen() = %v, want %v", got, tt.want)
}
})
}
}
func ExampleZenToHan() {
fmt.Println(ZenToHan("ニュージーランド"))
fmt.Println(ZenToHan("ニュージーランド Auckland 0123", Kana(false), Digits(true)))
//Output:
// ニュージーランド
// ニュージーランド Auckland 0123
}
func ExampleHanToZen() {
fmt.Println(HanToZen("ニュージーランド"))
fmt.Println(HanToZen("ニュージーランド Auckland 6012", ASCII(true), Digits(false), Kana(false)))
//Output:
//ニュージーランド
//ニュージーランド Auckland 6012
}
func BenchmarkZenToHan(b *testing.B) {
s := strings.Repeat("ABCDEFG012345", 10)
for n := 0; n < b.N; n++ {
ZenToHan(s)
}
}
func BenchmarkZenToHanConv(b *testing.B) {
// this benchmark is similar to that for python mojimoji library.
s := strings.Repeat("ABCDEFG012345", 10)
start := time.Now()
for n := 0; n < 1000000; n++ {
ZenToHan(s)
}
b.Log(time.Since(start))
}
func BenchmarkHanToZen(b *testing.B) {
s := strings.Repeat("ABCDEFG012345", 10)
for n := 0; n < b.N; n++ {
HanToZen(s)
}
}
func BenchmarkHanToZenConv(b *testing.B) {
// this benchmark is similar to that for python mojimoji library.
s := strings.Repeat("ABCDEFG012345", 10)
start := time.Now()
for n := 0; n < 1000000; n++ {
HanToZen(s)
}
b.Log(time.Since(start))
}