Skip to content

Commit

Permalink
fix: array diffs are incorrect/unreliable
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Feb 22, 2022
1 parent 0525c87 commit e1b6910
Show file tree
Hide file tree
Showing 133 changed files with 8,351 additions and 8,156 deletions.
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module gojsondiff

go 1.17

require (
github.com/adrg/strutil v0.2.3
github.com/onsi/ginkgo v1.1.1-0.20150303023352-38caab951a9f
github.com/onsi/gomega v0.0.0-20150401040250-4dfabf7db2e4
github.com/sergi/go-diff v0.0.0-20170118131230-24e2351369ec
github.com/urfave/cli v1.19.2-0.20170215051705-2526b57c56f3
github.com/yudai/gojsondiff v1.0.0
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce
github.com/yudai/pp v2.0.2-0.20150410014804-be8315415630+incompatible
)

require (
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/mattn/go-colorable v0.0.6 // indirect
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c // indirect
golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 // indirect
)
34 changes: 34 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
github.com/adrg/strutil v0.2.3 h1:WZVn3ItPBovFmP4wMHHVXUr8luRaHrbyIuLlHt32GZQ=
github.com/adrg/strutil v0.2.3/go.mod h1:+SNxbiH6t+O+5SZqIj5n/9i5yUjR+S3XXVrjEcN2mxg=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/mattn/go-colorable v0.0.6 h1:jGqlOoCjqVR4hfTO9H1qrR2xi0xZNYmX2T1xlw7P79c=
github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c h1:3nKFouDdpgGUV/uerJcYWH45ZbJzX0SiVWfTgmUeTzc=
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/onsi/ginkgo v1.1.1-0.20150303023352-38caab951a9f h1:znMoXRti03ZIy/gaW5cl3EO2A5zqzHBKA6uMnrAQDE0=
github.com/onsi/ginkgo v1.1.1-0.20150303023352-38caab951a9f/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20150401040250-4dfabf7db2e4 h1:vXLCFNIK5zI1YgKSvgc5qXOvegcGfwvQ4G3hgFCA11A=
github.com/onsi/gomega v0.0.0-20150401040250-4dfabf7db2e4/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v0.0.0-20170118131230-24e2351369ec h1:shdBt9xKJPFOcYfVt160PFXcIKxJZC6165xf9qeWx/o=
github.com/sergi/go-diff v0.0.0-20170118131230-24e2351369ec/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli v1.19.2-0.20170215051705-2526b57c56f3 h1:aLFlkys2/c3jUVHyHhPeQjC5TZ8TtxHZhq5b7qpm0QE=
github.com/urfave/cli v1.19.2-0.20170215051705-2526b57c56f3/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce h1:888GrqRxabUce7lj4OaoShPxodm3kXOMpSa85wdYzfY=
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.2-0.20150410014804-be8315415630+incompatible h1:TmF93o7P81230DTx1l2zw5rZbsDpOOQXoKVCa8+nXXI=
github.com/yudai/pp v2.0.2-0.20150410014804-be8315415630+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 h1:ZLExsLvnoqWSw6JB6k6RjWobIHGR3NG9dzVANJ7SVKc=
golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 7 additions & 8 deletions gojsondiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"reflect"
"sort"

"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
dmp "github.com/sergi/go-diff/diffmatchpatch"
"github.com/yudai/golcs"
lcs "github.com/yudai/golcs"
)

// A Diff holds deltas generated by a Differ
Expand Down Expand Up @@ -329,11 +331,8 @@ func (differ *Differ) maximizeSimilarities(left []maybe, right []maybe) (resultD
}
for x := sizeX - 2; x >= 0; x-- {
for y := sizeY - 2; y >= 0; y-- {
prevX := dpTable[x+1][y]
prevY := dpTable[x][y+1]
score := deltaTable[x][y].Similarity() + dpTable[x+1][y+1]

dpTable[x][y] = max(prevX, prevY, score)
dpTable[x][y] = score
}
}

Expand Down Expand Up @@ -369,10 +368,10 @@ func (differ *Differ) maximizeSimilarities(left []maybe, right []maybe) (resultD
}
}
for ; x < sizeX-1; x++ {
freeLeft = append(freeLeft, left[x-1])
freeLeft = append(freeLeft, left[x])
}
for ; y < sizeY-1; y++ {
freeRight = append(freeRight, right[y-1])
freeRight = append(freeRight, right[y])
}

return resultDeltas, freeLeft, freeRight
Expand All @@ -395,7 +394,7 @@ func stringSimilarity(left, right string) (similarity float64) {
)
similarity =
(matchingLength / float64(len(left))) * (matchingLength / float64(len(right)))
return
return strutil.Similarity(left, right, metrics.NewLevenshtein())
}

func stringToInterfaceSlice(str string) []interface{} {
Expand Down
77 changes: 77 additions & 0 deletions vendor/github.com/adrg/strutil/CODE_OF_CONDUCT.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions vendor/github.com/adrg/strutil/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/adrg/strutil/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1b6910

Please sign in to comment.