show type differences in reflect diff

This commit is contained in:
Jordan Liggitt 2018-06-26 11:30:30 -04:00
parent 67e7d4c68f
commit 6354665ee8
No known key found for this signature in database
GPG Key ID: 39928704103C7229
2 changed files with 13 additions and 0 deletions

View File

@ -108,6 +108,14 @@ func limit(aObj, bObj interface{}, max int) (string, string) {
elidedASuffix := ""
elidedBSuffix := ""
a, b := fmt.Sprintf("%#v", aObj), fmt.Sprintf("%#v", bObj)
if aObj != nil && bObj != nil {
if aType, bType := fmt.Sprintf("%T", aObj), fmt.Sprintf("%T", bObj); aType != bType {
a = fmt.Sprintf("%s (%s)", a, aType)
b = fmt.Sprintf("%s (%s)", b, bType)
}
}
for {
switch {
case len(a) > max && len(a) > 4 && len(b) > 4 && a[:4] == b[:4]:

View File

@ -75,6 +75,11 @@ object.A:
a: []int(nil)
b: []int{}`,
},
"display type differences": {a: []interface{}{int64(1)}, b: []interface{}{uint64(1)}, out: `
object[0]:
a: 1 (int64)
b: 0x1 (uint64)`,
},
}
for name, test := range testCases {
expect := test.out