Make isEmpty() properly handles maps. [fix #34]

This commit is contained in:
Chakrit Wichian 2014-01-19 10:30:16 +07:00
parent 18d938d6c5
commit f51780437f
2 changed files with 4 additions and 0 deletions

View File

@ -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)

View File

@ -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"}))
}