feature (is_nil): support checking func for nil (#3142)
This commit is contained in:
2 files changed
+4
-1
No files matched your search
@@ -11,7 +11,7 @@ func IsNil(i any) bool {
|
||||
return true
|
||||
}
|
||||
switch reflect.TypeOf(i).Kind() {
|
||||
case reflect.Ptr, reflect.Map, reflect.Chan, reflect.Slice:
|
||||
case reflect.Ptr, reflect.Map, reflect.Chan, reflect.Slice, reflect.Func:
|
||||
return reflect.ValueOf(i).IsNil()
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -19,6 +19,7 @@ func Test_IsNil(t *testing.T) {
|
||||
var testArrayNilPtr *[1]string
|
||||
var testChanNilPtr *chan string
|
||||
var testSliceNilPtr *[]string
|
||||
var testFuncNil func()
|
||||
|
||||
var testChanString chan string
|
||||
|
||||
@@ -35,6 +36,7 @@ func Test_IsNil(t *testing.T) {
|
||||
{i: &testChanString, want: false},
|
||||
{i: "string", want: false},
|
||||
{i: []string{}, want: false},
|
||||
{i: func() {}, want: false},
|
||||
{i: nil, want: true},
|
||||
{i: testErrNilPtr, want: true},
|
||||
{i: testMapNilPtr, want: true},
|
||||
@@ -42,6 +44,7 @@ func Test_IsNil(t *testing.T) {
|
||||
{i: testChanNilPtr, want: true},
|
||||
{i: testChanString, want: true},
|
||||
{i: testSliceNilPtr, want: true},
|
||||
{i: testFuncNil, want: true},
|
||||
}
|
||||
|
||||
for i, tc := range tc {
|
||||
|
||||
Reference in new issue
Block a user