Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -242,17 +242,17 @@ |
243 | 243 | 'getContent can return a middle portion of the content' |
244 | 244 | ); |
245 | 245 | |
| 246 | + // Test 4 |
246 | 247 | try { |
247 | 248 | documentModel[0].getContent( new es.Range( -1, 3 ) ); |
248 | 249 | } catch ( negativeIndexError ) { |
249 | | - // Test 4 |
250 | 250 | ok( true, 'getContent throws exceptions when given a range with start < 0' ); |
251 | 251 | } |
252 | 252 | |
| 253 | + // Test 5 |
253 | 254 | try { |
254 | 255 | documentModel[0].getContent( new es.Range( 0, 4 ) ); |
255 | 256 | } catch ( outOfRangeError ) { |
256 | | - // Test 5 |
257 | 257 | ok( true, 'getContent throws exceptions when given a range with end > length' ); |
258 | 258 | } |
259 | 259 | |
— | — | @@ -314,20 +314,20 @@ |
315 | 315 | 'prepareElementAttributeChange retains data before and after attribute change' |
316 | 316 | ); |
317 | 317 | |
| 318 | + // Test 3 |
318 | 319 | try { |
319 | 320 | documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 ); |
320 | 321 | } catch ( invalidOffsetError ) { |
321 | | - // Test 3 |
322 | 322 | ok( |
323 | 323 | true, |
324 | 324 | 'prepareElementAttributeChange throws an exception when offset is not an element' |
325 | 325 | ); |
326 | 326 | } |
327 | 327 | |
| 328 | + // Test 4 |
328 | 329 | try { |
329 | 330 | documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 ); |
330 | 331 | } catch ( closingElementError ) { |
331 | | - // Test 4 |
332 | 332 | ok( |
333 | 333 | true, |
334 | 334 | 'prepareElementAttributeChange throws an exception when offset is a closing element' |
— | — | @@ -499,12 +499,13 @@ |
500 | 500 | ); |
501 | 501 | } ); |
502 | 502 | |
503 | | -test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 2, function() { |
| 503 | +test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 4, function() { |
504 | 504 | var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
505 | 505 | |
506 | | - var tx = documentModel.prepareInsertion( 4, ['d'] ); |
507 | | - documentModel.commit( tx ); |
| 506 | + var insertion = documentModel.prepareInsertion( 4, ['d'] ); |
508 | 507 | |
| 508 | + // Test 1 |
| 509 | + documentModel.commit( insertion ); |
509 | 510 | deepEqual( |
510 | 511 | documentModel.getData( new es.Range( 0, 6 ) ), |
511 | 512 | [ |
— | — | @@ -515,12 +516,40 @@ |
516 | 517 | 'd', |
517 | 518 | { 'type': '/paragraph' } |
518 | 519 | ], |
519 | | - 'commit applies a transaction to the content' |
| 520 | + 'commit applies an insertion transaction to the content' |
520 | 521 | ); |
521 | 522 | |
522 | | - documentModel.rollback( tx ); |
| 523 | + // Test 2 |
| 524 | + documentModel.rollback( insertion ); |
| 525 | + deepEqual( |
| 526 | + documentModel.getData( new es.Range( 0, 5 ) ), |
| 527 | + [ |
| 528 | + { 'type': 'paragraph' }, |
| 529 | + 'a', |
| 530 | + ['b', { 'type': 'bold', 'hash': '#bold' }], |
| 531 | + ['c', { 'type': 'italic', 'hash': '#italic' }], |
| 532 | + { 'type': '/paragraph' } |
| 533 | + ], |
| 534 | + 'rollback reverses the effect of an insertion transaction on the content' |
| 535 | + ); |
523 | 536 | |
| 537 | + var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) ); |
| 538 | + |
| 539 | + // Test 3 |
| 540 | + documentModel.commit( removal ); |
524 | 541 | deepEqual( |
| 542 | + documentModel.getData( new es.Range( 0, 3 ) ), |
| 543 | + [ |
| 544 | + { 'type': 'paragraph' }, |
| 545 | + 'a', |
| 546 | + { 'type': '/paragraph' } |
| 547 | + ], |
| 548 | + 'commit applies a removal transaction to the content' |
| 549 | + ); |
| 550 | + |
| 551 | + // Test 4 |
| 552 | + documentModel.rollback( removal ); |
| 553 | + deepEqual( |
525 | 554 | documentModel.getData( new es.Range( 0, 5 ) ), |
526 | 555 | [ |
527 | 556 | { 'type': 'paragraph' }, |
— | — | @@ -529,6 +558,7 @@ |
530 | 559 | ['c', { 'type': 'italic', 'hash': '#italic' }], |
531 | 560 | { 'type': '/paragraph' } |
532 | 561 | ], |
533 | | - 'rollback reverses the effect of a transaction on the content' |
| 562 | + 'rollback reverses the effect of a removal transaction on the content' |
534 | 563 | ); |
| 564 | + |
535 | 565 | } ); |