@@ -37,24 +37,47 @@ func AssertEqualJQ(t *testing.T, expectedName, outName, expected, out string, ig
3737 } else {
3838 diff := UnifiedDiff (expectedName , outName , expected , out )
3939 t .Logf ("Diff:\n %s" , diff )
40- ignoredDiffs := []string {}
40+ allowedDiffs := []string {}
4141 erroredDiffs := []string {}
4242 for _ , op := range patch {
43- if matchesPrefixes (ignorePaths , op . Path ) {
44- ignoredDiffs = append (ignoredDiffs , fmt .Sprintf ("%7s %s %v" , op .Type , op .Path , op .Value ))
43+ if allowDifference (ignorePaths , op ) {
44+ allowedDiffs = append (allowedDiffs , fmt .Sprintf ("%7s %s %v old=%v " , op .Type , op .Path , op .Value , op . OldValue ))
4545 } else {
46- erroredDiffs = append (erroredDiffs , fmt .Sprintf ("%7s %s %v" , op .Type , op .Path , op .Value ))
46+ erroredDiffs = append (erroredDiffs , fmt .Sprintf ("%7s %s %v old=%v " , op .Type , op .Path , op .Value , op . OldValue ))
4747 }
4848 }
49- if len (ignoredDiffs ) > 0 {
50- t .Logf ("Ignored differences between %s and %s:\n ==> %s" , expectedName , outName , strings .Join (ignoredDiffs , "\n ==> " ))
49+ if len (allowedDiffs ) > 0 {
50+ t .Logf ("Allowed differences between %s and %s:\n ==> %s" , expectedName , outName , strings .Join (allowedDiffs , "\n ==> " ))
5151 }
5252 if len (erroredDiffs ) > 0 {
5353 t .Errorf ("Unexpected differences between %s and %s:\n ==> %s" , expectedName , outName , strings .Join (erroredDiffs , "\n ==> " ))
5454 }
5555 }
5656}
5757
58+ func allowDifference (ignorePaths []string , op jsondiff.Operation ) bool {
59+ if matchesPrefixes (ignorePaths , op .Path ) {
60+ return true
61+ }
62+ if op .Type == "replace" && almostSameStrings (op .OldValue , op .Value ) {
63+ return true
64+ }
65+ return false
66+ }
67+
68+ // compare strings and ignore forward vs backward slashes
69+ func almostSameStrings (v1 , v2 any ) bool {
70+ s1 , ok := v1 .(string )
71+ if ! ok {
72+ return false
73+ }
74+ s2 , ok := v2 .(string )
75+ if ! ok {
76+ return false
77+ }
78+ return strings .ReplaceAll (s1 , "\\ " , "/" ) == strings .ReplaceAll (s2 , "\\ " , "/" )
79+ }
80+
5881func matchesPrefixes (prefixes []string , path string ) bool {
5982 for _ , p := range prefixes {
6083 if p == path {
0 commit comments