Merge pull request #367 from packrat386/rm_numeric_check

Remove isNumericType check
pull/384/head
Ernesto Jiménez 2016-12-17 13:26:48 -06:00 committed by GitHub
commit ae4c58e530
2 changed files with 7 additions and 19 deletions

View File

@ -294,31 +294,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.
//

View File

@ -210,6 +210,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
}