formatUnequalValues takes two values of arbitrary types and returns string representations appropriate to be presented to the user. If the values are not of like type, the returned strings will be prefixed with the type name, and the value will be enclosed in parentheses similar to a type conversio
(expected, actual interface{})
| 603 | // with the type name, and the value will be enclosed in parentheses similar |
| 604 | // to a type conversion in the Go grammar. |
| 605 | func formatUnequalValues(expected, actual interface{}) (e string, a string) { |
| 606 | if reflect.TypeOf(expected) != reflect.TypeOf(actual) { |
| 607 | return fmt.Sprintf("%T(%s)", expected, truncatingFormat(expected)), |
| 608 | fmt.Sprintf("%T(%s)", actual, truncatingFormat(actual)) |
| 609 | } |
| 610 | switch expected.(type) { |
| 611 | case time.Duration: |
| 612 | return fmt.Sprintf("%v", expected), fmt.Sprintf("%v", actual) |
| 613 | } |
| 614 | return truncatingFormat(expected), truncatingFormat(actual) |
| 615 | } |
| 616 | |
| 617 | // truncatingFormat formats the data and truncates it if it's too long. |
| 618 | // |