From f51780437f56647307a283d083c6143067e31ae7 Mon Sep 17 00:00:00 2001 From: Chakrit Wichian Date: Sun, 19 Jan 2014 10:30:16 +0700 Subject: [PATCH] Make isEmpty() properly handles maps. [fix #34] --- assert/assertions.go | 2 ++ assert/assertions_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/assert/assertions.go b/assert/assertions.go index cc027cb..660dc97 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 4dda014..648d76e 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -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"})) }