-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber-parser_test.go
50 lines (41 loc) · 992 Bytes
/
number-parser_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
package numberparser
import (
"strings"
"testing"
)
func TestPhoneNumberDataCsv_NotEmpty(t *testing.T){
if len(PhoneNumberDataCsv) == 0 {
t.Errorf("PhoneNumberDataCsv is empty!")
}
}
func TestPhoneNumberData_Parsed(t *testing.T){
if len(PhoneNumberData) == 0 {
t.Errorf("PhoneNumberData is empty!")
}
}
func TestNormalizeE164(t *testing.T) {
testcases := []struct {
input, output string
}{
{"18005551212", "+18005551212"},
{" 18005551212", "+18005551212"},
}
for _, tc := range testcases {
res := NormalizeE164(tc.input)
if res != tc.output {
t.Errorf("NoramlizeE164: in: %s want: %s", res, tc.output)
}
}
}
func FuzzNormalizeE164(f *testing.F) {
testcases := []string{"18005551212", "+18005551212", " 18005551212", "08005551212"}
for _, tc := range testcases {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, arg string) {
res := NormalizeE164(arg)
if !strings.HasPrefix(res, "+") {
t.Errorf("NormalizeE164 fails %s --> %s", arg, res)
}
})
}