11package assert
22
33import (
4- "github.com/gravitton/assert/internal "
4+ "errors "
55)
66
77// Testing is an interface wrapper around *testing.T
@@ -16,7 +16,7 @@ type Testing interface {
1616func True (t Testing , condition bool ) bool {
1717 t .Helper ()
1818
19- if ! internal . Assert ( condition ) {
19+ if ! condition {
2020 return Fail (t , "Should be true" )
2121 }
2222
@@ -29,7 +29,7 @@ func True(t Testing, condition bool) bool {
2929func False (t Testing , condition bool ) bool {
3030 t .Helper ()
3131
32- if internal . Assert ( condition ) {
32+ if condition {
3333 return Fail (t , "Should be false" )
3434 }
3535
@@ -45,7 +45,7 @@ func False(t Testing, condition bool) bool {
4545func Equal (t Testing , actual , expected any ) bool {
4646 t .Helper ()
4747
48- if ! internal . Equal (actual , expected ) {
48+ if ! equal (actual , expected ) {
4949 return Failf (t , "Should be equal:\n actual: %#v\n expected: %#v" , actual , expected )
5050 }
5151
@@ -61,7 +61,7 @@ func Equal(t Testing, actual, expected any) bool {
6161func NotEqual (t Testing , actual , expected any ) bool {
6262 t .Helper ()
6363
64- if internal . Equal (actual , expected ) {
64+ if equal (actual , expected ) {
6565 return Failf (t , "Should not be equal\n actual: %#v" , actual )
6666 }
6767
@@ -72,12 +72,12 @@ func NotEqual(t Testing, actual, expected any) bool {
7272//
7373// assert.Same(t, actual, expected)
7474//
75- // Both arguments must be pointer variables. Pointer variable sameness is
75+ // Both arguments must be pointer variables. Pointer variable equality is
7676// determined based on the equality of both type and value.
7777func Same (t Testing , actual , expected any ) bool {
7878 t .Helper ()
7979
80- if ! internal . Same (expected , actual ) {
80+ if ! same (expected , actual ) {
8181 return Failf (t , "Should be same\n actual: %[1]p %#[1]v\n expected: %[2]p %#[2]v" , actual , expected )
8282 }
8383
@@ -88,32 +88,40 @@ func Same(t Testing, actual, expected any) bool {
8888//
8989// assert.NotSame(t, actual, expected)
9090//
91- // Both arguments must be pointer variables. Pointer variable sameness is
91+ // Both arguments must be pointer variables. Pointer variable equality is
9292// determined based on the equality of both type and value.
9393func NotSame (t Testing , actual , expected any ) bool {
9494 t .Helper ()
9595
96- if internal . Same (expected , actual ) {
96+ if same (expected , actual ) {
9797 return Failf (t , "Should not be same\n actual: %[1]p %#[1]v" , actual )
9898 }
9999
100100 return true
101101}
102102
103+ // Length asserts that object have given length.
104+ //
105+ // assert.Length(t, object, expected)
103106func Length (t Testing , object any , expected int ) bool {
104107 t .Helper ()
105108
106- if actual := internal . Length (object ); actual != expected {
109+ if actual := length (object ); actual != expected {
107110 return Failf (t , "Should have element length\n object: %#v\n actual: %d\n expected: %d" , object , actual , expected )
108111 }
109112
110113 return true
111114}
112115
116+ // Contains asserts that object contains given element
117+ //
118+ // assert.Contains(t, object, element)
119+ //
120+ // Works with strings, arrays, slices, maps values and channels
113121func Contains (t Testing , object , element any ) bool {
114122 t .Helper ()
115123
116- if found , ok := internal . Contains (object , element ); ! ok {
124+ if found , ok := contains (object , element ); ! ok {
117125 return Failf (t , "Should be iterable\n object: %#v" , object )
118126 } else if ! found {
119127 return Failf (t , "Should contain element\n object: %#v\n element: %#v" , object , element )
@@ -122,10 +130,15 @@ func Contains(t Testing, object, element any) bool {
122130 return true
123131}
124132
133+ // NotContains asserts that object do NOT contains given element
134+ //
135+ // assert.NotContains(t, object, element)
136+ //
137+ // Works with strings, arrays, slices, maps values and channels
125138func NotContains (t Testing , object any , element any ) bool {
126139 t .Helper ()
127140
128- if found , ok := internal . Contains (object , element ); ! ok {
141+ if found , ok := contains (object , element ); ! ok {
129142 return Failf (t , "Should be iterable\n object: %#v" , object )
130143 } else if found {
131144 return Failf (t , "Should not contain element\n object: %#v\n element: %#v" , object , element )
@@ -134,47 +147,59 @@ func NotContains(t Testing, object any, element any) bool {
134147 return true
135148}
136149
150+ // Error asserts that error is NOT nil
151+ //
152+ // assert.Error(t, err)
137153func Error (t Testing , err error ) bool {
138154 t .Helper ()
139155
140- if ! internal . Error ( err ) {
156+ if err == nil {
141157 return Failf (t , "Should be error" )
142158 }
143159
144160 return true
145161}
146162
163+ // NoError asserts that error is nil
164+ //
165+ // assert.NoError(t, err)
147166func NoError (t Testing , err error ) bool {
148167 t .Helper ()
149168
150- if internal . Error ( err ) {
169+ if err != nil {
151170 return Failf (t , "Should not be error\n error: %#v" , err )
152171 }
153172
154173 return true
155174}
156175
176+ // ErrorIs asserts that error is unwrappable to given target
177+ //
178+ // assert.ErrorIs(t, err)
157179func ErrorIs (t Testing , err error , target error ) bool {
158180 t .Helper ()
159181
160- if ! internal . ErrorIs (err , target ) {
182+ if ! errors . Is (err , target ) {
161183 return Failf (t , "Should be same error\n error: %#v\n target: %#v" , err , target )
162184 }
163185
164186 return true
165187}
166188
189+ // NotErrorIs asserts that error is NOT unwrappable to given target
190+ //
191+ // assert.NotErrorIs(t, err)
167192func NotErrorIs (t Testing , err error , target error ) bool {
168193 t .Helper ()
169194
170- if internal . ErrorIs (err , target ) {
195+ if errors . Is (err , target ) {
171196 return Failf (t , "Should not be same error\n error: %#v" , err , target )
172197 }
173198
174199 return true
175200}
176201
177- // Fail reports a failure through
202+ // Fail reports a failure message through
178203func Fail (t Testing , message string ) bool {
179204 t .Helper ()
180205
@@ -183,7 +208,7 @@ func Fail(t Testing, message string) bool {
183208 return false
184209}
185210
186- // Failf reports a failure through
211+ // Failf reports a failure formatted message through
187212func Failf (t Testing , format string , args ... any ) bool {
188213 t .Helper ()
189214
0 commit comments