Skip to content

Commit

Permalink
fix for comparing kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpantyukhin authored and georgelesica-wf committed Jan 3, 2019
1 parent f1df803 commit 1ecda49
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion assert/assertions.go
Expand Up @@ -419,6 +419,17 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
return Fail(t, "Expected value not to be nil.", msgAndArgs...)
}

// containsKind checks if a specified kind in the slice of kinds.
func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
for i := 0; i < len(kinds); i++ {
if kind == kinds[i] {
return true
}
}

return false
}

// isNil checks if a specified object is nil or not, without Failing.
func isNil(object interface{}) bool {
if object == nil {
Expand All @@ -427,7 +438,14 @@ func isNil(object interface{}) bool {

value := reflect.ValueOf(object)
kind := value.Kind()
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
isNilableKind := containsKind(
[]reflect.Kind{
reflect.Chan, reflect.Func,
reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice},
kind)

if isNilableKind && value.IsNil() {
return true
}

Expand Down

0 comments on commit 1ecda49

Please sign in to comment.