-
Notifications
You must be signed in to change notification settings - Fork 1
/
zengincode_test.go
234 lines (228 loc) · 4.83 KB
/
zengincode_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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package zengincode
import (
"os"
"sort"
"testing"
)
func TestBankNew(t *testing.T) {
os.Setenv("ZENGIN_SOURCE_ROOT", "source-data")
tests := []struct {
name string
code string
want *Bank
wantErr bool
}{
{
name: "ufj",
code: "0005",
want: &Bank{
Name: "三菱UFJ",
Kana: "ミツビシユ-エフジエイ",
Hira: "みつびしゆ-えふじえい",
Roma: "mitsubishiyu-efujiei",
},
wantErr: false,
},
{
name: "mizuho",
code: "0001",
want: &Bank{
Name: "みずほ",
Kana: "ミズホ",
Hira: "みずほ",
Roma: "mizuho",
},
wantErr: false,
},
{
name: "mitsuisumitomo",
code: "0009",
want: &Bank{
Name: "三井住友",
Kana: "ミツイスミトモ",
Hira: "みついすみとも",
Roma: "mitsuisumitomo",
},
wantErr: false,
},
{
name: "suruga",
code: "0150",
want: &Bank{
Name: "スルガ",
Kana: "スルガ",
Hira: "するが",
Roma: "suruga",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New()
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
return
}
bank, err := got.Find(tt.code)
if (err != nil) != tt.wantErr {
t.Errorf("Find() error = %v", err)
return
}
if tt.want.Name != bank.Name {
t.Errorf("New() Name = %s, want %s", bank.Name, tt.want.Name)
return
}
if tt.want.Kana != bank.Kana {
t.Errorf("New() Kana = %s, want %s", bank.Kana, tt.want.Kana)
return
}
if tt.want.Hira != bank.Hira {
t.Errorf("New() Hira = %s, want %s", bank.Hira, tt.want.Hira)
return
}
if tt.want.Roma != bank.Roma {
t.Errorf("New() Roma = %s, want %s", bank.Roma, tt.want.Roma)
return
}
})
}
}
func TestBranch(t *testing.T) {
os.Setenv("ZENGIN_SOURCE_ROOT", "source-data")
tests := []struct {
name string
code string
branchCode string
want *Branch
wantErr bool
}{
{
name: "ufj roppongi",
code: "0005",
branchCode: "045",
want: &Branch{
Code: "045",
Name: "六本木",
Kana: "ロツポンギ",
Hira: "ろつぽんぎ",
Roma: "rotsupongi",
},
wantErr: false,
},
{
name: "mizuho ebisu",
code: "0001",
branchCode: "188",
want: &Branch{
Name: "恵比寿",
Kana: "エビス",
Hira: "えびす",
Roma: "ebisu",
},
wantErr: false,
},
{
name: "mitsuisumitomo gifu",
code: "0009",
branchCode: "407",
want: &Branch{
Name: "岐阜",
Kana: "ギフ",
Hira: "ぎふ",
Roma: "gifu",
},
wantErr: false,
},
{
name: "suruga",
code: "0150",
branchCode: "640",
want: &Branch{
Name: "本店",
Kana: "ホンテン",
Hira: "ほんてん",
Roma: "honten",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New()
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
return
}
bank, err := got.Find(tt.code)
if (err != nil) != tt.wantErr {
t.Errorf("Find() error = %v", err)
return
}
branch, err := bank.Branches.Find(tt.branchCode)
if (err != nil) != tt.wantErr {
t.Errorf("Find() error = %v", err)
return
}
if tt.want.Name != branch.Name {
t.Errorf("New() Name = %s, want %s", branch.Name, tt.want.Name)
return
}
if tt.want.Kana != branch.Kana {
t.Errorf("New() Kana = %s, want %s", branch.Kana, tt.want.Kana)
return
}
if tt.want.Hira != branch.Hira {
t.Errorf("New() Hira = %s, want %s", branch.Hira, tt.want.Hira)
return
}
if tt.want.Roma != branch.Roma {
t.Errorf("New() Roma = %s, want %s", branch.Roma, tt.want.Roma)
return
}
})
}
}
func TestFuzzySearch(t *testing.T) {
os.Setenv("ZENGIN_SOURCE_INCLUDE", "TRUE")
tests := []struct {
name string
bankName string
want []string
wantErr bool
}{
{
name: "mitsubishi ufj",
bankName: "三菱",
want: []string{"三菱UFJ", "長崎三菱信組", "三菱UFJ信託"},
wantErr: false,
},
{
name: "risona",
bankName: "りそな",
want: []string{"りそな", "埼玉りそな"},
wantErr: false,
},
{
name: "code",
bankName: "003",
want: []string{"0033", "0034", "0035", "0036", "0038", "0039", "0403", "0603", "1003", "3003"},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New()
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
return
}
banks := got.FuzzySearch(tt.bankName)
sort.Strings(banks)
if tt.want[0] != banks[0] {
t.Errorf("FuzzySearch() banks = %v, want %v", banks, tt.want)
return
}
})
}
}