-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
1 changed file
with
29 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
import * as Y from '../src/internals' | ||
import * as t from 'lib0/testing.js' | ||
|
||
/** | ||
* @param {t.TestCase} tc | ||
*/ | ||
export const testRelativePosition = tc => { | ||
const ydoc = new Y.Doc() | ||
const ytext = ydoc.getText() | ||
ytext.insert(0, '1') | ||
ytext.insert(0, 'abc') | ||
ytext.insert(0, 'z') | ||
ytext.insert(0, 'y') | ||
ytext.insert(0, 'x') | ||
|
||
// test if all positions are encoded and restored correctly | ||
for (let i = 0; i < ytext.length; i++) { | ||
// for all types of associations.. | ||
for (let assoc = -1; assoc < 2; assoc++) { | ||
const rpos = Y.createRelativePositionFromTypeIndex(ytext, i, assoc) | ||
const encodedRpos = Y.encodeRelativePosition(rpos) | ||
const decodedRpos = Y.decodeRelativePosition(encodedRpos) | ||
const absPos = /** @type {Y.AbsolutePosition} */ (Y.createAbsolutePositionFromRelativePosition(decodedRpos, ydoc)) | ||
t.assert(absPos.index === i) | ||
t.assert(absPos.assoc === assoc) | ||
} | ||
} | ||
} |