-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_test.go
149 lines (140 loc) · 1.93 KB
/
normalize_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
package normalize_phone
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalizePhone(t *testing.T) {
testCases := []struct {
phoneNumber string
countryCode string
expectedResult string
expectedErr error
}{
// international
{
"+7 111 222 33 44",
"ru",
"+71112223344",
nil,
},
{
"+375 11 222 33 44",
"ru",
"+375112223344",
nil,
},
{
"+49 111 222 33 44",
"ru",
"+491112223344",
nil,
},
{
"+49 1111 222 33 44",
"ru",
"+4911112223344",
nil,
},
{
"+380 11 222 33 44",
"ru",
"+380112223344",
nil,
},
{
"+49 1111 222 33 44 5",
"ru",
"",
ErrIncorrectPhone,
},
// ru
{
"8 111 222 33 44",
"ru",
"+71112223344",
nil,
},
{
"111 222 33 44",
"ru",
"+71112223344",
nil,
},
{
"9527162525",
"ru",
"+79527162525",
nil,
},
{
"79527162525",
"ru",
"+79527162525",
nil,
},
// by
{
"80 11 222 33 44",
"by",
"+375112223344",
nil,
},
{
"11 222 33 44",
"by",
"+375112223344",
nil,
},
// de
{
"0 111 222 33 44",
"de",
"+491112223344",
nil,
},
{
"111 222 33 44",
"de",
"+491112223344",
nil,
},
{
"0 1111 222 33 44",
"de",
"+4911112223344",
nil,
},
{
"1111 222 33 44",
"de",
"+4911112223344",
nil,
},
// ua
{
"0 11 222 33 44",
"ua",
"+380112223344",
nil,
},
{
"11 222 33 44",
"ua",
"+380112223344",
nil,
},
{
"",
"any country",
"",
nil,
},
}
// Iterating over the test cases, call the function under test and assert the output.
for i, testCase := range testCases {
actualResult, err := NormalizePhone(testCase.countryCode, testCase.phoneNumber)
assert.Equal(t, testCase.expectedResult, actualResult, fmt.Sprintf("case %d: %v", i, testCase))
assert.Equal(t, testCase.expectedErr, err, fmt.Sprintf("case %d: %v", i, testCase))
}
}