Skip to content

Commit e697750

Browse files
committed
add test for As and Is function checking with standard library
1 parent d8ab995 commit e697750

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

errors_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package errors
22

33
import (
44
"errors"
5+
stdlib_errors "errors"
56
"fmt"
67
"io"
78
"reflect"
@@ -249,3 +250,25 @@ func TestErrorEquality(t *testing.T) {
249250
}
250251
}
251252
}
253+
254+
func TestIs(t *testing.T) {
255+
sentinelError := stdlib_errors.New("sentinel error")
256+
wrap := Wrap(sentinelError, "wrap error")
257+
if !Is(wrap, sentinelError) {
258+
t.Errorf("Expected that '%v' error and the '%v' error should be of the same type", sentinelError, wrap)
259+
}
260+
}
261+
262+
func TestAs(t *testing.T) {
263+
type myError struct {
264+
error
265+
}
266+
err := &myError{stdlib_errors.New("error")}
267+
wrap := Wrap(err, "wrap error")
268+
269+
var tt *myError
270+
if !As(wrap, &tt) {
271+
t.Errorf("Expected that '%v' error and the '%v' error should be of the same type", err, wrap)
272+
}
273+
274+
}

0 commit comments

Comments
 (0)