-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch_test.go
149 lines (124 loc) · 5.53 KB
/
match_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package assertion
import (
"strings"
"testing"
)
func TestAssertion_Alfanum_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Alfanum", []interface{}{"abc123"}},
{"Alfanum", []interface{}{"ABC098"}},
{"Alfanum", []interface{}{"España"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Alfanum_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Alfanum", []interface{}{"abc 123"}, "abc 123 is not alfa-numeric"},
{"Alfanum", []interface{}{"abc.123"}, "abc.123 is not alfa-numeric"},
{"Alfanum", []interface{}{"abc#123"}, "abc#123 is not alfa-numeric"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Digits_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Digits", []interface{}{"0123456789"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Digits_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Digits", []interface{}{"abc123"}, "abc123 is not only digits"},
{"Digits", []interface{}{"123.456"}, "123.456 is not only digits"},
{"Digits", []interface{}{"123#"}, "123# is not only digits"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Letters_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Letters", []interface{}{"abcDEFáöß"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Letters_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Letters", []interface{}{"abc123"}, "abc123 is not only letters"},
{"Letters", []interface{}{"abc.DEF"}, "abc.DEF is not only letters"},
{"Letters", []interface{}{"abc DEF"}, "abc DEF is not only letters"},
{"Letters", []interface{}{"abc#"}, "abc# is not only letters"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Email_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{`"first last"@mail.com`}},
{"Email", []interface{}{"test@[0.0.0.0]"}},
{"Email", []interface{}{"[email protected]"}},
{"Email", []interface{}{"test@" + strings.Repeat("subd.", 50) + "com"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Email_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Email", []interface{}{"plainaddress"}, "plainaddress is not a valid email"},
{"Email", []interface{}{"#@%^%#$@#$@#.com"}, "#@%^%#$@#$@#.com is not a valid email"},
{"Email", []interface{}{"@example.com"}, "@example.com is not a valid email"},
{"Email", []interface{}{"Joe Smith <[email protected]>"}, "Joe Smith <[email protected]> is not a valid email"},
{"Email", []interface{}{"email.example.com"}, "email.example.com is not a valid email"},
{"Email", []interface{}{"email@[email protected]"}, "email@[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"あいうえお@example.com"}, "あいうえお@example.com is not a valid email"},
{"Email", []interface{}{"[email protected] (Joe Smith)"}, "[email protected] (Joe Smith) is not a valid email"},
{"Email", []interface{}{"email@example"}, "email@example is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
{"Email", []interface{}{"first [email protected]"}, "first [email protected] is not a valid email"},
{"Email", []interface{}{"test@" + strings.Repeat("subd.", 50) + "com.es"}, "test@" + strings.Repeat("subd.", 50) + "com.es is not a valid email"},
{"Email", []interface{}{"[email protected]"}, "[email protected] is not a valid email"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Phone_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Phone", []interface{}{"+33626525690"}},
{"Phone", []interface{}{"33626525690"}},
{"Phone", []interface{}{"+16174552211"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Phone_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Phone", []interface{}{"+3362652569e"}, "+3362652569e is not a valid phone"},
{"Phone", []interface{}{"+3361231231232652569"}, "+3361231231232652569 is not a valid phone"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Ipv4_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Ipv4", []interface{}{"127.0.0.1"}},
{"Ipv4", []interface{}{"255.255.255.255"}},
{"Ipv4", []interface{}{"0.0.0.0"}},
{"Ipv4", []interface{}{"199.160.1.10"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Ipv4_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Ipv4", []interface{}{"127.0.01"}, "127.0.01 is not a valid ipv4"},
{"Ipv4", []interface{}{"256.0.0.1"}, "256.0.0.1 is not a valid ipv4"},
{"Ipv4", []interface{}{"0.0.0.0.0"}, "0.0.0.0.0 is not a valid ipv4"},
{"Ipv4", []interface{}{"0.0.0.1234"}, "0.0.0.1234 is not a valid ipv4"},
{"Ipv4", []interface{}{"0-0-0-0"}, "0-0-0-0 is not a valid ipv4"},
}
assertAllReturnsFalse(t, data)
}