-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoequalassert_test.go
More file actions
195 lines (191 loc) · 3.74 KB
/
toequalassert_test.go
File metadata and controls
195 lines (191 loc) · 3.74 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package texp_test
import (
"testing"
"github.com/gekorob/texp"
"github.com/gekorob/texp/mock"
)
var eqTests = []struct {
N string
T func(texp.ExpBuilder)
A func(*mock.TMock) bool
}{
{
N: "Equal ints",
T: func(expect texp.ExpBuilder) {
expect(1).ToEqual(1)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal ints",
T: func(expect texp.ExpBuilder) {
expect(10).ToEqual(1)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal strings",
T: func(expect texp.ExpBuilder) {
expect("alpha").ToEqual("alpha")
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal strings",
T: func(expect texp.ExpBuilder) {
expect("beta").ToEqual("alpha")
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal booleans",
T: func(expect texp.ExpBuilder) {
expect(true).ToEqual(true)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal booleans",
T: func(expect texp.ExpBuilder) {
expect(false).ToEqual(true)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal to nil",
T: func(expect texp.ExpBuilder) {
expect("first").ToEqual(nil)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Not Equal uint32 and uint64",
T: func(expect texp.ExpBuilder) {
expect(uint32(3)).ToEqual(uint64(3))
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal uint",
T: func(expect texp.ExpBuilder) {
expect(uint(3)).ToEqual(uint(3))
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Equal slicesi, same order",
T: func(expect texp.ExpBuilder) {
s1 := []string{"first", "second", "third"}
s2 := []string{"first", "second", "third"}
expect(s1).ToEqual(s2)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal slices, same elements different order",
T: func(expect texp.ExpBuilder) {
s1 := []string{"first", "second", "third"}
s2 := []string{"second", "first", "third"}
expect(s1).ToEqual(s2)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Not Equal maps",
T: func(expect texp.ExpBuilder) {
m1 := map[string]interface{}{"element": 5}
m2 := map[string]interface{}{"element": 20}
expect(m1).ToEqual(m2)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal nil and nil",
T: func(expect texp.ExpBuilder) {
expect(nil).ToEqual(nil)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal nil map",
T: func(expect texp.ExpBuilder) {
var m1 map[string]int
m2 := map[string]int{}
expect(m1).ToEqual(m2)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
{
N: "Equal nil map",
T: func(expect texp.ExpBuilder) {
var m1 map[string]int
var m2 map[string]int
expect(m1).ToEqual(m2)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Equal nil slice",
T: func(expect texp.ExpBuilder) {
var s1 []string
var s2 []string
expect(s1).ToEqual(s2)
},
A: func(tM *mock.TMock) bool {
return !testFailInvoked(tM)
},
},
{
N: "Not Equal chan",
T: func(expect texp.ExpBuilder) {
var c1 chan string
c2 := make(chan string)
expect(c1).ToEqual(c2)
},
A: func(tM *mock.TMock) bool {
return testFailInvoked(tM)
},
},
}
func TestEqual(t *testing.T) {
for _, tt := range eqTests {
t.Run(tt.N, func(t *testing.T) {
tMock := mock.NewTMock()
expect := texp.Expect(tMock)
tt.T(expect)
if !tt.A(tMock) {
t.Error("Wrong calls to Fail")
}
})
}
}