@@ -4,6 +4,54 @@ import (
4
4
"testing"
5
5
)
6
6
7
+ // Get country by mobile number only
8
+ var mobWithLLCountryTests = []struct {
9
+ input string
10
+ expected string
11
+ }{
12
+ // landline numbers
13
+ {"3726347343" , "EE" },
14
+ {"74997098833" , "RU" },
15
+ {"37167881727" , "LV" },
16
+ {"16466909997" , "US" },
17
+ {"14378869667" , "CA" },
18
+ {"12836907618" , "US" },
19
+ {"13406407159" , "VI" },
20
+ {"5117061970" , "PE" },
21
+ {"862185551232" , "CN" },
22
+ {"38391234999" , "XK" },
23
+
24
+ // Mobile numbers
25
+ {"39339638066" , "IT" },
26
+ {"37125641580" , "LV" },
27
+ {"43663242739" , "AT" },
28
+ {"21655886170" , "TN" },
29
+ {"3197010280754" , "NL" },
30
+ {"51999400500" , "PE" },
31
+ {"8614855512329" , "CN" },
32
+ {"38342224999" , "XK" },
33
+ }
34
+
35
+ func TestGetCountryForMobileNumberWithLandLine (t * testing.T ) {
36
+ for _ , tt := range mobWithLLCountryTests {
37
+ tt := tt
38
+ t .Run (tt .input , func (t * testing.T ) {
39
+ t .Parallel ()
40
+ country := GetISO3166ByNumber (tt .input , true )
41
+ if tt .expected == "" {
42
+ if country .CountryName != "" {
43
+ t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): must be empty, actual `%s`" , tt .input , country .CountryName )
44
+ }
45
+ } else {
46
+ expected := getISO3166ByCountry (tt .expected )
47
+ if country .CountryName != expected .CountryName {
48
+ t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): expected `%s`, actual `%s`" , tt .input , expected .CountryName , country .CountryName )
49
+ }
50
+ }
51
+ })
52
+ }
53
+ }
54
+
7
55
// Tests format mobile
8
56
var mobFormatTests = []struct {
9
57
input string
@@ -26,10 +74,14 @@ var mobFormatTests = []struct {
26
74
27
75
func TestFormatMobile (t * testing.T ) {
28
76
for _ , tt := range mobFormatTests {
29
- number := Parse (tt .input , tt .country )
30
- if number != tt .expected {
31
- t .Errorf ("Parse(number=`%s`, country=`%s`): expected `%s`, actual `%s`" , tt .input , tt .country , tt .expected , number )
32
- }
77
+ tt := tt
78
+ t .Run (tt .input , func (t * testing.T ) {
79
+ t .Parallel ()
80
+ number := Parse (tt .input , tt .country )
81
+ if number != tt .expected {
82
+ t .Errorf ("Parse(number=`%s`, country=`%s`): expected `%s`, actual `%s`" , tt .input , tt .country , tt .expected , number )
83
+ }
84
+ })
33
85
}
34
86
}
35
87
@@ -99,50 +151,6 @@ func TestFormatWithLandLine(t *testing.T) {
99
151
}
100
152
}
101
153
102
- // Get country by mobile number only
103
- var mobWithLLCountryTests = []struct {
104
- input string
105
- expected string
106
- }{
107
- // landline numbers
108
- {"3726347343" , "EE" },
109
- {"74997098833" , "RU" },
110
- {"37167881727" , "LV" },
111
- {"16466909997" , "US" },
112
- {"14378869667" , "CA" },
113
- {"12836907618" , "US" },
114
- {"13406407159" , "VI" },
115
- {"5117061970" , "PE" },
116
- {"862185551232" , "CN" },
117
- {"38391234999" , "XK" },
118
-
119
- // Mobile numbers
120
- {"39339638066" , "IT" },
121
- {"37125641580" , "LV" },
122
- {"43663242739" , "AT" },
123
- {"21655886170" , "TN" },
124
- {"3197010280754" , "NL" },
125
- {"51999400500" , "PE" },
126
- {"8614855512329" , "CN" },
127
- {"38342224999" , "XK" },
128
- }
129
-
130
- func TestGetCountryForMobileNumberWithLandLine (t * testing.T ) {
131
- for _ , tt := range mobWithLLCountryTests {
132
- country := GetISO3166ByNumber (tt .input , true )
133
- if tt .expected == "" {
134
- if country .CountryName != "" {
135
- t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): must be empty, actual `%s`" , tt .input , country .CountryName )
136
- }
137
- } else {
138
- expected := getISO3166ByCountry (tt .expected )
139
- if country .CountryName != expected .CountryName {
140
- t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): expected `%s`, actual `%s`" , tt .input , expected .CountryName , country .CountryName )
141
- }
142
- }
143
- }
144
- }
145
-
146
154
// Test the real and validated mobile number for India country
147
155
// We added "910" prefix that does not match a specification, but the numbers are really exists
148
156
var indiaMobileTests = []struct {
@@ -252,10 +260,15 @@ var indiaMobileTests = []struct {
252
260
253
261
func TestIndiaMobileNumber (t * testing.T ) {
254
262
for _ , tt := range indiaMobileTests {
255
- country := GetISO3166ByNumber (tt .input , false )
256
- if country .CountryName != "India" {
257
- t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): expected `%s`, actual `%s`" , tt .input , "India" , country .CountryName )
258
- }
263
+ tt := tt
264
+ t .Run (tt .input , func (t * testing.T ) {
265
+ t .Parallel ()
266
+
267
+ country := GetISO3166ByNumber (tt .input , false )
268
+ if country .CountryName != "India" {
269
+ t .Errorf ("GetISO3166ByNumber(number=`%s`, withLandline=false): expected `%s`, actual `%s`" , tt .input , "India" , country .CountryName )
270
+ }
271
+ })
259
272
}
260
273
}
261
274
0 commit comments