MCPcopy
hub / github.com/expr-lang/expr / diff

Function diff

internal/testify/assert/assertions.go:1794–1835  ·  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

1792// diff returns a diff of both values as long as both are of the same type and
1793// are a struct, map, slice, array or string. Otherwise it returns an empty string.
1794func diff(expected interface{}, actual interface{}) string {
1795 if expected == nil || actual == nil {
1796 return ""
1797 }
1798
1799 et, ek := typeAndKind(expected)
1800 at, _ := typeAndKind(actual)
1801
1802 if et != at {
1803 return ""
1804 }
1805
1806 if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String {
1807 return ""
1808 }
1809
1810 var e, a string
1811
1812 switch et {
1813 case reflect.TypeOf(""):
1814 e = reflect.ValueOf(expected).String()
1815 a = reflect.ValueOf(actual).String()
1816 case reflect.TypeOf(time.Time{}):
1817 e = spewConfigStringerEnabled.Sdump(expected)
1818 a = spewConfigStringerEnabled.Sdump(actual)
1819 default:
1820 e = spewConfig.Sdump(expected)
1821 a = spewConfig.Sdump(actual)
1822 }
1823
1824 diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
1825 A: difflib.SplitLines(e),
1826 B: difflib.SplitLines(a),
1827 FromFile: "Expected",
1828 FromDate: "",
1829 ToFile: "Actual",
1830 ToDate: "",
1831 Context: 1,
1832 })
1833
1834 return "\n\nDiff:\n" + diff
1835}
1836
1837func isFunction(arg interface{}) bool {
1838 if arg == nil {

Callers 7

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

Calls 5

GetUnifiedDiffStringFunction · 0.92
SplitLinesFunction · 0.92
typeAndKindFunction · 0.85
SdumpMethod · 0.80
StringMethod · 0.65

Tested by 4

TestInDeltaMapValuesFunction · 0.68
TestDiffFunction · 0.68
TestDiffEmptyCasesFunction · 0.68
TestDiffRaceFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…