-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathphone_number_test.go
71 lines (67 loc) · 1.36 KB
/
phone_number_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
package gsms
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestPhoneNumber(t *testing.T) {
as := assert.New(t)
phoneNumber := NewPhoneNumber(18888888888, "86")
as.Equal(86, phoneNumber.IDDCode())
as.EqualValues(18888888888, phoneNumber.Number())
as.Equal("+8618888888888", phoneNumber.UniversalNumber())
as.Equal("+8618888888888", phoneNumber.String())
as.Equal("008618888888888", phoneNumber.ZeroPrefixedNumber())
as.Equal("+86", phoneNumber.PrefixedIDDCode("+"))
as.Equal("0086", phoneNumber.PrefixedIDDCode("00"))
as.True(phoneNumber.InChineseMainland())
}
func TestPhoneNumber_IDDCode(t *testing.T) {
type fields struct {
number int
iddCode string
}
tests := []struct {
name string
fields fields
want int
}{
{
name: "+86",
fields: fields{
number: 18888888888,
iddCode: "+86",
},
want: 86,
},
{
name: "0086",
fields: fields{
number: 18888888888,
iddCode: "0086",
},
want: 86,
},
{
name: "empty",
fields: fields{
number: 18888888888,
iddCode: "",
},
want: 0,
},
{
name: "other",
fields: fields{
number: 18888888888,
iddCode: "other",
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewPhoneNumber(tt.fields.number, tt.fields.iddCode)
assert.Equalf(t, tt.want, p.IDDCode(), "IDDCode()")
})
}
}