MCPcopy Create free account
hub / github.com/stretchr/testify / diff

Function diff

assert/assertions.go:1855–1896  ·  view source on GitHub ↗

diff returns a diff of both values as long as both are of the same type and are a struct, map, slice, array or string. Otherwise it returns an empty string.

(expected interface{}, actual interface{})

Source from the content-addressed store, hash-verified

1853// diff returns a diff of both values as long as both are of the same type and
1854// are a struct, map, slice, array or string. Otherwise it returns an empty string.
1855func diff(expected interface{}, actual interface{}) string {
1856 if expected == nil || actual == nil {
1857 return ""
1858 }
1859
1860 et, ek := typeAndKind(expected)
1861 at, _ := typeAndKind(actual)
1862
1863 if et != at {
1864 return ""
1865 }
1866
1867 if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String {
1868 return ""
1869 }
1870
1871 var e, a string
1872
1873 switch et {
1874 case reflect.TypeOf(""):
1875 e = reflect.ValueOf(expected).String()
1876 a = reflect.ValueOf(actual).String()
1877 case reflect.TypeOf(time.Time{}):
1878 e = spewConfigStringerEnabled.Sdump(expected)
1879 a = spewConfigStringerEnabled.Sdump(actual)
1880 default:
1881 e = spewConfig.Sdump(expected)
1882 a = spewConfig.Sdump(actual)
1883 }
1884
1885 diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
1886 A: difflib.SplitLines(e),
1887 B: difflib.SplitLines(a),
1888 FromFile: "Expected",
1889 FromDate: "",
1890 ToFile: "Actual",
1891 ToDate: "",
1892 Context: 1,
1893 })
1894
1895 return "\n\nDiff:\n" + diff
1896}
1897
1898func isFunction(arg interface{}) bool {
1899 if arg == nil {

Callers 7

TestInDeltaMapValuesFunction · 0.70
TestDiffFunction · 0.70
TestDiffEmptyCasesFunction · 0.70
TestDiffRaceFunction · 0.70
EqualFunction · 0.70
EqualValuesFunction · 0.70
EqualExportedValuesFunction · 0.70

Calls 2

typeAndKindFunction · 0.70
StringMethod · 0.45

Tested by 4

TestInDeltaMapValuesFunction · 0.56
TestDiffFunction · 0.56
TestDiffEmptyCasesFunction · 0.56
TestDiffRaceFunction · 0.56