MCPcopy Index your code
hub / github.com/gavv/httpexpect / formatDiff

Method formatDiff

formatter.go:705–743  ·  view source on GitHub ↗
(expected, actual interface{})

Source from the content-addressed store, hash-verified

703}
704
705func (f *DefaultFormatter) formatDiff(expected, actual interface{}) (string, bool) {
706 differ := gojsondiff.New()
707
708 var diff gojsondiff.Diff
709
710 if ve, ok := expected.(map[string]interface{}); ok {
711 if va, ok := actual.(map[string]interface{}); ok {
712 diff = differ.CompareObjects(ve, va)
713 } else {
714 return "", false
715 }
716 } else if ve, ok := expected.([]interface{}); ok {
717 if va, ok := actual.([]interface{}); ok {
718 diff = differ.CompareArrays(ve, va)
719 } else {
720 return "", false
721 }
722 } else {
723 return "", false
724 }
725
726 if !diff.Modified() {
727 return "", false
728 }
729
730 config := formatter.AsciiFormatterConfig{
731 ShowArrayIndex: true,
732 }
733 fa := formatter.NewAsciiFormatter(expected, config)
734
735 str, err := fa.Format(diff)
736 if err != nil {
737 return "", false
738 }
739
740 diffText := "--- expected\n+++ actual\n" + str
741
742 return diffText, true
743}
744
745func (f *DefaultFormatter) reformatNumber(numStr string) string {
746 signPart, intPart, fracPart, expPart := f.decomposeNumber(numStr)

Callers 2

TestFormatter_FormatDiffFunction · 0.95
fillExpectedMethod · 0.95

Calls

no outgoing calls

Tested by 1

TestFormatter_FormatDiffFunction · 0.76