r100741 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100740‎ | r100741 | r100742 >
Date:20:42, 25 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed logic for set/clear and invert and use of name instead of key in attribute processing and added tests for attribute changes.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
@@ -502,11 +502,43 @@
503503 test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 6, function() {
504504 var documentModel = es.DocumentModel.newFromPlainObject( obj );
505505
 506+ var elementAttributeChange = documentModel.prepareElementAttributeChange(
 507+ 0, 'set', 'test', 1
 508+ );
 509+
 510+ // Test 1
 511+ documentModel.commit( elementAttributeChange );
 512+ deepEqual(
 513+ documentModel.getData( new es.Range( 0, 5 ) ),
 514+ [
 515+ { 'type': 'paragraph', 'attributes': { 'test': 1 } },
 516+ 'a',
 517+ ['b', { 'type': 'bold', 'hash': '#bold' }],
 518+ ['c', { 'type': 'italic', 'hash': '#italic' }],
 519+ { 'type': '/paragraph' }
 520+ ],
 521+ 'commit applies an element attribute change transaction to the content'
 522+ );
 523+
 524+ // Test 2
 525+ documentModel.rollback( elementAttributeChange );
 526+ deepEqual(
 527+ documentModel.getData( new es.Range( 0, 5 ) ),
 528+ [
 529+ { 'type': 'paragraph' },
 530+ 'a',
 531+ ['b', { 'type': 'bold', 'hash': '#bold' }],
 532+ ['c', { 'type': 'italic', 'hash': '#italic' }],
 533+ { 'type': '/paragraph' }
 534+ ],
 535+ 'rollback reverses the effect of an element attribute change transaction on the content'
 536+ );
 537+
506538 var contentAnnotation = documentModel.prepareContentAnnotation(
507539 new es.Range( 1, 4 ), 'set', { 'type': 'bold' }
508540 );
509541
510 - // Test 1
 542+ // Test 3
511543 documentModel.commit( contentAnnotation );
512544 deepEqual(
513545 documentModel.getData( new es.Range( 0, 5 ) ),
@@ -520,7 +552,7 @@
521553 'commit applies a content annotation transaction to the content'
522554 );
523555
524 - // Test 2
 556+ // Test 4
525557 documentModel.rollback( contentAnnotation );
526558 deepEqual(
527559 documentModel.getData( new es.Range( 0, 5 ) ),
@@ -536,7 +568,7 @@
537569
538570 var insertion = documentModel.prepareInsertion( 4, ['d'] );
539571
540 - // Test 3
 572+ // Test 5
541573 documentModel.commit( insertion );
542574 deepEqual(
543575 documentModel.getData( new es.Range( 0, 6 ) ),
@@ -551,7 +583,7 @@
552584 'commit applies an insertion transaction to the content'
553585 );
554586
555 - // Test 4
 587+ // Test 6
556588 documentModel.rollback( insertion );
557589 deepEqual(
558590 documentModel.getData( new es.Range( 0, 5 ) ),
@@ -567,7 +599,7 @@
568600
569601 var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) );
570602
571 - // Test 5
 603+ // Test 7
572604 documentModel.commit( removal );
573605 deepEqual(
574606 documentModel.getData( new es.Range( 0, 3 ) ),
@@ -579,7 +611,7 @@
580612 'commit applies a removal transaction to the content'
581613 );
582614
583 - // Test 6
 615+ // Test 8
584616 documentModel.rollback( removal );
585617 deepEqual(
586618 documentModel.getData( new es.Range( 0, 5 ) ),
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -93,15 +93,15 @@
9494 if ( element.type === undefined ) {
9595 throw 'Invalid element error. Can not set attributes on non-element data.';
9696 }
97 - if ( op.method === 'set' || ( op.method === 'clear' && invert ) ) {
 97+ if ( ( op.method === 'set' && !invert ) || ( op.method === 'clear' && invert ) ) {
9898 // Automatically initialize attributes object
9999 if ( !element.attributes ) {
100100 element.attributes = {};
101101 }
102 - element.attributes[op.name] = op.value;
103 - } else if ( op.method === 'clear' || ( op.method === 'set' && invert ) ) {
 102+ element.attributes[op.key] = op.value;
 103+ } else if ( ( op.method === 'clear' && !invert ) || ( op.method === 'set' && invert ) ) {
104104 if ( element.attributes ) {
105 - delete element.attributes[op.name];
 105+ delete element.attributes[op.key];
106106 }
107107 // Automatically clean up attributes object
108108 var empty = true;

Status & tagging log