MCPcopy
hub / github.com/stretchr/testify / diff

Function diff

assert/assertions.go:1913–1954  ·  assert/assertions.go::diff

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

1911// diff returns a diff of both values as long as both are of the same type and
1912// are a struct, map, slice, array or string. Otherwise it returns an empty string.
1913func diff(expected interface{}, actual interface{}) string {
1914 if expected == nil || actual == nil {
1915 return ""
1916 }
1917
1918 et, ek := typeAndKind(expected)
1919 at, _ := typeAndKind(actual)
1920
1921 if et != at {
1922 return ""
1923 }
1924
1925 if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String {
1926 return ""
1927 }
1928
1929 var e, a string
1930
1931 switch et {
1932 case reflect.TypeOf(""):
1933 e = reflect.ValueOf(expected).String()
1934 a = reflect.ValueOf(actual).String()
1935 case reflect.TypeOf(time.Time{}):
1936 e = spewConfigStringerEnabled.Sdump(expected)
1937 a = spewConfigStringerEnabled.Sdump(actual)
1938 default:
1939 e = spewConfig.Sdump(expected)
1940 a = spewConfig.Sdump(actual)
1941 }
1942
1943 diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
1944 A: difflib.SplitLines(e),
1945 B: difflib.SplitLines(a),
1946 FromFile: "Expected",
1947 FromDate: "",
1948 ToFile: "Actual",
1949 ToDate: "",
1950 Context: 1,
1951 })
1952
1953 return "\n\nDiff:\n" + diff
1954}
1955
1956func isFunction(arg interface{}) bool {
1957 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