github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/unsafe/reflectx/reflect_test.go (about) 1 package reflectx 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 type dummyError struct{} 10 11 func (_ *dummyError) Error() string { return "dummyError" } 12 13 func TestIsNil(t *testing.T) { 14 testcases := []struct { 15 v any 16 want bool 17 }{ 18 {nil, true}, 19 {(map[string]int)(nil), true}, 20 {([]string)(nil), true}, 21 {(*int)(nil), true}, 22 {(*simple)(nil), true}, 23 {error((*dummyError)(nil)), true}, 24 {map[string]int{}, false}, 25 {[]string{}, false}, 26 {1, false}, 27 {"abc", false}, 28 {simple{}, false}, 29 {&simple{}, false}, 30 } 31 for i, tc := range testcases { 32 got := IsNil(tc.v) 33 assert.Equalf(t, tc.want, got, "i= %v, v = %q", i, tc.v) 34 } 35 }