mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Merge pull request #367 from packrat386/rm_numeric_check
Remove isNumericType check
This commit is contained in:
commit
ae4c58e530
@ -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
|
// with the type name, and the value will be enclosed in parenthesis similar
|
||||||
// to a type conversion in the Go grammar.
|
// to a type conversion in the Go grammar.
|
||||||
func formatUnequalValues(expected, actual interface{}) (e string, a string) {
|
func formatUnequalValues(expected, actual interface{}) (e string, a string) {
|
||||||
aType := reflect.TypeOf(expected)
|
if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
|
||||||
bType := reflect.TypeOf(actual)
|
return fmt.Sprintf("%T(%#v)", expected, expected),
|
||||||
|
fmt.Sprintf("%T(%#v)", actual, actual)
|
||||||
if aType != bType && isNumericType(aType) && isNumericType(bType) {
|
|
||||||
return fmt.Sprintf("%v(%#v)", aType, expected),
|
|
||||||
fmt.Sprintf("%v(%#v)", bType, actual)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%#v", expected),
|
return fmt.Sprintf("%#v", expected),
|
||||||
fmt.Sprintf("%#v", actual)
|
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
|
// EqualValues asserts that two objects are equal or convertable to the same types
|
||||||
// and equal.
|
// and equal.
|
||||||
//
|
//
|
||||||
|
@ -210,6 +210,10 @@ func TestFormatUnequalValues(t *testing.T) {
|
|||||||
Equal(t, `int64(123)`, expected, "value should include type")
|
Equal(t, `int64(123)`, expected, "value should include type")
|
||||||
Equal(t, `int32(123)`, actual, "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 {
|
type testStructType struct {
|
||||||
Val string
|
Val string
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user