@@ -287,10 +287,13 @@ func largeJsonDiffTests(t *testing.T) []jsonDiffTest {
287287 ctx := sql .NewEmptyContext ()
288288 ns := NewTestNodeStore ()
289289
290+ emptyDocument := types.JSONDocument {Val : types.JsonObject {}}
291+
290292 insert := func (document types.MutableJSON , path string , val interface {}) types.MutableJSON {
291293 jsonVal , inRange , err := types .JSON .Convert (val )
292294 require .NoError (t , err )
293295 require .True (t , (bool )(inRange ))
296+ document = document .Clone (ctx ).(types.MutableJSON )
294297 newDoc , changed , err := document .Insert (ctx , path , jsonVal .(sql.JSONWrapper ))
295298 require .NoError (t , err )
296299 require .True (t , changed )
@@ -400,6 +403,18 @@ func largeJsonDiffTests(t *testing.T) []jsonDiffTest {
400403 },
401404 },
402405 },
406+ {
407+ // This is a regression test.
408+ // If:
409+ // - One document fits in a single chunk and the other doesn't
410+ // - The location of the chunk boundary in the larger document is also present in the smaller document
411+ // - The chunk boundary doesn't fall at the beginning of value.
412+ // Then the differ would fail to advance the prolly tree cursor and would incorrectly see the larger document as corrupt.
413+ // The values in this test case are specifically chosen to meet these conditions.
414+ name : "no error when diffing large doc with small doc" ,
415+ from : largeObject ,
416+ to : insert (emptyDocument , "$.level6" , insert (emptyDocument , "$.level4" , lookup (largeObject , "$.level6.level4" ))),
417+ },
403418 }
404419}
405420
@@ -473,9 +488,11 @@ func runTest(t *testing.T, test jsonDiffTest) {
473488
474489 return cmp == 0
475490 }
476- require .Equal (t , len (test .expectedDiffs ), len (actualDiffs ))
477- for i , expected := range test .expectedDiffs {
478- actual := actualDiffs [i ]
479- require .True (t , diffsEqual (expected , actual ), fmt .Sprintf ("Expected: %v\n Actual: %v" , expected , actual ))
491+ if test .expectedDiffs != nil {
492+ require .Equal (t , len (test .expectedDiffs ), len (actualDiffs ))
493+ for i , expected := range test .expectedDiffs {
494+ actual := actualDiffs [i ]
495+ require .True (t , diffsEqual (expected , actual ), fmt .Sprintf ("Expected: %v\n Actual: %v" , expected , actual ))
496+ }
480497 }
481498}
0 commit comments