mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Make isEmpty() properly handles maps. [fix #34]
This commit is contained in:
parent
18d938d6c5
commit
f51780437f
@ -227,6 +227,8 @@ func isEmpty(object interface{}) bool {
|
||||
|
||||
objValue := reflect.ValueOf(object)
|
||||
switch objValue.Kind() {
|
||||
case reflect.Map:
|
||||
fallthrough
|
||||
case reflect.Slice:
|
||||
{
|
||||
return (objValue.Len() == 0)
|
||||
|
@ -318,12 +318,14 @@ func Test_isEmpty(t *testing.T) {
|
||||
True(t, isEmpty([]string{}))
|
||||
True(t, isEmpty(0))
|
||||
True(t, isEmpty(false))
|
||||
True(t, isEmpty(map[string]string{}))
|
||||
|
||||
False(t, isEmpty("something"))
|
||||
False(t, isEmpty(errors.New("something")))
|
||||
False(t, isEmpty([]string{"something"}))
|
||||
False(t, isEmpty(1))
|
||||
False(t, isEmpty(true))
|
||||
False(t, isEmpty(map[string]string{"Hello": "World"}))
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user