File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ func New(t *testing.T) *Assertion {
2121 a := new (Assertion )
2222
2323 if t == nil {
24- panic ("parameter t is required" )
24+ panic (ErrRequireT )
2525 }
2626 a .T = t
2727
Original file line number Diff line number Diff line change 11package assert
22
3- import "fmt"
3+ import (
4+ "errors"
5+ "fmt"
6+ )
47
58const (
69 defaultErrMessageEqual string = "%v == %v"
@@ -27,6 +30,19 @@ const (
2730 defaultErrMessageNotMapHasValue string = "expect map has no value %v"
2831)
2932
33+ var (
34+ // ErrNotArray indicates that the value must be a slice or an array.
35+ ErrNotArray error = errors .New ("the value must be a slice or an array" )
36+ // ErrNotMap indicates that the value must be a map.
37+ ErrNotMap error = errors .New ("the value must be a map" )
38+ // ErrNotOrderable indicates that the value must be orderable.
39+ ErrNotOrderable error = errors .New ("the value must be orderable" )
40+ // ErrNotSameType indicates that both values must be the same type.
41+ ErrNotSameType error = errors .New ("the values must be the same type" )
42+ // ErrRequireT indicates that the instance of testing.T is a required parameter.
43+ ErrRequireT error = errors .New ("testing.T is required" )
44+ )
45+
3046// AssertionError indicates the failure of an assertion.
3147type AssertionError struct {
3248 message string
Original file line number Diff line number Diff line change @@ -107,10 +107,10 @@ func isContainsElement(source, elem any) bool {
107107 st = st .Elem ()
108108 }
109109 if st .Kind () != reflect .Array && st .Kind () != reflect .Slice {
110- panic ("require array or slice" )
110+ panic (ErrNotArray )
111111 }
112112 if ok := isSameType (st .Type ().Elem (), reflect .TypeOf (elem )); ! ok {
113- panic ("require same type" )
113+ panic (ErrNotSameType )
114114 }
115115
116116 if st .Len () == 0 {
You can’t perform that action at this time.
0 commit comments