@@ -26,6 +26,20 @@ func failed(t *testing.T, err error, failedNow bool) {
2626// ## Assertion Helper Functions ##
2727// ################################
2828
29+ // isComparable gets the type of the value, and checks whether the type is comparable or not.
30+ func isComparable (v any ) bool {
31+ switch v .(type ) {
32+ case
33+ int , int8 , int16 , int32 , int64 , // Signed integer
34+ uint , uint8 , uint16 , uint32 , uint64 , uintptr , // Unsigned integer
35+ float32 , float64 , // Floating-point number
36+ string : // string
37+ return true
38+ default :
39+ return false
40+ }
41+ }
42+
2943// isEqual checks the equality of the values.
3044func isEqual (x , y any ) bool {
3145 if x == nil || y == nil {
@@ -54,20 +68,38 @@ func isEqual(x, y any) bool {
5468 }
5569}
5670
57- // isComparable gets the type of the value, and checks whether the type is comparable or not.
58- func isComparable (v any ) bool {
59- switch v .(type ) {
60- case
61- int , int8 , int16 , int32 , int64 , // Signed integer
62- uint , uint8 , uint16 , uint32 , uint64 , uintptr , // Unsigned integer
63- float32 , float64 , // Floating-point number
64- string : // string
71+ // isNil checks whether a value is nil or not. It'll always return false if the value is not a
72+ // channel, a function, a map, a point, an unsafe point, an interface, or a slice.
73+ func isNil (val any ) bool {
74+ if val == nil {
6575 return true
76+ }
77+
78+ v := reflect .ValueOf (val )
79+
80+ switch v .Kind () {
81+ case reflect .Chan , reflect .Func , reflect .Map , reflect .Pointer , reflect .UnsafePointer ,
82+ reflect .Interface , reflect .Slice :
83+ return v .IsNil ()
6684 default :
6785 return false
6886 }
6987}
7088
89+ // isPanic executes the function, and tries to catching and returns the return value from
90+ // recover().
91+ func isPanic (fn func ()) (err any ) {
92+ defer func () {
93+ if e := recover (); e != nil {
94+ err = e
95+ }
96+ }()
97+
98+ fn ()
99+
100+ return
101+ }
102+
71103// isSameType indicates the equality of two types, and it will ignore the bit size of the same
72104// type. For example, `int32` and `int64` will be the same type.
73105func isSameType (t1 , t2 reflect.Type ) bool {
@@ -103,38 +135,6 @@ func isSliceEqual(v1, v2 reflect.Value) bool {
103135 return true
104136}
105137
106- // isNil checks whether a value is nil or not. It'll always return false if the value is not a
107- // channel, a function, a map, a point, an unsafe point, an interface, or a slice.
108- func isNil (val any ) bool {
109- if val == nil {
110- return true
111- }
112-
113- v := reflect .ValueOf (val )
114-
115- switch v .Kind () {
116- case reflect .Chan , reflect .Func , reflect .Map , reflect .Pointer , reflect .UnsafePointer ,
117- reflect .Interface , reflect .Slice :
118- return v .IsNil ()
119- default :
120- return false
121- }
122- }
123-
124- // isPanic executes the function, and tries to catching and returns the return value from
125- // recover().
126- func isPanic (fn func ()) (err any ) {
127- defer func () {
128- if e := recover (); e != nil {
129- err = e
130- }
131- }()
132-
133- fn ()
134-
135- return
136- }
137-
138138// isTrue checks whether a value is truthy or not. It'll return true if the value is not the zero
139139// value for its type. For a slice, a truthy value should not be the zero value and the length must
140140// be greater than 0. For nil, it'll always return false.
0 commit comments