Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/lib/number/utils_test.go
988 views
1
package number
2
3
import (
4
"github.com/stretchr/testify/assert"
5
"testing"
6
)
7
8
func TestUtils(t *testing.T) {
9
t.Run("FormatNumber", func(t *testing.T) {
10
t.Run("should format number correctly", func(t *testing.T) {
11
result := FormatNumber("+1 555-444-2222")
12
13
assert.Equal(t, result, "15554442222", "they should be equal")
14
})
15
16
t.Run("should format number correctly", func(t *testing.T) {
17
result := FormatNumber("+1 (315) 284-1580")
18
19
assert.Equal(t, result, "13152841580", "they should be equal")
20
})
21
})
22
23
t.Run("ParseCountryCode", func(t *testing.T) {
24
t.Run("should parse country code correctly", func(t *testing.T) {
25
result := ParseCountryCode("+33 679368229")
26
27
assert.Equal(t, result, "FR", "they should be equal")
28
})
29
30
t.Run("should parse country code correctly", func(t *testing.T) {
31
result := ParseCountryCode("+1 315-284-1580")
32
33
assert.Equal(t, result, "US", "they should be equal")
34
})
35
36
t.Run("should parse country code correctly", func(t *testing.T) {
37
result := ParseCountryCode("4566118311")
38
39
assert.Equal(t, result, "DK", "they should be equal")
40
})
41
})
42
43
t.Run("IsValid", func(t *testing.T) {
44
t.Run("should validate phone number", func(t *testing.T) {
45
result := IsValid("+1 315-284-1580")
46
47
assert.Equal(t, result, true, "they should be equal")
48
})
49
50
t.Run("should validate phone number", func(t *testing.T) {
51
result := IsValid("P+1 315-284-1580A")
52
53
assert.Equal(t, result, false, "they should be equal")
54
})
55
})
56
}
57
58