Skip to content

Commit

Permalink
Check round trip fuzzing.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephburnett committed Feb 8, 2022
1 parent b37264c commit 0eeba92
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,38 @@ func FuzzJd(f *testing.F) {
return
}
if a == nil {
t.Errorf("nil parsed input: %v", aStr)
t.Errorf("nil parsed input: %q", aStr)
return
}
b, err := ReadJsonString(bStr)
if err != nil {
return
}
if b == nil {
t.Errorf("nil parsed input: %v", bStr)
t.Errorf("nil parsed input: %q", bStr)
return
}
diffAB := a.Diff(b)
if diffAB == nil {
// Diff A and B.
d := a.Diff(b)
if d == nil {
t.Errorf("nil diff of a and b")
return
}
diffABStr := d.Render()
diffAB, err := ReadDiffString(diffABStr)
if err != nil {
t.Errorf("error parsing diff string %q: %v", diffABStr, err)
return
}
// Apply diff to A to get B.
patchedA, err := a.Patch(diffAB)
if err != nil {
t.Errorf("applying patch %v to %v should give %v. Got err: %v", diffAB, aStr, bStr, err)
return
}
if !patchedA.Equals(b) {
t.Errorf("applying patch %v to %v should give %v. Got err: %v", diffAB, aStr, bStr, patchedA)
return
}
})
}

0 comments on commit 0eeba92

Please sign in to comment.