@@ -45,3 +45,31 @@ func testDeepEqualAndNotDeepEqual(t *testing.T, assertion *Assertion, v1, v2 any
4545 t .Errorf ("NotEqual(%v, %v) = %v, want = nil" , v1 , v2 , err )
4646 }
4747}
48+
49+ func TestNilAndNotNil (t * testing.T ) {
50+ mockT := new (testing.T )
51+ assert := New (mockT )
52+
53+ testNilAndNotNil (t , assert , 1 , false )
54+ testNilAndNotNil (t , assert , "" , false )
55+ testNilAndNotNil (t , assert , nil , true )
56+ var testAssert * Assertion
57+ testNilAndNotNil (t , assert , testAssert , true )
58+ testNilAndNotNil (t , assert , assert , false )
59+ }
60+
61+ func testNilAndNotNil (t * testing.T , assertion * Assertion , v any , isNil bool ) {
62+ err := assertion .Nil (v )
63+ if isNil && err != nil {
64+ t .Errorf ("Nil(%v) = %v, want nil" , v , err )
65+ } else if ! isNil && err == nil {
66+ t .Errorf ("Nil(%v) = nil, want error" , v )
67+ }
68+
69+ err = assertion .NotNil (v )
70+ if isNil && err == nil {
71+ t .Errorf ("Nil(%v) = nil, want error" , v )
72+ } else if ! isNil && err != nil {
73+ t .Errorf ("Nil(%v) = %v, want nil" , v , err )
74+ }
75+ }
0 commit comments