Skip to content

Commit db0b0d5

Browse files
committed
fix: adapt to v0.15.0
1 parent afbf996 commit db0b0d5

File tree

8 files changed

+84
-32
lines changed

8 files changed

+84
-32
lines changed

01_basic.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Loro, LoroList, LoroMap } from "npm:loro-crdt@0.6.3"
1+
import { Loro, LoroList, LoroMap, LoroText } from "npm:loro-crdt@0.15.0"
22
import { expect } from "npm:[email protected]"
33

44
Deno.test("Basic usage", () => {
@@ -37,11 +37,11 @@ Deno.test("Sub containers", () => {
3737
const list: LoroList = doc.getList("list");
3838
const map: LoroMap = doc.getMap("list");
3939
// insert a List container at index 0, and get the handler to that list
40-
const subList = list.insertContainer(0, "List");
40+
const subList = list.insertContainer(0, new LoroList());
4141
subList.insert(0, "A");
4242
expect(list.toJson()).toStrictEqual([["A"]]);
4343
// create a Text container inside the Map container
44-
const subtext = map.setContainer("text", "Text");
44+
const subtext = map.setContainer("text", new LoroText());
4545
subtext.insert(0, "Hi");
4646
expect(map.toJson()).toStrictEqual({ text: "Hi" });
4747
});

02_text.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Delta, Loro } from "npm:loro-crdt@0.6.3";
1+
import { Delta, Loro } from "npm:loro-crdt@0.15.0";
22
import { expect } from "npm:[email protected]";
33

44
Deno.test("Text", () => {
@@ -37,9 +37,10 @@ Deno.test("Rich text custom expand behavior - Bold", () => {
3737
* - Link: will not expand the style when inserting new text at the boundary.
3838
*/
3939
const doc = new Loro();
40+
doc.configTextStyle({ bold: { expand: "after" } })
4041
const text = doc.getText("text");
4142
text.insert(0, "Hello world!");
42-
text.mark({ start: 0, end: 5, expand: "after" }, "bold", true);
43+
text.mark({ start: 0, end: 5 }, "bold", true);
4344
text.insert(5, "!");
4445
expect(text.toDelta()).toStrictEqual([{
4546
insert: "Hello!",
@@ -59,9 +60,12 @@ Deno.test("Rich text custom expand behavior - Link", () => {
5960
* - Link: will not expand the style when inserting new text at the boundary.
6061
*/
6162
const doc = new Loro();
63+
doc.configTextStyle({
64+
link: { expand: "none" },
65+
})
6266
const text = doc.getText("text");
6367
text.insert(0, "Hello world!");
64-
text.mark({ start: 0, end: 5, expand: "none" }, "link", true);
68+
text.mark({ start: 0, end: 5 }, "link", true);
6569
text.insert(5, "!");
6670
expect(text.toDelta()).toStrictEqual([{
6771
insert: "Hello",
@@ -80,13 +84,15 @@ Deno.test("Rich text event", async () => {
8084
text.insert(0, "Hello world!");
8185
doc.commit();
8286
let ran = false;
83-
text.subscribe(doc, (event) => {
84-
if (event.diff.type === "text") {
85-
expect(event.diff.diff).toStrictEqual([{
86-
retain: 5,
87-
attributes: { bold: true }
88-
}]);
89-
ran = true;
87+
text.subscribe((events) => {
88+
for (const event of events.events) {
89+
if (event.diff.type === "text") {
90+
expect(event.diff.diff).toStrictEqual([{
91+
retain: 5,
92+
attributes: { bold: true }
93+
}]);
94+
ran = true;
95+
}
9096
}
9197
});
9298
text.mark({ start: 0, end: 5 }, "bold", true);

03_version.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Loro, OpId } from "npm:loro-crdt@0.6.3";
1+
import { Loro, OpId } from "npm:loro-crdt@0.15.0";
22
import { expect } from "npm:[email protected]";
33

44

@@ -16,8 +16,8 @@ Deno.test("Frontiers & Version Vector Conversion", () => {
1616
doc1.commit();
1717

1818
const frontiers = doc1.frontiers();
19-
expect(frontiers).toStrictEqual([{ peer: 1n, counter: 1 } as OpId])
19+
expect(frontiers).toStrictEqual([{ peer: "1", counter: 1 } as OpId])
2020
const vv = doc1.frontiersToVV(frontiers);
21-
expect(vv).toStrictEqual(new Map([[0n, 1], [1n, 2]]))
21+
expect(vv.toJSON()).toStrictEqual(new Map([["0", 1], ["1", 2]]))
2222
expect(doc1.vvToFrontiers(vv)).toStrictEqual(frontiers);
2323
})

04_time_travel.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Loro } from "npm:loro-crdt@0.6.3";
1+
import { Loro } from "npm:loro-crdt@0.15.0";
22
import { expect } from "npm:[email protected]";
33

44
Deno.test("Time Travel", () => {
@@ -16,12 +16,12 @@ Deno.test("Time Travel", () => {
1616
});
1717

1818
// Every unicode char insertion is a single operation for Text container
19-
doc.checkout([{ peer: 0n, counter: 0 }]);
19+
doc.checkout([{ peer: "0", counter: 0 }]);
2020
expect(doc.toJson()).toStrictEqual({
2121
text: "H"
2222
});
2323

24-
doc.checkout([{ peer: 0n, counter: 4 }]);
24+
doc.checkout([{ peer: "0", counter: 4 }]);
2525
expect(doc.toJson()).toStrictEqual({
2626
text: "Hello"
2727
});

05_save_and_load.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Loro } from "npm:loro-crdt@0.6.3";
1+
import { Loro } from "npm:loro-crdt@0.15.0";
22
import { expect } from "npm:[email protected]";
33

44
Deno.test("Save and load", () => {

06_event.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import { Loro, LoroText, getType } from "npm:loro-crdt@0.6.3";
1+
import { Loro, LoroMap, LoroText, getType } from "npm:loro-crdt@0.15.0";
22
import { expect } from "npm:[email protected]";
33

44
Deno.test("Event have delta that contains Container", async () => {
55
const doc = new Loro();
66
const list = doc.getList("list");
77
let ran = false;
8-
doc.subscribe(event => {
9-
if (event.diff.type === "list") {
10-
for (const item of event.diff.diff) {
11-
expect(item.insert?.length).toBe(2);
12-
expect(getType(item.insert![0])).toBe("Text")
13-
expect(getType(item.insert![1])).toBe("Map")
14-
const t = item.insert![0] as LoroText;
15-
expect(t.toString()).toBe("Hello")
8+
doc.subscribe(events => {
9+
for (const event of events.events) {
10+
if (event.diff.type === "list") {
11+
for (const item of event.diff.diff) {
12+
expect(item.insert?.length).toBe(2);
13+
expect(getType(item.insert![0])).toBe("Text")
14+
expect(getType(item.insert![1])).toBe("Map")
15+
const t = item.insert![0] as LoroText;
16+
expect(t.toString()).toBe("Hello")
17+
}
18+
ran = true;
1619
}
17-
ran = true;
1820
}
1921
})
2022

21-
list.insertContainer(0, "Map");
22-
const t = list.insertContainer(0, "Text");
23+
list.insertContainer(0, new LoroMap());
24+
const t = list.insertContainer(0, new LoroText());
2325
t.insert(0, "He");
2426
t.insert(2, "llo");
2527
doc.commit();

07_list.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Loro, LoroList, LoroMovableList, LoroText } from "npm:[email protected]";
2+
import { expect } from "npm:[email protected]";
3+
4+
Deno.test("List", () => {
5+
let list = new LoroList();
6+
list.push(0);
7+
list.push("1");
8+
const doc = new Loro();
9+
const map = doc.getMap("root");
10+
list = map.setContainer("list", list);
11+
expect(doc.toJson()).toStrictEqual({ root: { list: [0, "1"] } });
12+
list.delete(0, 1);
13+
expect(doc.toJson()).toStrictEqual({ root: { list: ["1"] } });
14+
})
15+
16+
Deno.test("MovableList", () => {
17+
let list = new LoroMovableList();
18+
list.push(0);
19+
list.push("1");
20+
const doc = new Loro();
21+
const map = doc.getMap("root");
22+
list = map.setContainer("list", list);
23+
expect(doc.toJson()).toStrictEqual({ root: { list: [0, "1"] } });
24+
list.move(0, 1);
25+
expect(doc.toJson()).toStrictEqual({ root: { list: ["1", 0] } });
26+
// Uint8Array is a special type in Loro
27+
list.set(1, new Uint8Array([1, 2, 3]));
28+
expect(doc.toJson()).toStrictEqual({ root: { list: ["1", new Uint8Array([1, 2, 3])] } });
29+
const text = list.setContainer(0, new LoroText());
30+
text.insert(0, "Hello")
31+
expect(doc.toJson()).toStrictEqual({ root: { list: ["Hello", new Uint8Array([1, 2, 3])] } });
32+
})
33+

deno.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)