-
Notifications
You must be signed in to change notification settings - Fork 182
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
6 changed files
with
85 additions
and
11 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
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
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
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
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
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,50 @@ | ||
const { create } = require('./helpers') | ||
const test = require('brittle') | ||
const b4a = require('b4a') | ||
|
||
test('draft', async function (t) { | ||
const core = await create(t) | ||
|
||
await core.append('hello') | ||
await core.append('world') | ||
|
||
const draft = core.session({ draft: true }) | ||
|
||
await draft.append('edits!') | ||
|
||
t.alike(await draft.get(0), b4a.from('hello')) | ||
t.alike(await draft.get(1), b4a.from('world')) | ||
t.alike(await draft.get(2), b4a.from('edits!')) | ||
t.alike(await draft.seek(11), [2, 1]) | ||
t.alike(draft.byteLength, 16) | ||
t.alike(draft.length, 3) | ||
|
||
await draft.close() | ||
|
||
// nothing changed as it was a draft | ||
t.alike(core.byteLength, 10) | ||
t.alike(core.length, 2) | ||
|
||
await core.close() | ||
}) | ||
|
||
test('draft and then undraft', async function (t) { | ||
const core = await create(t) | ||
|
||
await core.append('hello') | ||
await core.append('world') | ||
|
||
const draft = core.session({ draft: true }) | ||
|
||
await draft.append('edits!') | ||
|
||
await core.core.commit(draft.state) | ||
|
||
await draft.close() | ||
|
||
// nothing changed as it was a draft | ||
t.alike(core.byteLength, 16) | ||
t.alike(core.length, 3) | ||
|
||
await core.close() | ||
}) |