diff --git a/builtin/assertion.go b/builtin/assertion.go index ca290aa8..30ecfdd5 100644 --- a/builtin/assertion.go +++ b/builtin/assertion.go @@ -49,5 +49,8 @@ func EndsWith(t assert.TestingT, expected, actual interface{}, msgAndArgs ...int } func EqualLength(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + if !assert.IsType(t, 129, expected, fmt.Sprintf("expected type is not int, got %#v", expected)) { + return false + } return assert.Len(t, actual, expected.(int), msgAndArgs...) } diff --git a/builtin/assertion_test.go b/builtin/assertion_test.go index 328839be..632dad30 100644 --- a/builtin/assertion_test.go +++ b/builtin/assertion_test.go @@ -41,3 +41,23 @@ func TestEndsWith(t *testing.T) { } } } + +func TestEqualLength(t *testing.T) { + testData := []struct { + raw interface{} + expected int + }{ + {"", 0}, + {[]string{}, 0}, + {map[string]interface{}{}, 0}, + {"a", 1}, + {[]string{"a"}, 1}, + {map[string]interface{}{"a": 123}, 1}, + } + + for _, data := range testData { + if !assert.True(t, EqualLength(t, data.expected, data.raw)) { + t.Fail() + } + } +}