From 6835870125ef09da6f47336ae18429402a42340d Mon Sep 17 00:00:00 2001 From: Aidan Coyle <packrat386@gmail.com> Date: Tue, 15 Nov 2016 14:20:51 -0600 Subject: [PATCH] Remove isNumericType check I'm not sure why this check is needed. It seems worthwhile to print the type any time the types aren't equal. Closes #366. --- assert/assertions.go | 22 +++------------------- assert/assertions_test.go | 4 ++++ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 835084f..0f44046 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -295,31 +295,15 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) // with the type name, and the value will be enclosed in parenthesis similar // to a type conversion in the Go grammar. func formatUnequalValues(expected, actual interface{}) (e string, a string) { - aType := reflect.TypeOf(expected) - bType := reflect.TypeOf(actual) - - if aType != bType && isNumericType(aType) && isNumericType(bType) { - return fmt.Sprintf("%v(%#v)", aType, expected), - fmt.Sprintf("%v(%#v)", bType, actual) + if reflect.TypeOf(expected) != reflect.TypeOf(actual) { + return fmt.Sprintf("%T(%#v)", expected, expected), + fmt.Sprintf("%T(%#v)", actual, actual) } return fmt.Sprintf("%#v", expected), fmt.Sprintf("%#v", actual) } -func isNumericType(t reflect.Type) bool { - switch t.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return true - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return true - case reflect.Float32, reflect.Float64: - return true - } - - return false -} - // EqualValues asserts that two objects are equal or convertable to the same types // and equal. // diff --git a/assert/assertions_test.go b/assert/assertions_test.go index ac9b701..e6cd4d0 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -208,6 +208,10 @@ func TestFormatUnequalValues(t *testing.T) { Equal(t, `int64(123)`, expected, "value should include type") Equal(t, `int32(123)`, actual, "value should include type") + expected, actual = formatUnequalValues(int64(123), nil) + Equal(t, `int64(123)`, expected, "value should include type") + Equal(t, `<nil>(<nil>)`, actual, "value should include type") + type testStructType struct { Val string }