Skip to content

Commit

Permalink
Additional tests for obliterate with and without expansion (microsoft…
Browse files Browse the repository at this point in the history
…#22562)

Add tests for interesting cases of obliterate, both with endpoint
expansion and without. All tests are currently skipped.

- `obliterate.spec.ts`: These tests fail as of now, but do not require
endpoint expansion in order to start passing.
- `obliterate.rangeExpansion.spec.ts`: These will not work without
endpoint expansion (microsoft#22552).

---------

Co-authored-by: Tony Murphy <[email protected]>
  • Loading branch information
jzaffiro and anthony-murphy authored Sep 19, 2024
1 parent a0b1e50 commit 1949d57
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/dds/merge-tree/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ export class Client extends TypedEventEmitter<IClientEvents> {
invalidPositions.push("start");
}
// Validate end if not insert, or insert has end
//
if (
(op.type !== MergeTreeDeltaType.INSERT || end !== undefined) &&
(end === undefined || end <= start!)
Expand Down
24 changes: 24 additions & 0 deletions packages/dds/merge-tree/src/test/obliterate.concurrent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ for (const incremental of [true, false]) {
MergeTree.options.incrementalUpdate = true;
});

it("obliterate, then insert at the end of the string", () => {
const helper = new ReconnectTestHelper();

helper.insertText("A", 0, "01234567");
helper.processAllOps();
helper.obliterateRange("A", 0, 8);
helper.insertText("B", 8, "BBB");
helper.processAllOps();

helper.logger.validate({ baseText: "BBB" });
});

it("insert, then obliterate at the end of the string", () => {
const helper = new ReconnectTestHelper();

helper.insertText("A", 0, "01234567");
helper.processAllOps();
helper.insertText("B", 8, "BBB");
helper.obliterateRange("A", 0, 8);
helper.processAllOps();

helper.logger.validate({ baseText: "BBB" });
});

it("length of children does not differ from parent when overlapping remove+obliterate", () => {
const helper = new ReconnectTestHelper();

Expand Down
47 changes: 47 additions & 0 deletions packages/dds/merge-tree/src/test/obliterate.rangeExpansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,53 @@ describe.skip("obliterate", () => {
expectedText: "XYZheo world",
expectedEventCount: 3,
});
itCorrectlyObliterates({
title: "zero length obliterate in the middle of the string",
action: (helper) => {
helper.insertText("A", 0, "hello world");
helper.processAllOps();

helper.obliterateRange("A", { pos: 0, side: Side.After }, { pos: 1, side: Side.Before });
helper.insertText("B", 0, "more ");
},
expectedText: "hello world",
// TODO: remove this after merging sided obliterates
expectedEventCount: 3,
});
itCorrectlyObliterates({
title: "obliterate, then insert at the end of the string",
action: (helper) => {
helper.insertText("A", 0, "hello world");
helper.processAllOps();

helper.obliterateRange(
"A",
{ pos: 5, side: Side.Before },
{ pos: 10, side: Side.After },
);
helper.insertText("B", 10, "123");
},
expectedText: "hello",
// TODO: remove this after merging sided obliterates
expectedEventCount: 3,
});
itCorrectlyObliterates({
title: "insert, then obliterate at the end of the string",
action: (helper) => {
helper.insertText("A", 0, "hello world");
helper.processAllOps();

helper.insertText("A", 10, "123");
helper.obliterateRange(
"B",
{ pos: 5, side: Side.Before },
{ pos: 10, side: Side.After },
);
},
expectedText: "hello",
// TODO: remove this after merging sided obliterates
expectedEventCount: 3,
});
});

describe.skip("overlapping edits", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/merge-tree/src/test/obliterate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe("obliterate", () => {
obliterateRange({
mergeTree: client.mergeTree,
start: 5,
end: "hello world".length,
end: client.getLength(),
refSeq,
clientId: remoteClientId,
seq: refSeq + 1,
Expand Down Expand Up @@ -162,7 +162,7 @@ describe("obliterate", () => {

describe("local obliterate with concurrent inserts", () => {
it("removes range when pending local obliterate op", () => {
client.obliterateRangeLocal(0, "hello world".length);
client.obliterateRangeLocal(0, client.getLength());
insertText({
mergeTree: client.mergeTree,
pos: 1,
Expand Down

0 comments on commit 1949d57

Please sign in to comment.