package assert import "reflect" // Nil asserts that the given value equals nil func Nil(t test, value any) { if isNil(value) { return } t.Errorf(formatSingleValueMessage("Nil", value)) t.FailNow() } // NotNil asserts that the given value does not equal nil func NotNil(t test, value any) { if !isNil(value) { return } t.Errorf(formatSingleValueMessage("NotNil", value)) t.FailNow() } // isNil returns true if the object is nil. func isNil(object any) bool { if object == nil { return true } value := reflect.ValueOf(object) kind := value.Kind() switch kind { case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: return value.IsNil() } return false }