-
Notifications
You must be signed in to change notification settings - Fork 37
/
internet_test.go
64 lines (50 loc) · 1.42 KB
/
internet_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
package faker
import (
"regexp"
"testing"
)
func TestInternetEmail(t *testing.T) {
testMatchRx(t, Internet().Email, `\w+@\w+\.\w+`)
}
func TestInternetFreeEmail(t *testing.T) {
testMatchRx(t, Internet().FreeEmail, `\w+@\w+\.\w+`)
}
func TestInternetSafeEmail(t *testing.T) {
testMatchRx(t, Internet().SafeEmail, `\w+@example\.\w+`)
}
func TestInternetUserName(t *testing.T) {
testMatchRx(t, Internet().UserName, `\w+`)
}
func TestInternetPassword(t *testing.T) {
rx := `\w+`
for i := 0; i < 10; i++ {
res := Internet().Password(RandomInt(4, 8), RandomInt(8, 16))
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}
}
func TestInternetDomainName(t *testing.T) {
testMatchRx(t, Internet().DomainName, `\w+\.\w+`)
}
func TestInternetDomainWord(t *testing.T) {
testMatchRx(t, Internet().DomainWord, `\w+`)
}
func TestInternetDomainSuffix(t *testing.T) {
testMatchRx(t, Internet().DomainSuffix, `\w+`)
}
func TestMacAddress(t *testing.T) {
testMatchRx(t, Internet().MacAddress, `([0-9a-f]{2}:){5}[0-9a-f]{2}`)
}
func TestIpV4Address(t *testing.T) {
testMatchRx(t, Internet().IpV4Address, `(\d{1,3}\.){3}\d{1,3}`)
}
func TestIpV6Address(t *testing.T) {
testMatchRx(t, Internet().IpV6Address, `([0-9a-f]{4}:){7}[0-9a-f]{4}`)
}
func TestUrl(t *testing.T) {
testMatchRx(t, Internet().Url, `http://\w+\.\w+/\w+`)
}
func TestSlug(t *testing.T) {
testMatchRx(t, Internet().Slug, `\w+`)
}