Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | 37x 37x 37x 1549x 37x 1549x 1549x 1549x 1549x 1549x 1549x 1549x 37x 91x 91x 91x 91x 37x 77x 77x 77x 77x 77x 77x 77x 37x 100x 100x 100x 100x 37x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 37x 80x 80x 80x 80x 80x 37x 80x 80x 80x 80x 80x 37x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 37x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 37x 149x 149x 149x 149x 37x 149x 149x 149x 149x 149x 37x 149x 149x 149x 149x 149x 149x 37x 149x 149x 149x 149x 149x 149x 149x 149x 149x 149x 149x 37x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 282x 37x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 37x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x | import {s} from '../../../json-crdt-patch'; import type {Model} from '../../../json-crdt/model'; import type {SchemaToJsonNode} from '../../../json-crdt/schema/types'; import {ModelWithExt, ext} from '../../ModelWithExt'; export type Schema = ReturnType<typeof schema>; export type Kit = ReturnType<typeof setupKit>; const schema = (text: string) => s.obj({ text: ext.peritext.new(text), }); export const setupKit = ( initialText: string = '', edits: (model: Model<SchemaToJsonNode<Schema>>) => void = () => {}, sid?: number, ) => { const model = ModelWithExt.create(schema(initialText), sid); edits(model); const api = model.api; const peritextApi = model.s.text.toExt(); const peritext = peritextApi.txt; const editor = peritextApi.editor; return { schema, model, api, peritextApi, peritext, editor, }; }; export const setupHelloWorldKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'hello world'); Iif (str.view() !== 'hello world') throw new Error('Invalid text'); }); }; export const setupHelloWorldWithFewEditsKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'wworld'); str.ins(0, 'helo '); str.ins(2, 'l'); str.del(7, 1); Iif (str.view() !== 'hello world') throw new Error('Invalid text'); }); }; /** * Creates a Peritext instance with text "0123456789", no edits. */ export const setupNumbersKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, '0123456789'); Iif (str.view() !== '0123456789') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "0123456789", with single-char and * block-wise chunks, as well as with plenty of tombstones. */ export const setupNumbersWithTombstonesKit = (sid?: number): Kit => { return setupKit( '1234', (model) => { const str = model.s.text.toExt().text(); str.ins(0, '234'); str.ins(1, '234'); str.ins(2, '345'); str.ins(3, '456'); str.ins(4, '567'); str.ins(5, '678'); str.ins(6, '789'); str.del(7, 1); str.del(8, 1); str.ins(0, '0'); str.del(1, 4); str.del(2, 1); str.ins(1, '1'); str.del(0, 1); str.ins(0, '0'); str.ins(2, '234'); str.del(4, 7); str.del(4, 2); str.del(7, 3); str.ins(6, '6789'); str.del(7, 2); str.ins(7, '78'); str.del(10, 2); str.del(2, 3); str.ins(2, 'x234'); str.del(2, 1); str.del(10, 3); Iif (str.view() !== '0123456789') throw new Error('Invalid text: ' + str.view()); }, sid, ); }; /** * Creates a Peritext instance with text "0123456789", two RGA chunks. */ export const setupNumbersWithTwoChunksKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, '56789'); str.ins(0, '01234'); Iif (str.view() !== '0123456789') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "0123456789", with RGA chunks split. */ export const setupNumbersWithRgaSplitKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, '012389'); str.ins(4, '4567'); Iif (str.view() !== '0123456789') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "0123456789", with multiple chunks and deletes. */ export const setupNumbersWithMultipleChunksAndDeletesKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, '0'); str.ins(1, '1'); str.ins(2, '2xyz3'); str.del(3, 3); str.ins(4, '4589'); str.ins(6, '67'); str.ins(8, 'cool worlds'); str.del(8, 11); Iif (str.view() !== '0123456789') throw new Error('Invalid text: ' + str.view()); }); }; export const runNumbersKitTestSuite = (runTestSuite: (getKit: () => Kit) => void) => { describe('numbers "0123456789", no edits', () => { runTestSuite(setupNumbersKit); }); describe('numbers "0123456789", with default schema and tombstones', () => { runTestSuite(setupNumbersWithTombstonesKit); }); describe('numbers "0123456789", two RGA chunks', () => { runTestSuite(setupNumbersWithTwoChunksKit); }); describe('numbers "0123456789", with RGA split', () => { runTestSuite(setupNumbersWithRgaSplitKit); }); describe('numbers "0123456789", with multiple deletes', () => { runTestSuite(setupNumbersWithMultipleChunksAndDeletesKit); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz", no edits. */ export const setupAlphabetKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'abcdefghijklmnopqrstuvwxyz'); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz", two text chunks. */ export const setupAlphabetWithTwoChunksKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'lmnopqrstuvwxyz'); str.ins(0, 'abcdefghijk'); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz", with RGA chunks split. */ export const setupAlphabetChunkSplitKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'lmnwxyz'); str.ins(3, 'opqrstuv'); str.ins(0, 'abcdefghijk'); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz", with RGA deletes. */ export const setupAlphabetWithDeletesKit = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'lmXXXnwYxyz'); str.del(2, 3); str.ins(3, 'opqrstuv'); str.del(12, 1); str.ins(0, 'ab1c3defghijk4444'); str.del(2, 1); str.del(3, 1); str.del(11, 4); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz" written in * reverse. */ export const setupAlphabetWrittenInReverse = (): Kit => { return setupKit('', (model) => { const str = model.s.text.toExt().text(); str.ins(0, 'z'); str.ins(0, 'y'); str.ins(0, 'x'); str.ins(0, 'w'); str.ins(0, 'v'); str.ins(0, 'u'); str.ins(0, 't'); str.ins(0, 's'); str.ins(0, 'r'); str.ins(0, 'q'); str.ins(0, 'p'); str.ins(0, 'o'); str.ins(0, 'n'); str.ins(0, 'm'); str.ins(0, 'l'); str.ins(0, 'k'); str.ins(0, 'j'); str.ins(0, 'i'); str.ins(0, 'h'); str.ins(0, 'g'); str.ins(0, 'f'); str.ins(0, 'e'); str.ins(0, 'd'); str.ins(0, 'c'); str.ins(0, 'b'); str.ins(0, 'a'); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); }); }; /** * Creates a Peritext instance with text "abcdefghijklmnopqrstuvwxyz" written in * reverse and contains deletes. */ export const setupAlphabetWrittenInReverseWithDeletes = (): Kit => { const kit = setupAlphabetWrittenInReverse(); const str = kit.model.s.text.toExt().text(); str.ins(0, '123'); str.del(0, 3); str.ins(3, '1'); str.del(3, 1); str.del(2, 2); str.ins(2, 'cd'); str.del(3, 5); str.ins(3, 'defgh'); str.del(7, 8); str.ins(7, 'hijklmno'); Iif (str.view() !== 'abcdefghijklmnopqrstuvwxyz') throw new Error('Invalid text: ' + str.view()); return kit; }; export const runAlphabetKitTestSuite = (runTestSuite: (getKit: () => Kit) => void) => { describe('basic alphabet', () => { runTestSuite(setupAlphabetKit); }); describe('alphabet with two chunks', () => { runTestSuite(setupAlphabetWithTwoChunksKit); }); describe('alphabet with chunk split', () => { runTestSuite(setupAlphabetChunkSplitKit); }); describe('alphabet with deletes', () => { runTestSuite(setupAlphabetWithDeletesKit); }); describe('alphabet written in reverse', () => { runTestSuite(setupAlphabetWrittenInReverse); }); describe('alphabet written in reverse with deletes', () => { runTestSuite(setupAlphabetWrittenInReverseWithDeletes); }); }; |