add test for non-overlapping insert-delete case

This commit is contained in:
Brian Gough
2016-01-26 12:07:33 +00:00
parent b3ddd839e6
commit ed0aaa189d
2 changed files with 22 additions and 1 deletions
@@ -133,6 +133,7 @@ module.exports = UpdateCompressor =
else if firstOp.i? and secondOp.d? and firstOp.p <= secondOp.p <= (firstOp.p + firstOp.i.length)
offset = secondOp.p - firstOp.p
insertedText = firstOp.i.slice(offset, offset + secondOp.d.length)
# Only trim the insert when the delete is fully contained within in it
if insertedText == secondOp.d
insert = strRemove(firstOp.i, offset, secondOp.d.length)
return [
@@ -146,7 +147,7 @@ module.exports = UpdateCompressor =
v: secondUpdate.v
]
else
# This shouldn't be possible!
# This will only happen if the delete extends outside the insert
return [firstUpdate, secondUpdate]
else
@@ -263,6 +263,26 @@ describe "UpdateCompressor", ->
v: 43
}]
it "should not combine updates with overlap beyond the end", ->
expect(@UpdateCompressor.compressUpdates [{
op: { p: 3, i: "foobar" }
meta: ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 6, d: "bardle" }
meta: ts: @ts2, user_id: @user_id
v: 43
}])
.to.deep.equal [{
op: { p: 3, i: "foobar" }
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
v: 42
}, {
op: { p: 6, d: "bardle" }
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
v: 43
}]
describe "noop - insert", ->
it "should leave them untouched", ->
expect(@UpdateCompressor.compressUpdates [{