Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/dm/ve.dm.Change.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel Change tests.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 QUnit.module( 've.dm.Change' );
8
9 QUnit.test( 'rebaseTransactions', ( assert ) => {
10 const doc = ve.dm.example.createExampleDocument(),
11 bold = ve.dm.example.createAnnotation( ve.dm.example.bold ),
12 replace12 = ve.dm.TransactionBuilder.static.newFromReplacement( doc, new ve.Range( 1, 2 ), [ ...'Foo' ] ),
13 replace23 = ve.dm.TransactionBuilder.static.newFromReplacement( doc, new ve.Range( 2, 3 ), [ ...'Bar' ] ),
14 replace13 = ve.dm.TransactionBuilder.static.newFromReplacement( doc, new ve.Range( 1, 3 ), [ ...'Baz' ] ),
15 replace24 = ve.dm.TransactionBuilder.static.newFromReplacement( doc, new ve.Range( 2, 4 ), [ ...'qux' ] ),
16 insert1X = ve.dm.TransactionBuilder.static.newFromInsertion( doc, 1, [ 'x' ] ),
17 insert1Y = ve.dm.TransactionBuilder.static.newFromInsertion( doc, 1, [ 'y' ] ),
18 annotate12 = ve.dm.TransactionBuilder.static.newFromAnnotation( doc, new ve.Range( 1, 2 ), 'set', bold ),
19 rebasedOnto = function ( tx1, tx2 ) {
20 return ve.dm.Change.static.rebaseTransactions( tx1, tx2 )[ 0 ];
21 };
22 assert.deepEqual( rebasedOnto( replace23, replace12 ).operations, [
23 {
24 type: 'retain',
25 length: 4
26 },
27 {
28 type: 'replace',
29 remove: [ [ 'b', [ ve.dm.example.boldHash ] ] ],
30 insert: [ ...'Bar' ]
31 },
32 {
33 type: 'retain',
34 length: 60
35 }
36 ], 'Rebase onto upwind replace' );
37
38 assert.deepEqual( rebasedOnto( replace12, replace23 ).operations, [
39 {
40 type: 'retain',
41 length: 1
42 },
43 {
44 type: 'replace',
45 remove: [ 'a' ],
46 insert: [ ...'Foo' ]
47 },
48 {
49 type: 'retain',
50 length: 63
51 }
52 ], 'Rebase onto downwind replace' );
53
54 assert.deepEqual( rebasedOnto( replace12, replace23 ).operations, [
55 {
56 type: 'retain',
57 length: 1
58 },
59 {
60 type: 'replace',
61 remove: [ 'a' ],
62 insert: [ ...'Foo' ]
63 },
64 {
65 type: 'retain',
66 length: 63
67 }
68 ], 'Rebase onto downwind replace' );
69
70 assert.deepEqual( rebasedOnto( replace24, annotate12 ).operations, replace24.operations, 'Rebase onto upwind annotate' );
71
72 assert.strictEqual( rebasedOnto( replace12, annotate12 ), null, 'Rebase conflict with overlapping annotate' );
73 assert.strictEqual( rebasedOnto( replace12, replace13 ), null, 'Rebase conflict with surrounding replace' );
74 assert.strictEqual( rebasedOnto( replace13, replace12 ), null, 'Rebase conflict with surrounded replace' );
75 assert.strictEqual( rebasedOnto( replace13, replace24 ), null, 'Rebase conflict with overlapping downwind replace' );
76 assert.strictEqual( rebasedOnto( replace24, replace13 ), null, 'Rebase conflict with overlapping upwind replace' );
77
78 assert.deepEqual(
79 rebasedOnto( rebasedOnto( replace12, replace23 ), replace23.reversed() ).operations,
80 replace12.operations,
81 'Inverse rebase'
82 );
83
84 const rebased = ve.dm.Change.static.rebaseTransactions( insert1X, insert1Y );
85 assert.deepEqual( rebased[ 0 ].operations, [
86 {
87 type: 'retain',
88 length: 1
89 },
90 {
91 type: 'replace',
92 remove: [],
93 insert: [ 'x' ]
94 },
95 {
96 type: 'retain',
97 length: 63
98 }
99 ], 'Rebase-startmost insert onto parallel insert at the same offset' );
100
101 assert.deepEqual( rebased[ 1 ].operations, [
102 {
103 type: 'retain',
104 length: 2
105 },
106 {
107 type: 'replace',
108 remove: [],
109 insert: [ 'y' ]
110 },
111 {
112 type: 'retain',
113 length: 62
114 }
115 ], 'Rebase-endmost insert onto parallel insert at the same offset' );
116 } );
117
118 QUnit.test( 'Change operations', ( assert ) => {
119 const origData = [ { type: 'paragraph' }, ...'three', { type: '/paragraph' } ],
120 newSurface = function () {
121 return new ve.dm.Surface(
122 ve.dm.example.createExampleDocumentFromData( origData )
123 );
124 };
125 let surface = newSurface();
126 const emptyStore = new ve.dm.HashValueStore(),
127 doc = surface.documentModel,
128 b = ve.dm.example.bold,
129 i = ve.dm.example.italic,
130 u = ve.dm.example.underline,
131 bHash = [ ve.dm.example.boldHash ],
132 iHash = [ ve.dm.example.italicHash ],
133 uHash = [ ve.dm.example.underlineHash ],
134 TxInsert = ve.dm.TransactionBuilder.static.newFromInsertion,
135 TxReplace = ve.dm.TransactionBuilder.static.newFromReplacement,
136 TxRemove = ve.dm.TransactionBuilder.static.newFromRemoval,
137 TxAnnotate = ve.dm.TransactionBuilder.static.newFromAnnotation,
138 insert1 = new ve.dm.Change( 0, [
139 TxInsert( doc, 1, [ [ 'o', bHash ] ] ),
140 TxInsert( doc, 2, [ [ 'n', bHash ] ] ),
141 TxInsert( doc, 3, [ [ 'e', bHash ] ] ),
142 TxInsert( doc, 4, [ ' ' ] )
143 ], [ new ve.dm.HashValueStore( [ b ] ), emptyStore, emptyStore, emptyStore ], {
144 1: new ve.dm.LinearSelection( new ve.Range( 7, 7 ) )
145 } ),
146 insert2 = new ve.dm.Change( 0, [
147 TxInsert( doc, 1, [ [ 't', iHash ] ] ),
148 TxInsert( doc, 2, [ [ 'w', iHash ] ] ),
149 TxInsert( doc, 3, [ [ 'o', iHash ] ] ),
150 TxInsert( doc, 4, [ ' ' ] )
151 ], [ new ve.dm.HashValueStore( [ i ] ), emptyStore, emptyStore, emptyStore ], {
152 2: new ve.dm.LinearSelection( new ve.Range( 1, 1 ) )
153 } ),
154 underline3 = new ve.dm.Change( 0, [
155 TxAnnotate( doc, new ve.Range( 1, 6 ), 'set', u )
156 ], [ new ve.dm.HashValueStore( [ u ] ) ], {} );
157
158 insert2.applyTo( surface );
159 assert.deepEqual(
160 doc.data.data.slice( 1, -1 ),
161 [ [ 't', iHash ], [ 'w', iHash ], [ 'o', iHash ], ...' three' ],
162 'Apply insert2'
163 );
164
165 const replace2 = new ve.dm.Change( 4, [
166 TxReplace( doc, new ve.Range( 1, 4 ), [ ...'TWO' ] )
167 ], [ emptyStore ], {} );
168
169 const remove2 = new ve.dm.Change( 4, [
170 TxRemove( doc, new ve.Range( 1, 4 ) )
171 ], [ emptyStore ], {} );
172
173 let change = insert2.reversed();
174 assert.strictEqual( change.start, 4, 'start for insert2.reversed()' );
175 change.applyTo( surface );
176 assert.deepEqual( doc.data.data, origData, 'Apply insert2.reversed()' );
177
178 surface = newSurface();
179 change = insert1.concatRebased( insert2 );
180 change.applyTo( surface );
181 assert.deepEqual(
182 surface.documentModel.data.data.slice( 1, -1 ),
183 [
184 [ 'o', bHash ],
185 [ 'n', bHash ],
186 [ 'e', bHash ],
187 ' ',
188 [ 't', iHash ],
189 [ 'w', iHash ],
190 [ 'o', iHash ],
191 ...' three'
192 ],
193 'Apply insert1 then insert2'
194 );
195 change.reversed().applyTo( surface );
196 assert.deepEqual(
197 surface.documentModel.data.data,
198 origData,
199 'Apply (insert1 then insert2) reversed'
200 );
201
202 surface = newSurface();
203 change = insert1.concatRebased( insert2.concat( replace2 ) ).concatRebased( underline3 );
204 change.applyTo( surface );
205 assert.deepEqual(
206 surface.documentModel.data.data.slice( 1, -1 ),
207 [
208 [ 'o', bHash ],
209 [ 'n', bHash ],
210 [ 'e', bHash ],
211 ...' TWO ',
212 [ 't', uHash ],
213 [ 'h', uHash ],
214 [ 'r', uHash ],
215 [ 'e', uHash ],
216 [ 'e', uHash ]
217 ],
218 'Apply insert1 then insert2*replace2 then underline3'
219 );
220 change.reversed().applyTo( surface );
221 assert.deepEqual(
222 doc.data.data,
223 origData,
224 'Apply (insert1 then insert2*replace2 then underline3) reversed'
225 );
226
227 assert.deepEqual(
228 ve.dm.Change.static.rebaseUncommittedChange( remove2, replace2 ).rebased.transactions,
229 [],
230 'Conflict rebasing replace2 onto remove2'
231 );
232
233 assert.equalRange(
234 ve.dm.Change.static.rebaseUncommittedChange( insert1, insert2 ).rebased.selections[ 2 ].range,
235 new ve.Range( 1 ),
236 'Selection before insertion is not adjusted when rebasing (1)'
237 );
238
239 assert.equalRange(
240 ve.dm.Change.static.rebaseUncommittedChange( insert2, insert1 ).transposedHistory.selections[ 2 ].range,
241 new ve.Range( 1 ),
242 'Selection before insertion is not adjusted when rebasing (2)'
243 );
244
245 assert.equalRange(
246 ve.dm.Change.static.rebaseUncommittedChange( insert1, insert2 ).transposedHistory.selections[ 1 ].range,
247 new ve.Range( 11 ),
248 'Selection after insertion is adjusted when rebasing (1)'
249 );
250
251 assert.equalRange(
252 ve.dm.Change.static.rebaseUncommittedChange( insert2, insert1 ).rebased.selections[ 1 ].range,
253 new ve.Range( 11 ),
254 'Selection after insertion is adjusted when rebasing (2)'
255 );
256 } );
257
258 QUnit.test( 'Rebase with conflicting annotations', ( assert ) => {
259 const origData = [ { type: 'paragraph' }, 'A', { type: '/paragraph' } ],
260 newSurface = function () {
261 return new ve.dm.Surface(
262 ve.dm.example.createExampleDocumentFromData( origData )
263 );
264 },
265 surface = newSurface(),
266 doc = surface.documentModel,
267 TxRemove = ve.dm.TransactionBuilder.static.newFromRemoval,
268 TxAnnotate = ve.dm.TransactionBuilder.static.newFromAnnotation,
269 b = ve.dm.example.bold,
270 emptyStore = new ve.dm.HashValueStore(),
271 bStore = new ve.dm.HashValueStore( [ b ] );
272
273 // Canonical history: text gets removed
274 const remove = new ve.dm.Change( 1, [ TxRemove( doc, new ve.Range( 1, 2 ) ) ], [ emptyStore ], {} );
275 // Doomed conflicting history: text gets bolded
276 const setBold = new ve.dm.Change( 1, [ TxAnnotate( doc, new ve.Range( 1, 2 ), 'set', b ) ], [ bStore ], {} );
277 const result = ve.dm.Change.static.rebaseUncommittedChange( remove, setBold );
278 assert.deepEqual(
279 result.rebased.toJSON(),
280 new ve.dm.Change( 2, [], [], {} ).toJSON(),
281 'Nothing got rebased'
282 );
283 assert.deepEqual(
284 result.rejected.toJSON(),
285 setBold.toJSON(),
286 'setBold got rejected'
287 );
288 assert.deepEqual(
289 result.transposedHistory.toJSON(),
290 remove.toJSON(),
291 'remove got transposed'
292 );
293 } );
294
295 QUnit.test( 'toJSON/deserialize/unsafeDeserialize', ( assert ) => {
296 const origData = [ { type: 'paragraph' }, ...'Bar', { type: '/paragraph' } ],
297 newSurface = function () {
298 return new ve.dm.Surface(
299 ve.dm.example.createExampleDocumentFromData( origData )
300 );
301 },
302 surface = newSurface(),
303 emptyStore = new ve.dm.HashValueStore(),
304 doc = surface.documentModel,
305 b = ve.dm.example.bold,
306 bHash = [ ve.dm.example.boldHash ],
307 TxInsert = ve.dm.TransactionBuilder.static.newFromInsertion,
308 change = new ve.dm.Change( 0, [
309 TxInsert( doc, 1, [ [ 'f', bHash ] ] ),
310 // Second insert is too short, as first insert wasn't applied to the doc
311 TxInsert( doc, 2, [ [ 'u', bHash ] ] )
312 ], [ new ve.dm.HashValueStore( [ b ] ), emptyStore ], {} ),
313 simpleChange = new ve.dm.Change( 0, [ TxInsert( doc, 1, [ 'a' ] ) ], [ emptyStore ], {} ),
314 serialized = {
315 start: 0,
316 transactions: [
317 [ 1, [ '', [ [ 'f', bHash ] ] ], 4 ],
318 'u'
319 ],
320 stores: [
321 {
322 hashStore: {
323 h49981eab0f8056ff: {
324 type: 'plain',
325 value: {
326 type: 'textStyle/bold',
327 attributes: { nodeName: 'b' }
328 }
329 }
330 },
331 hashes: bHash
332 },
333 null
334 ]
335 },
336 simpleSerialized = {
337 start: 0,
338 transactions: [ [ 1, [ '', 'a' ], 4 ] ]
339 },
340 unsanitized = {
341 start: 0,
342 transactions: [ { a: 'fred', o: [ 2 ] } ],
343 stores: [ { hashes: [ 'xx' ], hashStore: { xx: {
344 type: 'domNodes',
345 value: '<script></script><p onclick="alert(\'gotcha!\')"></p>'
346 } } } ]
347 },
348 sanitized = {
349 start: 0,
350 transactions: [ { a: 'fred', o: [ 2 ] } ],
351 stores: [ { hashes: [ 'xx' ], hashStore: { xx: {
352 type: 'domNodes',
353 value: '<p></p>'
354 } } } ]
355 };
356
357 // Fixup second insert
358 change.transactions[ 1 ].operations[ 2 ].length += 1;
359
360 assert.deepEqual( change.toJSON(), serialized, 'Serialize' );
361 assert.deepEqual(
362 JSON.parse( JSON.stringify( { change: change } ) ),
363 { change: serialized },
364 'Serialize with JSON.stringify while nested (ensure arguments are no passed to serialize)'
365 );
366
367 assert.deepEqual(
368 ve.dm.Change.static.deserialize( serialized ).toJSON(),
369 serialized,
370 'Deserialize and reserialize'
371 );
372
373 assert.deepEqual(
374 ve.dm.Change.static.deserialize( serialized, true ).getStores().map( ( store ) => store.hashStore ),
375 serialized.stores.map( ( store ) => store ? store.hashStore : {} ),
376 'Deserialize, preserving store values'
377 );
378
379 assert.notDeepEqual(
380 ve.dm.Change.static.deserialize( serialized ).getStores().map( ( store ) => store.hashStore ),
381 serialized.stores.map( ( store ) => store ? store.hashStore : {} ),
382 'Deserialize, not preserving store values'
383 );
384
385 assert.deepEqual(
386 ve.dm.Change.static.deserialize( serialized, true ).serialize( true ),
387 serialized,
388 'Deserialize and reserialize, preserving store values'
389 );
390
391 assert.deepEqual(
392 ve.dm.Change.static.deserialize( unsanitized ).toJSON(),
393 sanitized,
394 'Unsanitized round trips into sanitized'
395 );
396
397 assert.deepEqual(
398 ve.dm.Change.static.unsafeDeserialize( unsanitized ).toJSON(),
399 unsanitized,
400 'Unsanitized round trips into unsanitized in unsafe mode'
401 );
402
403 assert.deepEqual( simpleChange.toJSON(), simpleSerialized, 'Serialize (simple)' );
404
405 assert.deepEqual(
406 ve.dm.Change.static.deserialize( simpleSerialized ).toJSON(),
407 simpleSerialized,
408 'Deserialize and reserialize (simple)'
409 );
410
411 assert.deepEqual(
412 ve.dm.Change.static.deserialize( simpleSerialized, true ).getStores().map( ( store ) => store.hashStore ),
413 [ {} ],
414 'Deserialize, preserving store values (simple)'
415 );
416
417 } );
418
419 QUnit.test( 'Minified serialization', ( assert ) => {
420 const serialized = {
421 start: 0,
422 transactions: [
423 // Type some individual code units
424 [ 1, [ '', 'T' ], 3 ],
425 'h', 'e', ' ', 'r', 'e',
426 // Type in whole words like some IMEs
427 'd panda jumps over', 'the ', 'automaton',
428 // Italicize some text
429 [
430 5,
431 {
432 type: 'annotate',
433 method: 'set',
434 bias: 'start',
435 index: 'he4e7c54e2204d10b'
436 },
437 9,
438 {
439 type: 'annotate',
440 method: 'set',
441 bias: 'stop',
442 index: 'he4e7c54e2204d10b'
443 },
444 28
445 ],
446 // Type over the italicized text
447 [
448 5,
449 [
450 [
451 [ 'r', [ 'he4e7c54e2204d10b' ] ],
452 [ 'e', [ 'he4e7c54e2204d10b' ] ],
453 [ 'd', [ 'he4e7c54e2204d10b' ] ],
454 [ ' ', [ 'he4e7c54e2204d10b' ] ],
455 [ 'p', [ 'he4e7c54e2204d10b' ] ],
456 [ 'a', [ 'he4e7c54e2204d10b' ] ],
457 [ 'n', [ 'he4e7c54e2204d10b' ] ],
458 [ 'd', [ 'he4e7c54e2204d10b' ] ],
459 [ 'a', [ 'he4e7c54e2204d10b' ] ]
460 ],
461 [
462 [ 'q', [ 'he4e7c54e2204d10b' ] ]
463 ]
464 ],
465 28
466 ],
467 'u', 'i', 'c', 'k', ' ', 'bro', 'wn ', 'fox',
468 // Bold some text
469 [
470 36,
471 {
472 type: 'annotate',
473 method: 'set',
474 bias: 'start',
475 index: 'hfbe3cfe099b83e1e'
476 },
477 9,
478 {
479 type: 'annotate',
480 method: 'set',
481 bias: 'stop',
482 index: 'hfbe3cfe099b83e1e'
483 },
484 3
485 ],
486 // Type over the bolded text
487 [
488 36,
489 [
490 [
491 [ 'a', [ 'hfbe3cfe099b83e1e' ] ],
492 [ 'u', [ 'hfbe3cfe099b83e1e' ] ],
493 [ 't', [ 'hfbe3cfe099b83e1e' ] ],
494 [ 'o', [ 'hfbe3cfe099b83e1e' ] ],
495 [ 'm', [ 'hfbe3cfe099b83e1e' ] ],
496 [ 'a', [ 'hfbe3cfe099b83e1e' ] ],
497 [ 't', [ 'hfbe3cfe099b83e1e' ] ],
498 [ 'o', [ 'hfbe3cfe099b83e1e' ] ],
499 [ 'n', [ 'hfbe3cfe099b83e1e' ] ]
500 ],
501 [
502 [ 'l', [ 'hfbe3cfe099b83e1e' ] ]
503 ]
504 ],
505 3
506 ],
507 'a', 'z', 'y', ' ', 'd', 'o', 'g', '.'
508 ],
509 stores: [
510 null, null, null, null, null, null, null, null, null,
511 {
512 hashes: [ 'he4e7c54e2204d10b' ],
513 hashStore: {
514 he4e7c54e2204d10b: {
515 type: 'annotation',
516 value: { type: 'textStyle/italic' }
517 }
518 }
519 },
520 null, null, null, null, null, null, null, null, null,
521 {
522 hashes: [ 'hfbe3cfe099b83e1e' ],
523 hashStore: {
524 hfbe3cfe099b83e1e: {
525 type: 'annotation',
526 value: { type: 'textStyle/bold' }
527 }
528 }
529 },
530 null, null, null, null, null, null, null, null, null
531 ]
532 };
533
534 const deserialized = ve.dm.Change.static.deserialize( serialized );
535 assert.deepEqual(
536 deserialized.toJSON(),
537 serialized,
538 'Deserialize-serialize round trip'
539 );
540 } );
541
542 QUnit.test( 'Same-offset typing', ( assert ) => {
543 const surface = new ve.dm.Surface( ve.dm.example.createExampleDocumentFromData( [
544 { type: 'paragraph' },
545 { type: '/paragraph' },
546 { type: 'internalList' }, { type: '/internalList' }
547 ] ) ),
548 emptyStore = new ve.dm.HashValueStore(),
549 doc = surface.documentModel,
550 saved = doc.completeHistory.toJSON(),
551 clear = function () {
552 doc.getChangeSince( 0 ).reversed().applyTo( surface );
553 doc.completeHistory = ve.dm.Change.static.deserialize( saved );
554 doc.store = doc.completeHistory.store;
555 },
556 TxInsert = ve.dm.TransactionBuilder.static.newFromInsertion;
557
558 // 'ab' and 'cd' typed at the same offset
559 const a = new ve.dm.Change( 0, [ TxInsert( doc, 1, [ 'a' ] ) ], [ emptyStore ], {} );
560 a.transactions[ 0 ].authorId = 1;
561 a.applyTo( surface );
562 const b = new ve.dm.Change( 1, [ TxInsert( doc, 2, [ 'b' ] ) ], [ emptyStore ], {} );
563 b.transactions[ 0 ].authorId = 1;
564 clear();
565 const c = new ve.dm.Change( 0, [ TxInsert( doc, 1, [ 'c' ] ) ], [ emptyStore ], {} );
566 c.transactions[ 0 ].authorId = 2;
567 c.applyTo( surface );
568 const d = new ve.dm.Change( 1, [ TxInsert( doc, 2, [ 'd' ] ) ], [ emptyStore ], {} );
569 d.transactions[ 0 ].authorId = 2;
570 c.reversed().applyTo( surface );
571
572 const cases = [
573 {
574 message: 'a on c',
575 change: a.rebasedOnto( c ),
576 expected: { before: 1, insert: 'a', after: 4 }
577 },
578 {
579 message: 'c on a',
580 change: c.rebasedOnto( a ),
581 expected: { before: 2, insert: 'c', after: 3 }
582 },
583 {
584 message: 'b on ( c on a )',
585 change: b.rebasedOnto( c.rebasedOnto( a ) ),
586 expected: { before: 2, insert: 'b', after: 4 }
587 },
588 {
589 message: 'd on ( a on c )',
590 change: d.rebasedOnto( a.rebasedOnto( c ) ),
591 expected: { before: 3, insert: 'd', after: 3 }
592 },
593 {
594 message: 'b on ( c+d on a )',
595 change: b.rebasedOnto( c.concat( d ).rebasedOnto( a ) ),
596 expected: { before: 2, insert: 'b', after: 5 }
597 },
598 {
599 message: 'd on ( a+b on c )',
600 change: d.rebasedOnto( a.concat( b ).rebasedOnto( c ) ),
601 expected: { before: 4, insert: 'd', after: 3 }
602 }
603 ];
604
605 cases.forEach( ( caseItem ) => {
606 const operations = caseItem.change.transactions[ 0 ].operations;
607 assert.deepEqual( {
608 before: operations[ 0 ].length,
609 insert: operations[ 1 ].insert[ 0 ],
610 after: operations[ 2 ].length
611 }, caseItem.expected, caseItem.message );
612 } );
613
614 // Check that the order of application doesn't matter
615 const expected = [ { type: 'paragraph' }, ...'abcd', { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ];
616
617 clear();
618 surface.setSelection( new ve.dm.LinearSelection( new ve.Range( 1 ) ) );
619 a.applyTo( surface );
620 b.applyTo( surface );
621 c.rebasedOnto( a.concat( b ) ).applyTo( surface );
622 d.rebasedOnto( a.concat( b ).rebasedOnto( c ) ).applyTo( surface );
623 assert.deepEqual( doc.data.data, expected, 'a,b,c,d' );
624 assert.equalRange(
625 surface.getSelection().getRange(),
626 new ve.Range( 1 ),
627 'a,b,c,d range'
628 );
629
630 clear();
631 a.applyTo( surface );
632 c.rebasedOnto( a ).applyTo( surface );
633 b.rebasedOnto( c.rebasedOnto( a ) ).applyTo( surface );
634 d.rebasedOnto( a.concat( b ).rebasedOnto( c ) ).applyTo( surface );
635 assert.deepEqual( doc.data.data, expected, 'a,c,b,d' );
636
637 clear();
638 a.applyTo( surface );
639 c.rebasedOnto( a ).applyTo( surface );
640 d.rebasedOnto( a.rebasedOnto( c ) ).applyTo( surface );
641 b.rebasedOnto( c.concat( d ).rebasedOnto( a ) ).applyTo( surface );
642 assert.deepEqual( doc.data.data, expected, 'a,c,d,b' );
643
644 clear();
645 c.applyTo( surface );
646 a.rebasedOnto( c ).applyTo( surface );
647 d.rebasedOnto( a.rebasedOnto( c ) ).applyTo( surface );
648 b.rebasedOnto( c.concat( d ).rebasedOnto( a ) ).applyTo( surface );
649 assert.deepEqual( doc.data.data, expected, 'c,a,d,b' );
650
651 clear();
652 c.applyTo( surface );
653 d.applyTo( surface );
654 a.rebasedOnto( c.concat( d ) ).applyTo( surface );
655 b.rebasedOnto( c.concat( d ).rebasedOnto( a ) ).applyTo( surface );
656 assert.deepEqual( doc.data.data, expected, 'c,d,a,b' );
657
658 } );