-
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
12 changed files
with
103 additions
and
53 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, LoroText } from "npm:loro-crdt@0.15.0" | ||
import { Loro, LoroList, LoroMap, LoroText } from "npm:loro-crdt@0.16.4-alpha.0" | ||
import { expect } from "npm:[email protected]" | ||
|
||
Deno.test("Basic usage", () => { | ||
|
@@ -15,14 +15,14 @@ Deno.test("Basic usage", () => { | |
const map: LoroMap = doc.getMap("map"); | ||
// map can only has string key | ||
map.set("key", "value"); | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
list: ["A", "B", "C"], | ||
map: { key: "value" } | ||
}); | ||
|
||
// delete 2 element at index 0 | ||
list.delete(0, 2) | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
list: ["C"], | ||
map: { key: "value" } | ||
}); | ||
|
@@ -39,11 +39,11 @@ Deno.test("Sub containers", () => { | |
// insert a List container at index 0, and get the handler to that list | ||
const subList = list.insertContainer(0, new LoroList()); | ||
subList.insert(0, "A"); | ||
expect(list.toJson()).toStrictEqual([["A"]]); | ||
expect(list.toJSON()).toStrictEqual([["A"]]); | ||
// create a Text container inside the Map container | ||
const subtext = map.setContainer("text", new LoroText()); | ||
subtext.insert(0, "Hi"); | ||
expect(map.toJson()).toStrictEqual({ text: "Hi" }); | ||
expect(map.toJSON()).toStrictEqual({ text: "Hi" }); | ||
}); | ||
|
||
Deno.test("Sync", () => { | ||
|
@@ -58,7 +58,7 @@ Deno.test("Sync", () => { | |
listA.insert(2, "C"); | ||
// B import the ops from A | ||
docB.import(docA.exportFrom()); | ||
expect(docB.toJson()).toStrictEqual({ | ||
expect(docB.toJSON()).toStrictEqual({ | ||
list: ["A", "B", "C"] | ||
}) | ||
|
||
|
@@ -68,8 +68,8 @@ Deno.test("Sync", () => { | |
// A import the missing ops from B | ||
docA.import(docB.exportFrom(docA.version())) | ||
// list at A is now ["A", "C"], with the same state as B | ||
expect(docA.toJson()).toStrictEqual({ | ||
expect(docA.toJSON()).toStrictEqual({ | ||
list: ["A", "C"] | ||
}); | ||
expect(docA.toJson()).toStrictEqual(docB.toJson()); | ||
expect(docA.toJSON()).toStrictEqual(docB.toJSON()); | ||
}) |
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,6 +1,19 @@ | ||
import { Delta, Loro } from "npm:[email protected].0"; | ||
import { Delta, Loro } from "npm:[email protected].2"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Long text", () => { | ||
/** | ||
* Loro supports text manipulation. | ||
*/ | ||
const doc = new Loro(); | ||
const text = doc.getText("text"); | ||
for (let i = 0; i < 1_000_000; i += 1) { | ||
text.insert(i, i.toString()) | ||
} | ||
doc.exportFrom(); | ||
doc.exportSnapshot(); | ||
}); | ||
|
||
Deno.test("Text", () => { | ||
/** | ||
* Loro supports text manipulation. | ||
|
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.15.0"; | ||
import { Loro, OpId } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
|
||
|
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.15.0"; | ||
import { Loro } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Time Travel", () => { | ||
|
@@ -11,24 +11,24 @@ Deno.test("Time Travel", () => { | |
text.insert(0, "Hello"); | ||
doc.commit(); | ||
text.insert(5, " world"); | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
text: "Hello world" | ||
}); | ||
|
||
// Every unicode char insertion is a single operation for Text container | ||
doc.checkout([{ peer: "0", counter: 0 }]); | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
text: "H" | ||
}); | ||
|
||
doc.checkout([{ peer: "0", counter: 4 }]); | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
text: "Hello" | ||
}); | ||
|
||
// Returns to the latest version | ||
doc.attach(); | ||
expect(doc.toJson()).toStrictEqual({ | ||
expect(doc.toJSON()).toStrictEqual({ | ||
text: "Hello world" | ||
}); | ||
}) |
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.15.0"; | ||
import { Loro } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Save and load", () => { | ||
|
@@ -10,7 +10,7 @@ Deno.test("Save and load", () => { | |
|
||
const newDoc = new Loro(); | ||
newDoc.import(data); | ||
expect(newDoc.toJson()).toStrictEqual({ | ||
expect(newDoc.toJSON()).toStrictEqual({ | ||
text: "Hello world!" | ||
}); | ||
}) | ||
|
@@ -37,19 +37,19 @@ Deno.test("Save and load incrementally", () => { | |
// import the snapshot | ||
const newDoc = new Loro(); | ||
newDoc.import(data); | ||
expect(newDoc.toJson()).toStrictEqual({ | ||
expect(newDoc.toJSON()).toStrictEqual({ | ||
text: "Hello world!" | ||
}); | ||
|
||
// import update0 | ||
newDoc.import(update0) | ||
expect(newDoc.toJson()).toStrictEqual({ | ||
expect(newDoc.toJSON()).toStrictEqual({ | ||
text: "✨Hello world!" | ||
}); | ||
|
||
// import update1 | ||
newDoc.import(update1) | ||
expect(newDoc.toJson()).toStrictEqual({ | ||
expect(newDoc.toJSON()).toStrictEqual({ | ||
text: "😶🌫️✨Hello world!" | ||
}); | ||
} | ||
|
@@ -60,7 +60,7 @@ Deno.test("Save and load incrementally", () => { | |
*/ | ||
const newDoc = new Loro(); | ||
newDoc.importUpdateBatch([update1, update0, data]) | ||
expect(newDoc.toJson()).toStrictEqual({ | ||
expect(newDoc.toJSON()).toStrictEqual({ | ||
text: "😶🌫️✨Hello world!" | ||
}); | ||
} | ||
|
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, LoroMap, LoroText, getType } from "npm:loro-crdt@0.15.0"; | ||
import { Loro, LoroMap, LoroText, getType } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Event have delta that contains Container", async () => { | ||
|
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 { Cursor, Loro } from "npm:loro-crdt@0.15.0"; | ||
import { Cursor, Loro } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("List", () => { | ||
|
@@ -17,15 +17,15 @@ Deno.test("List", () => { | |
// Concurrently docA and docB update element at index 2 | ||
// docA updates it to 8 | ||
// docB updates it to 9 | ||
// docA.toJson() should return { list: [0, 1, 8] } | ||
// docB.toJson() should return { list: [0, 1, 9] } | ||
// docA.toJSON() should return { list: [0, 1, 8] } | ||
// docB.toJSON() should return { list: [0, 1, 9] } | ||
|
||
listB.delete(2, 1); | ||
listB.insert(2, 9); | ||
expect(docB.toJson()).toStrictEqual({ list: [0, 1, 9] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [0, 1, 9] }); | ||
listA.delete(2, 1); | ||
listA.insert(2, 8); | ||
expect(docA.toJson()).toStrictEqual({ list: [0, 1, 8] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [0, 1, 8] }); | ||
} | ||
|
||
{ | ||
|
@@ -34,8 +34,8 @@ Deno.test("List", () => { | |
docB.import(docA.exportFrom(docB.version())); | ||
} | ||
|
||
expect(docA.toJson()).toStrictEqual({ list: [0, 1, 8, 9] }); | ||
expect(docB.toJson()).toStrictEqual({ list: [0, 1, 8, 9] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [0, 1, 8, 9] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [0, 1, 8, 9] }); | ||
}) | ||
|
||
Deno.test("MovableList", () => { | ||
|
@@ -54,13 +54,13 @@ Deno.test("MovableList", () => { | |
// Concurrently docA and docB update element at index 2 | ||
// docA updates it to 8 | ||
// docB updates it to 9 | ||
// docA.toJson() should return { list: [0, 1, 8] } | ||
// docB.toJson() should return { list: [0, 1, 9] } | ||
// docA.toJSON() should return { list: [0, 1, 8] } | ||
// docB.toJSON() should return { list: [0, 1, 9] } | ||
|
||
listA.set(2, 8); | ||
expect(docA.toJson()).toStrictEqual({ list: [0, 1, 8] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [0, 1, 8] }); | ||
listB.set(2, 9); | ||
expect(docB.toJson()).toStrictEqual({ list: [0, 1, 9] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [0, 1, 9] }); | ||
} | ||
|
||
{ | ||
|
@@ -70,20 +70,20 @@ Deno.test("MovableList", () => { | |
} | ||
|
||
// Converge to [0, 1, 9] because docB has larger peerId thus larger logical time | ||
expect(docA.toJson()).toStrictEqual({ list: [0, 1, 9] }); | ||
expect(docB.toJson()).toStrictEqual({ list: [0, 1, 9] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [0, 1, 9] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [0, 1, 9] }); | ||
|
||
{ | ||
// Concurrently docA and docB move element at index 0 | ||
// docA moves it to 2 | ||
// docB moves it to 1 | ||
// docA.toJson() should return { list: [1, 9, 0] } | ||
// docB.toJson() should return { list: [1, 0, 9] } | ||
// docA.toJSON() should return { list: [1, 9, 0] } | ||
// docB.toJSON() should return { list: [1, 0, 9] } | ||
|
||
listA.move(0, 2); | ||
listB.move(0, 1); | ||
expect(docA.toJson()).toStrictEqual({ list: [1, 9, 0] }); | ||
expect(docB.toJson()).toStrictEqual({ list: [1, 0, 9] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [1, 9, 0] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [1, 0, 9] }); | ||
} | ||
|
||
{ | ||
|
@@ -93,8 +93,8 @@ Deno.test("MovableList", () => { | |
} | ||
|
||
// Converge to [1, 0, 9] because docB has larger peerId thus larger logical time | ||
expect(docA.toJson()).toStrictEqual({ list: [1, 0, 9] }); | ||
expect(docB.toJson()).toStrictEqual({ list: [1, 0, 9] }); | ||
expect(docA.toJSON()).toStrictEqual({ list: [1, 0, 9] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: [1, 0, 9] }); | ||
}) | ||
|
||
|
||
|
@@ -119,22 +119,22 @@ Deno.test("List Cursors", () => { | |
const listB = docB.getList("list"); | ||
docB.import(exported); | ||
listB.insert(0, "Foo"); | ||
expect(docB.toJson()).toStrictEqual({ list: ["Foo", "Hello", "World"] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: ["Foo", "Hello", "World"] }); | ||
const cursorB = Cursor.decode(encodedCursor); | ||
{ | ||
// The cursor position is shifted to the right by 1 | ||
const pos = docB.getCursorPos(cursorB); | ||
expect(pos.offset).toBe(2); | ||
} | ||
listB.insert(1, "Bar"); | ||
expect(docB.toJson()).toStrictEqual({ list: ["Foo", "Bar", "Hello", "World"] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: ["Foo", "Bar", "Hello", "World"] }); | ||
{ | ||
// The cursor position is shifted to the right by 1 | ||
const pos = docB.getCursorPos(cursorB); | ||
expect(pos.offset).toBe(3); | ||
} | ||
listB.delete(3, 1); | ||
expect(docB.toJson()).toStrictEqual({ list: ["Foo", "Bar", "Hello"] }); | ||
expect(docB.toJSON()).toStrictEqual({ list: ["Foo", "Bar", "Hello"] }); | ||
{ | ||
// The position cursor points to is now deleted, | ||
// but it should still get the position | ||
|
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, LoroText } from "npm:loro-crdt@0.15.0"; | ||
import { Loro, LoroText } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("LoroMap", () => { | ||
|
@@ -14,13 +14,13 @@ Deno.test("LoroMap", () => { | |
const textB = mapB.setContainer("a", new LoroText()); | ||
textB.insert(0, "Hi"); | ||
|
||
expect(docA.toJson()).toStrictEqual({ map: { a: 1 } }); | ||
expect(docB.toJson()).toStrictEqual({ map: { a: "Hi" } }); | ||
expect(docA.toJSON()).toStrictEqual({ map: { a: 1 } }); | ||
expect(docB.toJSON()).toStrictEqual({ map: { a: "Hi" } }); | ||
|
||
docA.import(docB.exportSnapshot()); | ||
docB.import(docA.exportSnapshot()); | ||
|
||
expect(docA.toJson()).toStrictEqual({ map: { a: "Hi" } }); | ||
expect(docB.toJson()).toStrictEqual({ map: { a: "Hi" } }); | ||
expect(docA.toJSON()).toStrictEqual({ map: { a: "Hi" } }); | ||
expect(docB.toJSON()).toStrictEqual({ map: { a: "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 { Loro, LoroList, LoroText } from "npm:loro-crdt@0.15.0"; | ||
import { Loro, LoroList, LoroText } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Composition", async () => { | ||
|
@@ -18,7 +18,7 @@ Deno.test("Composition", async () => { | |
// Create a sub container for list | ||
// { map: { list: [0, 1, LoroText] } } | ||
const text = list.insertContainer(2, new LoroText()); | ||
expect(doc.toJson()).toStrictEqual({ map: { list: [0, 1, ""] } }); | ||
expect(doc.toJSON()).toStrictEqual({ map: { list: [0, 1, ""] } }); | ||
{ | ||
// Commit will trigger the event, because list is a sub container of map | ||
doc.commit(); | ||
|
@@ -28,7 +28,7 @@ Deno.test("Composition", async () => { | |
|
||
text.insert(0, "Hello, "); | ||
text.insert(7, "World!"); | ||
expect(doc.toJson()).toStrictEqual({ map: { list: [0, 1, "Hello, World!"] } }); | ||
expect(doc.toJSON()).toStrictEqual({ map: { list: [0, 1, "Hello, World!"] } }); | ||
{ | ||
// Commit will trigger the event, because text is a descendant of map | ||
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Change, Loro, LoroList, LoroText } from "npm:loro-crdt@0.15.0"; | ||
import { Change, Loro, LoroList, LoroText } from "npm:loro-crdt@0.16.4-alpha.0"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("op and change", () => { | ||
|
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,15 @@ | ||
import { Change, Loro, LoroList, LoroText } from "npm:[email protected]"; | ||
import { expect } from "npm:[email protected]"; | ||
|
||
Deno.test("Tree move", () => { | ||
const docA = new Loro(); | ||
|
||
const treeA = docA.getTree("tree"); | ||
const node0 = treeA.createNode() | ||
const node1 = treeA.createNode(node0.id, 0); | ||
const node2 = treeA.createNode(node0.id, 1); | ||
node2.moveBefore(node1); | ||
expect(node2.index()).toBe(0); | ||
expect(node1.index()).toBe(1); | ||
}); | ||
|
Oops, something went wrong.