@@ -7,57 +7,75 @@ import (
77)
88
99// DeepEqual tests deeply equality between actual and expect parameters.
10- func DeepEqual (t * testing.T , actual , expect any , message ... string ) error {
10+ func (a * Assertion ) DeepEqual (actual , expect any , message ... string ) error {
11+ return tryDeepEqual (a .t , false , actual , expect , message ... )
12+ }
13+
14+ // NotDeepEqual tests deeply inequality between actual and expected parameters.
15+ func (a * Assertion ) NotDeepEqual (actual , expect any , message ... string ) error {
16+ return tryNotDeepEqual (a .t , false , actual , expect , message ... )
17+ }
18+
19+ // tryDeepEqual try to testing the deeply equality between actual and expect values, and it'll
20+ // fail if the values are not deeply equal.
21+ func tryDeepEqual (t * testing.T , failedNow bool , actual , expect any , message ... string ) error {
1122 if reflect .DeepEqual (actual , expect ) {
1223 return nil
1324 }
1425
1526 err := newAssertionError (fmt .Sprintf ("%v == %v" , actual , expect ), message ... )
16-
17- t .Error (err )
27+ failed (t , err , failedNow )
1828
1929 return err
2030}
2131
22- // NotDeepEqual tests deeply inequality between actual and expected parameters.
23- func NotDeepEqual (t * testing.T , actual , expect any , message ... string ) error {
32+ // tryNotDeepEqual try to testing the deeply inequality between actual and expect values, and it'll
33+ // fail if the values are deeply equal.
34+ func tryNotDeepEqual (t * testing.T , failedNow bool , actual , expect any , message ... string ) error {
2435 if ! reflect .DeepEqual (actual , expect ) {
2536 return nil
2637 }
2738
2839 err := newAssertionError (fmt .Sprintf ("%v != %v" , actual , expect ), message ... )
29-
30- t .Error (err )
40+ failed (t , err , failedNow )
3141
3242 return err
3343}
3444
3545// Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will
3646// always return false if the value is a bool, an integer, a floating number, a complex, or a
3747// string.
38- func Nil (t * testing.T , val any , message ... string ) error {
48+ func (a * Assertion ) Nil (val any , message ... string ) error {
49+ return tryNil (a .t , false , val , message ... )
50+ }
51+
52+ // NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will
53+ // always return true if the value is a bool, an integer, a floating number, a complex, or a
54+ // string.
55+ func (a * Assertion ) NotNil (val any , message ... string ) error {
56+ return tryNotNil (a .t , false , val , message ... )
57+ }
58+
59+ // tryNil try to testing a value is nil or not, and it'll fail the value is nil.
60+ func tryNil (t * testing.T , failedNow bool , val any , message ... string ) error {
3961 if isNil (val ) {
4062 return nil
4163 }
4264
4365 err := newAssertionError (fmt .Sprintf ("expect nil, got %v" , val ), message ... )
44-
45- t .Error (err )
66+ failed (t , err , failedNow )
4667
4768 return err
4869}
4970
50- // NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will
51- // always return true if the value is a bool, an integer, a floating number, a complex, or a
52- // string.
53- func NotNil (t * testing.T , val any , message ... string ) error {
71+ // tryNotNil try to testing a value is nil or not, and it'll fail the value is not nil.
72+ func tryNotNil (t * testing.T , failedNow bool , val any , message ... string ) error {
5473 if ! isNil (val ) {
5574 return nil
5675 }
5776
5877 err := newAssertionError ("expect not nil, got nil" , message ... )
59-
60- t .Error (err )
78+ failed (t , err , failedNow )
6179
6280 return err
6381}
0 commit comments