-
Notifications
You must be signed in to change notification settings - Fork 2
/
string_test.go
159 lines (143 loc) · 4.45 KB
/
string_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
150
151
152
153
154
155
156
157
158
159
package verify_test
import (
"regexp"
"testing"
"github.com/fluentassert/verify"
)
func TestString(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("").Empty()
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("val").Empty()
assertFailed(t, msg, "the value was not an empty string")
})
})
t.Run("NotEmpty", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("val").NotEmpty()
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("").NotEmpty()
assertFailed(t, msg, "the value was \"\"")
})
})
t.Run("Contains", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("text").Contain("ex")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("text").Contain("asd")
assertFailed(t, msg, "the value does not contain the substring")
})
})
t.Run("NotContains", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("text").NotContain("asd")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("text").NotContain("ex")
assertFailed(t, msg, "the value contains the substring")
})
})
t.Run("Prefix", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("[ok]a").Prefix("[ok]")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("a[ok]").Prefix("[ok]")
assertFailed(t, msg, "the value does not have the prefix")
})
})
t.Run("NoPrefix", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("a[ok]").NoPrefix("[ok]")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("[ok]a").NoPrefix("[ok]")
assertFailed(t, msg, "the value has the prefix")
})
})
t.Run("Sufix", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("a[ok]").Sufix("[ok]")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("[ok]a").Sufix("[ok]")
assertFailed(t, msg, "the value does not have the sufix")
})
})
t.Run("NoSufix", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("[ok]a").NoSufix("[ok]")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("a[ok]").NoSufix("[ok]")
assertFailed(t, msg, "the value has the sufix")
})
})
t.Run("EqualFold", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("aBc").EqualFold("ABC")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("aBc").EqualFold("aB")
assertFailed(t, msg, "the string values are not equal under Unicode case folding")
})
})
t.Run("NotEqualFold", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("aBc").NotEqualFold("aB")
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("aBc").NotEqualFold("ABC")
assertFailed(t, msg, "the string values are equal under Unicode case folding")
})
})
t.Run("MatchRegex", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("3aD").MatchRegex(regexp.MustCompile("[0-9][a-z][A-Z]"))
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("123").MatchRegex(regexp.MustCompile("[0-9][a-z][A-Z]"))
assertFailed(t, msg, "the string value does not match the regular expression")
})
})
t.Run("NotMatchRegex", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
msg := verify.String("123").NotMatchRegex(regexp.MustCompile("[0-9][a-z][A-Z]"))
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
msg := verify.String("3aD").NotMatchRegex(regexp.MustCompile("[0-9][a-z][A-Z]"))
assertFailed(t, msg, "the string value matches the regular expression")
})
})
t.Run("Len", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
got := verify.String("abc").Len(3)
assertPassed(t, got)
})
t.Run("Failed", func(t *testing.T) {
got := verify.String("abc").Len(10)
assertFailed(t, got, "has different length")
})
})
t.Run("has assertions from Ordered, Obj, Any", func(t *testing.T) {
want := "text"
got := verify.String(want).FluentOrdered.FluentObj.FluentAny.Got // type embedding done properly
assertEqual(t, got, want)
})
}