@@ -47,32 +47,32 @@ func testDeepEqualAndNotDeepEqual(t *testing.T, assertion *Assertion, v1, v2 any
4747func testDeepEqual (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
4848 err := assertion .DeepEqual (v1 , v2 )
4949 if isEqual && err != nil {
50- t .Errorf ("Equal (%v, %v) = %v, want = nil" , v1 , v2 , err )
50+ t .Errorf ("DeepEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
5151 } else if ! isEqual && err == nil {
52- t .Errorf ("Equal (%v, %v) = nil, want = error" , v1 , v2 )
52+ t .Errorf ("DeepEqual (%v, %v) = nil, want = error" , v1 , v2 )
5353 }
5454
5555 err = DeepEqual (assertion .T , v1 , v2 )
5656 if isEqual && err != nil {
57- t .Errorf ("Equal (%v, %v) = %v, want = nil" , v1 , v2 , err )
57+ t .Errorf ("DeepEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
5858 } else if ! isEqual && err == nil {
59- t .Errorf ("Equal (%v, %v) = nil, want = error" , v1 , v2 )
59+ t .Errorf ("DeepEqual (%v, %v) = nil, want = error" , v1 , v2 )
6060 }
6161}
6262
6363func testNotDeepEqual (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
6464 err := assertion .NotDeepEqual (v1 , v2 )
6565 if isEqual && err == nil {
66- t .Errorf ("NotEqual (%v, %v) = nil, want = error" , v1 , v2 )
66+ t .Errorf ("NotDeepEqual (%v, %v) = nil, want = error" , v1 , v2 )
6767 } else if ! isEqual && err != nil {
68- t .Errorf ("NotEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
68+ t .Errorf ("NotDeepEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
6969 }
7070
7171 err = NotDeepEqual (assertion .T , v1 , v2 )
7272 if isEqual && err == nil {
73- t .Errorf ("NotEqual (%v, %v) = nil, want = error" , v1 , v2 )
73+ t .Errorf ("NotDeepEqual (%v, %v) = nil, want = error" , v1 , v2 )
7474 } else if ! isEqual && err != nil {
75- t .Errorf ("NotEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
75+ t .Errorf ("NotDeepEqual (%v, %v) = %v, want = nil" , v1 , v2 , err )
7676 }
7777}
7878
@@ -116,6 +116,112 @@ func testNotDeepEqualNow(t *testing.T, assertion *Assertion, v1, v2 any, isEqual
116116 }
117117}
118118
119+ func TestEqualAndNotEqual (t * testing.T ) {
120+ mockT := new (testing.T )
121+ assertion := New (mockT )
122+
123+ testEqualAndNotEqual (t , assertion , 1 , 1 , true )
124+ testEqualAndNotEqual (t , assertion , 1 , 2 , false )
125+ testEqualAndNotEqual (t , assertion , 1 , int64 (1 ), true )
126+ testEqualAndNotEqual (t , assertion , 1 , 1.0 , false )
127+ testEqualAndNotEqual (t , assertion , 1 , "1" , false )
128+ testEqualAndNotEqual (t , assertion , 1 , '1' , false )
129+ testEqualAndNotEqual (t , assertion , 1 , []int {1 }, false )
130+ testEqualAndNotEqual (t , assertion , []int {1 }, []int {1 }, true )
131+
132+ obj1 := testStruct {v : 1 }
133+ obj2 := testStruct {v : 1 }
134+
135+ testEqualAndNotEqual (t , assertion , obj1 , obj2 , true )
136+ testEqualAndNotEqual (t , assertion , obj1 , & obj2 , false )
137+ testEqualAndNotEqual (t , assertion , & obj1 , & obj2 , false )
138+
139+ obj2 .v = 2
140+ testEqualAndNotEqual (t , assertion , obj1 , obj2 , false )
141+ }
142+
143+ func testEqualAndNotEqual (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
144+ testEqual (t , assertion , v1 , v2 , isEqual )
145+
146+ testNotEqual (t , assertion , v1 , v2 , isEqual )
147+
148+ testEqualNow (t , assertion , v1 , v2 , isEqual )
149+
150+ testNotEqualNow (t , assertion , v1 , v2 , isEqual )
151+ }
152+
153+ func testEqual (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
154+ err := assertion .Equal (v1 , v2 )
155+ if isEqual && err != nil {
156+ t .Errorf ("Equal(%v, %v) = %v, want = nil" , v1 , v2 , err )
157+ } else if ! isEqual && err == nil {
158+ t .Errorf ("Equal(%v, %v) = nil, want = error" , v1 , v2 )
159+ }
160+
161+ err = Equal (assertion .T , v1 , v2 )
162+ if isEqual && err != nil {
163+ t .Errorf ("Equal(%v, %v) = %v, want = nil" , v1 , v2 , err )
164+ } else if ! isEqual && err == nil {
165+ t .Errorf ("Equal(%v, %v) = nil, want = error" , v1 , v2 )
166+ }
167+ }
168+
169+ func testNotEqual (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
170+ err := assertion .NotEqual (v1 , v2 )
171+ if isEqual && err == nil {
172+ t .Errorf ("NotEqual(%v, %v) = nil, want = error" , v1 , v2 )
173+ } else if ! isEqual && err != nil {
174+ t .Errorf ("NotEqual(%v, %v) = %v, want = nil" , v1 , v2 , err )
175+ }
176+
177+ err = NotEqual (assertion .T , v1 , v2 )
178+ if isEqual && err == nil {
179+ t .Errorf ("NotEqual(%v, %v) = nil, want = error" , v1 , v2 )
180+ } else if ! isEqual && err != nil {
181+ t .Errorf ("NotEqual(%v, %v) = %v, want = nil" , v1 , v2 , err )
182+ }
183+ }
184+
185+ func testEqualNow (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
186+ isTerminated := internal .CheckTermination (func () {
187+ assertion .EqualNow (v1 , v2 )
188+ })
189+ if isEqual && isTerminated {
190+ t .Error ("execution stopped, want do not stop" )
191+ } else if ! isEqual && ! isTerminated {
192+ t .Error ("execution do not stopped, want stop" )
193+ }
194+
195+ isTerminated = internal .CheckTermination (func () {
196+ EqualNow (assertion .T , v1 , v2 )
197+ })
198+ if isEqual && isTerminated {
199+ t .Error ("execution stopped, want do not stop" )
200+ } else if ! isEqual && ! isTerminated {
201+ t .Error ("execution do not stopped, want stop" )
202+ }
203+ }
204+
205+ func testNotEqualNow (t * testing.T , assertion * Assertion , v1 , v2 any , isEqual bool ) {
206+ isTerminated := internal .CheckTermination (func () {
207+ assertion .NotEqualNow (v1 , v2 )
208+ })
209+ if ! isEqual && isTerminated {
210+ t .Error ("execution stopped, want do not stop" )
211+ } else if isEqual && ! isTerminated {
212+ t .Error ("execution do not stopped, want stop" )
213+ }
214+
215+ isTerminated = internal .CheckTermination (func () {
216+ NotEqualNow (assertion .T , v1 , v2 )
217+ })
218+ if ! isEqual && isTerminated {
219+ t .Error ("execution stopped, want do not stop" )
220+ } else if isEqual && ! isTerminated {
221+ t .Error ("execution do not stopped, want stop" )
222+ }
223+ }
224+
119225func TestNilAndNotNil (t * testing.T ) {
120226 mockT := new (testing.T )
121227 assert := New (mockT )
0 commit comments