-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Loro, LoroList, LoroMap } from "npm:loro-crdt@0.6.3" | ||
import { Loro, LoroList, LoroMap, LoroText } from "npm:loro-crdt@0.15.0" | ||
import { expect } from "npm:[email protected]" | ||
|
||
Deno.test("Basic usage", () => { | ||
|
@@ -37,11 +37,11 @@ Deno.test("Sub containers", () => { | |
const list: LoroList = doc.getList("list"); | ||
const map: LoroMap = doc.getMap("list"); | ||
// insert a List container at index 0, and get the handler to that list | ||
const subList = list.insertContainer(0, "List"); | ||
const subList = list.insertContainer(0, new LoroList()); | ||
subList.insert(0, "A"); | ||
expect(list.toJson()).toStrictEqual([["A"]]); | ||
// create a Text container inside the Map container | ||
const subtext = map.setContainer("text", "Text"); | ||
const subtext = map.setContainer("text", new LoroText()); | ||
subtext.insert(0, "Hi"); | ||
expect(map.toJson()).toStrictEqual({ text: "Hi" }); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Delta, Loro } from "npm:loro-crdt@0.6.3"; | ||
import { Delta, Loro } from "npm:loro-crdt@0.15.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Text", () => { | ||
|
@@ -37,9 +37,10 @@ Deno.test("Rich text custom expand behavior - Bold", () => { | |
* - Link: will not expand the style when inserting new text at the boundary. | ||
*/ | ||
const doc = new Loro(); | ||
doc.configTextStyle({ bold: { expand: "after" } }) | ||
const text = doc.getText("text"); | ||
text.insert(0, "Hello world!"); | ||
text.mark({ start: 0, end: 5, expand: "after" }, "bold", true); | ||
text.mark({ start: 0, end: 5 }, "bold", true); | ||
text.insert(5, "!"); | ||
expect(text.toDelta()).toStrictEqual([{ | ||
insert: "Hello!", | ||
|
@@ -59,9 +60,12 @@ Deno.test("Rich text custom expand behavior - Link", () => { | |
* - Link: will not expand the style when inserting new text at the boundary. | ||
*/ | ||
const doc = new Loro(); | ||
doc.configTextStyle({ | ||
link: { expand: "none" }, | ||
}) | ||
const text = doc.getText("text"); | ||
text.insert(0, "Hello world!"); | ||
text.mark({ start: 0, end: 5, expand: "none" }, "link", true); | ||
text.mark({ start: 0, end: 5 }, "link", true); | ||
text.insert(5, "!"); | ||
expect(text.toDelta()).toStrictEqual([{ | ||
insert: "Hello", | ||
|
@@ -80,13 +84,15 @@ Deno.test("Rich text event", async () => { | |
text.insert(0, "Hello world!"); | ||
doc.commit(); | ||
let ran = false; | ||
text.subscribe(doc, (event) => { | ||
if (event.diff.type === "text") { | ||
expect(event.diff.diff).toStrictEqual([{ | ||
retain: 5, | ||
attributes: { bold: true } | ||
}]); | ||
ran = true; | ||
text.subscribe((events) => { | ||
for (const event of events.events) { | ||
if (event.diff.type === "text") { | ||
expect(event.diff.diff).toStrictEqual([{ | ||
retain: 5, | ||
attributes: { bold: true } | ||
}]); | ||
ran = true; | ||
} | ||
} | ||
}); | ||
text.mark({ start: 0, end: 5 }, "bold", true); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Loro, OpId } from "npm:loro-crdt@0.6.3"; | ||
import { Loro, OpId } from "npm:loro-crdt@0.15.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
|
||
|
@@ -16,8 +16,8 @@ Deno.test("Frontiers & Version Vector Conversion", () => { | |
doc1.commit(); | ||
|
||
const frontiers = doc1.frontiers(); | ||
expect(frontiers).toStrictEqual([{ peer: 1n, counter: 1 } as OpId]) | ||
expect(frontiers).toStrictEqual([{ peer: "1", counter: 1 } as OpId]) | ||
const vv = doc1.frontiersToVV(frontiers); | ||
expect(vv).toStrictEqual(new Map([[0n, 1], [1n, 2]])) | ||
expect(vv.toJSON()).toStrictEqual(new Map([["0", 1], ["1", 2]])) | ||
expect(doc1.vvToFrontiers(vv)).toStrictEqual(frontiers); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Loro } from "npm:loro-crdt@0.6.3"; | ||
import { Loro } from "npm:loro-crdt@0.15.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Time Travel", () => { | ||
|
@@ -16,12 +16,12 @@ Deno.test("Time Travel", () => { | |
}); | ||
|
||
// Every unicode char insertion is a single operation for Text container | ||
doc.checkout([{ peer: 0n, counter: 0 }]); | ||
doc.checkout([{ peer: "0", counter: 0 }]); | ||
expect(doc.toJson()).toStrictEqual({ | ||
text: "H" | ||
}); | ||
|
||
doc.checkout([{ peer: 0n, counter: 4 }]); | ||
doc.checkout([{ peer: "0", counter: 4 }]); | ||
expect(doc.toJson()).toStrictEqual({ | ||
text: "Hello" | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Loro } from "npm:loro-crdt@0.6.3"; | ||
import { Loro } from "npm:loro-crdt@0.15.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Save and load", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { Loro, LoroText, getType } from "npm:loro-crdt@0.6.3"; | ||
import { Loro, LoroMap, LoroText, getType } from "npm:loro-crdt@0.15.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Event have delta that contains Container", async () => { | ||
const doc = new Loro(); | ||
const list = doc.getList("list"); | ||
let ran = false; | ||
doc.subscribe(event => { | ||
if (event.diff.type === "list") { | ||
for (const item of event.diff.diff) { | ||
expect(item.insert?.length).toBe(2); | ||
expect(getType(item.insert![0])).toBe("Text") | ||
expect(getType(item.insert![1])).toBe("Map") | ||
const t = item.insert![0] as LoroText; | ||
expect(t.toString()).toBe("Hello") | ||
doc.subscribe(events => { | ||
for (const event of events.events) { | ||
if (event.diff.type === "list") { | ||
for (const item of event.diff.diff) { | ||
expect(item.insert?.length).toBe(2); | ||
expect(getType(item.insert![0])).toBe("Text") | ||
expect(getType(item.insert![1])).toBe("Map") | ||
const t = item.insert![0] as LoroText; | ||
expect(t.toString()).toBe("Hello") | ||
} | ||
ran = true; | ||
} | ||
ran = true; | ||
} | ||
}) | ||
|
||
list.insertContainer(0, "Map"); | ||
const t = list.insertContainer(0, "Text"); | ||
list.insertContainer(0, new LoroMap()); | ||
const t = list.insertContainer(0, new LoroText()); | ||
t.insert(0, "He"); | ||
t.insert(2, "llo"); | ||
doc.commit(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Loro, LoroList, LoroMovableList, LoroText } from "npm:[email protected]"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("List", () => { | ||
let list = new LoroList(); | ||
list.push(0); | ||
list.push("1"); | ||
const doc = new Loro(); | ||
const map = doc.getMap("root"); | ||
list = map.setContainer("list", list); | ||
expect(doc.toJson()).toStrictEqual({ root: { list: [0, "1"] } }); | ||
list.delete(0, 1); | ||
expect(doc.toJson()).toStrictEqual({ root: { list: ["1"] } }); | ||
}) | ||
|
||
Deno.test("MovableList", () => { | ||
let list = new LoroMovableList(); | ||
list.push(0); | ||
list.push("1"); | ||
const doc = new Loro(); | ||
const map = doc.getMap("root"); | ||
list = map.setContainer("list", list); | ||
expect(doc.toJson()).toStrictEqual({ root: { list: [0, "1"] } }); | ||
list.move(0, 1); | ||
expect(doc.toJson()).toStrictEqual({ root: { list: ["1", 0] } }); | ||
// Uint8Array is a special type in Loro | ||
list.set(1, new Uint8Array([1, 2, 3])); | ||
expect(doc.toJson()).toStrictEqual({ root: { list: ["1", new Uint8Array([1, 2, 3])] } }); | ||
const text = list.setContainer(0, new LoroText()); | ||
text.insert(0, "Hello") | ||
expect(doc.toJson()).toStrictEqual({ root: { list: ["Hello", new Uint8Array([1, 2, 3])] } }); | ||
}) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.