-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(json-crdt-extensions): ⚡️ speed up range text materialization
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
src/json-crdt-extensions/peritext/rga/__tests__/Range.text.spec.ts
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,32 @@ | ||
import {Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; | ||
|
||
const run = (setup: () => Kit) => { | ||
test('can produce text for all possible ranges', () => { | ||
const {peritext} = setup(); | ||
const length = peritext.strApi().length(); | ||
const str = peritext.strApi().view(); | ||
for (let i = 0; i < length - 1; i++) { | ||
for (let j = 1; j <= length - i - i; j++) { | ||
const range = peritext.rangeAt(i, j); | ||
expect(range.text()).toBe(str.slice(i, i + j)); | ||
// console.log(str.slice(i, i + j)); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
describe('no edits "hello world"', () => { | ||
run(setupHelloWorldKit); | ||
}); | ||
|
||
describe('some edits "hello world"', () => { | ||
run(setupHelloWorldWithFewEditsKit); | ||
}); | ||
|
||
describe('no edits "number"', () => { | ||
run(setupNumbersKit); | ||
}); | ||
|
||
describe('heavy edits "number"', () => { | ||
run(setupNumbersWithTombstonesKit); | ||
}); |