http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99130
Revision: 99130 Author: tparscal Date: 2011-10-06 19:08:37 +0000 (Thu, 06 Oct 2011) Log Message: ----------- Added tests for getIndexOfAnnotation, and fixed a bug in it Modified Paths: -------------- trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js Modified: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js =================================================================== --- trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js 2011-10-06 18:54:19 UTC (rev 99129) +++ trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js 2011-10-06 19:08:37 UTC (rev 99130) @@ -264,10 +264,9 @@ es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) { if ( $.isArray( character ) ) { // Find the index of a comparable annotation (checking for same value, not reference) - var index; - for ( var i = 0; i < character.length; i++ ) { - if ( character[i].hash === op.annotation.hash ) { - return index; + for ( var i = 1; i < character.length; i++ ) { + if ( character[i].hash === annotation.hash ) { + return i; } } } Modified: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js =================================================================== --- trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js 2011-10-06 18:54:19 UTC (rev 99129) +++ trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js 2011-10-06 19:08:37 UTC (rev 99130) @@ -201,11 +201,13 @@ new es.ParagraphModel( data[25], 1 ) ]; -test( 'es.DocumentModel', 8, function() { +test( 'es.DocumentModel', 11, function() { var documentModel = es.DocumentModel.newFromPlainObject( obj ); deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' ); + deepEqual( documentModel.slice( 0 ), tree, 'Nodes contain correct lengths' ); + deepEqual( documentModel[0].getContent( new es.Range( 1, 3 ) ), [ @@ -214,6 +216,7 @@ ], 'When getting content for a node, ranges can trim left' ); + deepEqual( documentModel[0].getContent( new es.Range( 0, 2 ) ), [ @@ -222,6 +225,7 @@ ], 'When getting content for a node, ranges can trim right' ); + deepEqual( documentModel[0].getContent( new es.Range( 1, 2 ) ), [ @@ -229,6 +233,7 @@ ], 'When getting content for a node, ranges can trim left and right' ); + try { documentModel[0].getContent( new es.Range( -1, 3 ) ); } catch ( err ) { @@ -237,6 +242,7 @@ 'Exceptions are thrown when getting node content within a range starting before 0' ); } + try { documentModel[0].getContent( new es.Range( 0, 4 ) ); } catch ( err ) { @@ -245,5 +251,17 @@ 'Exceptions are thrown when getting node content within a range ending after length' ); } + deepEqual( documentModel[2].getContent(), ['a'], 'Content can be extracted from nodes' ); + + var bold = { 'type': 'bold', 'hash': '#bold' }, + italic = { 'type': 'italic', 'hash': '#italic' }, + nothing = { 'type': 'nothing', 'hash': '#nothing' }, + character = ['a', bold, italic]; + + equal( es.DocumentModel.getIndexOfAnnotation( character, bold ), 1 ); + + equal( es.DocumentModel.getIndexOfAnnotation( character, italic ), 2 ); + + equal( es.DocumentModel.getIndexOfAnnotation( character, nothing ), -1 ); } ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs