-
Notifications
You must be signed in to change notification settings - Fork 148
/
shortnumber_info_test.go
74 lines (63 loc) · 1.9 KB
/
shortnumber_info_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
package phonenumbers
import (
"testing"
"github.com/stretchr/testify/assert"
)
////////// Copied from java-libphonenumber
/**
* Unit tests for ShortNumberInfo.java
*/
func TestIsPossibleShortNumber(t *testing.T) {
countryCode := int32(33)
nationalNumber := uint64(123456)
possibleNumber := &PhoneNumber{
CountryCode: &countryCode,
NationalNumber: &nationalNumber,
}
assert.True(t, IsPossibleShortNumber(possibleNumber))
possibleNumber, err := Parse("123456", "FR")
if err != nil {
t.Errorf("Error parsing number: %s: %s", "123456", err)
}
assert.True(t, IsPossibleShortNumberForRegion(possibleNumber, "FR"))
nationalNumber = 9
impossibleNumber := &PhoneNumber{
CountryCode: &countryCode,
NationalNumber: &nationalNumber,
}
assert.False(t, IsPossibleShortNumber(impossibleNumber))
// Note that GB and GG share the country calling code 44, and that this number is possible but
// not valid.
countryCode = 44
nationalNumber = 11001
possibleNumber = &PhoneNumber{
CountryCode: &countryCode,
NationalNumber: &nationalNumber,
}
assert.True(t, IsPossibleShortNumber(possibleNumber))
}
func TestIsValidShortNumber(t *testing.T) {
countryCode := int32(33)
nationalNumber := uint64(1010)
validNumber := &PhoneNumber{
CountryCode: &countryCode,
NationalNumber: &nationalNumber,
}
assert.True(t, IsValidShortNumber(validNumber))
validNumber, err := Parse("1010", "FR")
if err != nil {
t.Errorf("Error parsing number: %s: %s", "1010", err)
}
assert.True(t, IsValidShortNumberForRegion(validNumber, "FR"))
nationalNumber = uint64(123456)
invalidNumber := &PhoneNumber{
CountryCode: &countryCode,
NationalNumber: &nationalNumber,
}
assert.False(t, IsValidShortNumber(invalidNumber))
invalidNumber, err = Parse("123456", "FR")
if err != nil {
t.Errorf("Error parsing number: %s: %s", "1010", err)
}
assert.False(t, IsValidShortNumberForRegion(invalidNumber, "FR"))
}