forked from dmgk/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphone_number_test.go
52 lines (44 loc) · 1.13 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
package faker
import (
"fmt"
"regexp"
"testing"
"syreclabs.com/go/faker/locales"
)
func TestPhoneNumberPhoneNumber(t *testing.T) {
testMatchRx(t, PhoneNumber().PhoneNumber, `\w+`)
}
func TestPhoneNumberCellPhone(t *testing.T) {
Locale = locales.De
testMatchRx(t, PhoneNumber().CellPhone, `\+49-\w+`)
Locale = locales.En
}
func TestPhoneNumberAreaCode(t *testing.T) {
Locale = locales.En_US
testMatchRx(t, PhoneNumber().AreaCode, `\d+`)
Locale = locales.En
}
func TestPhoneNumberExchangeCode(t *testing.T) {
Locale = locales.En_US
testMatchRx(t, PhoneNumber().AreaCode, `\d+`)
Locale = locales.En
}
func TestPhoneNumberSubscriberNumber(t *testing.T) {
args := []int{3, 4, 5}
for _, digits := range args {
for i := 0; i < 10; i++ {
rx := fmt.Sprintf(`\d{%d}`, digits)
res := PhoneNumber().SubscriberNumber(digits)
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}
}
}
func TestPhoneNumberStringer(t *testing.T) {
rx := `\w+`
res := fmt.Sprintf("%s", PhoneNumber())
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}