Open blaskovicz opened 7 years ago
Given two arrays of objects, if the objects appear in a different order, reflect.DeepEqual(expected, actual) will return false, whereas differ.CompareArrays(expected, actual) will contain an unexpected diff.
reflect.DeepEqual(expected, actual)
false
differ.CompareArrays(expected, actual)
Reproducer:
package main import ( "fmt" "github.com/yudai/gojsondiff" "github.com/yudai/gojsondiff/formatter" ) func main() { a := map[string]interface{}{"key": "bobby", "val": "tables", "foo": false} b := map[string]interface{}{"key": "how", "val": "outage", "foo": true} c := map[string]interface{}{"key": "stuffs", "val": "sample", "foo": true} expected := []interface{}{a, b, c} //actual := []interface{}{a, b, c} actual := []interface{}{b, c, a} differ := gojsondiff.New() diff := differ.CompareArrays(expected, actual) //diff := differ.CompareObjects(map[string]interface{}{"_": expected}, map[string]interface{}{"_": actual}) //formatter := formatter.NewDeltaFormatter() formatter := formatter.NewAsciiFormatter(expected, formatter.AsciiFormatterConfig{ShowArrayIndex: true}) str, err := formatter.Format(diff) if err != nil { panic(err) } fmt.Printf("%s\n", str) }
Diff Results:
$ go run diff.go [ 0: { "foo": false, "key": "bobby", "val": "tables" }, 1: { "foo": true, "key": "how", "val": "outage" }, ]
Diff Results from jsondiff.com:
@blaskovicz Thank you for the report.
It looks a bug. I'll take a look more when I have time.
Given two arrays of objects, if the objects appear in a different order,
reflect.DeepEqual(expected, actual)
will returnfalse
, whereasdiffer.CompareArrays(expected, actual)
will contain an unexpected diff.Reproducer:
Diff Results:
Diff Results from jsondiff.com: