-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix nil test so that []interface{} when nil works correctly
- use switch for haslength.go
- Loading branch information
mcorbyeaglen
committed
Dec 17, 2020
1 parent
e5a7240
commit 160fd77
Showing
3 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
package is | ||
|
||
import "github.com/corbym/gocrest" | ||
import ( | ||
"fmt" | ||
"github.com/corbym/gocrest" | ||
"reflect" | ||
) | ||
|
||
//Nil matches if the expected value is nil | ||
//Nil matches if the actual value is nil | ||
func Nil() *gocrest.Matcher { | ||
return EqualTo(nil) | ||
match := new(gocrest.Matcher) | ||
match.Describe = "value that is <nil>" | ||
match.Matches = func(actual interface{}) bool { | ||
match.Actual = fmt.Sprintf("%v", actual) | ||
if actual == nil { | ||
return true | ||
} | ||
switch reflect.TypeOf(actual).Kind() { | ||
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice: | ||
return reflect.ValueOf(actual).IsNil() | ||
} | ||
return false // anything else is never nil (hopefully) | ||
} | ||
return match | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters