-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
135 lines (124 loc) · 3.16 KB
/
common_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
package verify
import "testing"
var (
threeCharacterNames = []string{
"bob",
"mat",
"jim",
"sue",
}
validIntegers = []string{
"123",
"4",
"9993",
}
invalidIntegers = []string{
"12 3",
" 123",
" 1",
"1,200",
"fm",
"dskq",
" a",
}
)
func Test_Length(t *testing.T) {
for _, name := range threeCharacterNames {
v := Verify(name).MinLength(2).IsVerified()
expect(t, v, true)
v = Verify(name).MinLength(3).IsVerified()
expect(t, v, true)
v = Verify(name).MinLength(3).MaxLength(8).IsVerified()
expect(t, v, true)
v = Verify(name).MinLength(3).MaxLength(3).IsVerified()
expect(t, v, true)
v = Verify(name).MinLength(4).MaxLength(8).IsVerified()
expect(t, v, false)
v = Verify(name).Length(3).IsVerified()
expect(t, v, true)
v = Verify(name).Length(2).IsVerified()
expect(t, v, false)
v = Verify(name).Length(4).IsVerified()
expect(t, v, false)
v = Verify(name).IsntLength(123).IsVerified()
expect(t, v, true)
}
}
func Test_Integers(t *testing.T) {
for _, integer := range validIntegers {
v := Verify(integer).Int().IsVerified()
expect(t, v, true)
v = Verify(integer).IsntInt().IsVerified()
refute(t, v, true)
}
for _, integer := range invalidIntegers {
v := Verify(integer).Int().IsVerified()
expect(t, v, false)
v = Verify(integer).IsntInt().IsVerified()
refute(t, v, false)
}
}
func Test_Is(t *testing.T) {
v := Verify("seafood").Is("seafood").IsVerified()
expect(t, v, true)
v = Verify("seafood").Is("Seafood").IsVerified()
expect(t, v, false)
v = Verify("seafood").Is("Poultry").IsVerified()
expect(t, v, false)
}
func Test_Isnt(t *testing.T) {
v := Verify("seafood").Isnt("poultry").IsVerified()
expect(t, v, true)
v = Verify("seafood").Isnt("seafood").IsVerified()
expect(t, v, false)
}
func Test_IsntEmpty(t *testing.T) {
v := Verify("seafood").IsntEmpty().IsVerified()
expect(t, v, true)
v = Verify("").IsntEmpty().IsVerified()
expect(t, v, false)
}
func Test_IsEmpty(t *testing.T) {
v := Verify("").IsEmpty().IsVerified()
expect(t, v, true)
v = Verify("seafood").IsEmpty().IsVerified()
expect(t, v, false)
}
func Test_Contains(t *testing.T) {
v := Verify("team").Contains("i").IsVerified()
expect(t, v, false)
v = Verify("team").Contains("e").Contains("a").IsVerified()
expect(t, v, true)
v = Verify("team").Length(4).Contains("e").IsVerified()
expect(t, v, true)
v = Verify("team").MaxLength(20).MinLength(5).Contains("e").IsVerified()
expect(t, v, false)
v = Verify("team").MaxLength(8).MinLength(2).IContains("E").IsVerified()
expect(t, v, true)
}
func Test_DoesntContain(t *testing.T) {
v := Verify("team").DoesntContain("i").IsVerified()
expect(t, v, true)
v = Verify("team").DoesntContain("e").IsVerified()
expect(t, v, false)
v = Verify("team").MaxLength(8).IDoesntContain("yy").IsVerified()
expect(t, v, true)
}
func Test_IsIn(t *testing.T) {
array := []string{
"There",
"is",
"no",
"I",
"in",
"team",
}
v := Verify("team").IsIn(array).IsVerified()
expect(t, v, true)
v = Verify("eye").IsIn(array).IsVerified()
expect(t, v, false)
v = Verify("eye").IsntIn(array).IsVerified()
expect(t, v, true)
v = Verify("team").IsntIn(array).IsVerified()
expect(t, v, false)
}