r99130 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99129‎ | r99130 | r99131 >
Date:19:08, 6 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added tests for getIndexOfAnnotation, and fixed a bug in it
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
@@ -201,11 +201,13 @@
202202 new es.ParagraphModel( data[25], 1 )
203203 ];
204204
205 -test( 'es.DocumentModel', 8, function() {
 205+test( 'es.DocumentModel', 11, function() {
206206 var documentModel = es.DocumentModel.newFromPlainObject( obj );
207207
208208 deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' );
 209+
209210 deepEqual( documentModel.slice( 0 ), tree, 'Nodes contain correct lengths' );
 211+
210212 deepEqual(
211213 documentModel[0].getContent( new es.Range( 1, 3 ) ),
212214 [
@@ -214,6 +216,7 @@
215217 ],
216218 'When getting content for a node, ranges can trim left'
217219 );
 220+
218221 deepEqual(
219222 documentModel[0].getContent( new es.Range( 0, 2 ) ),
220223 [
@@ -222,6 +225,7 @@
223226 ],
224227 'When getting content for a node, ranges can trim right'
225228 );
 229+
226230 deepEqual(
227231 documentModel[0].getContent( new es.Range( 1, 2 ) ),
228232 [
@@ -229,6 +233,7 @@
230234 ],
231235 'When getting content for a node, ranges can trim left and right'
232236 );
 237+
233238 try {
234239 documentModel[0].getContent( new es.Range( -1, 3 ) );
235240 } catch ( err ) {
@@ -237,6 +242,7 @@
238243 'Exceptions are thrown when getting node content within a range starting before 0'
239244 );
240245 }
 246+
241247 try {
242248 documentModel[0].getContent( new es.Range( 0, 4 ) );
243249 } catch ( err ) {
@@ -245,5 +251,17 @@
246252 'Exceptions are thrown when getting node content within a range ending after length'
247253 );
248254 }
 255+
249256 deepEqual( documentModel[2].getContent(), ['a'], 'Content can be extracted from nodes' );
 257+
 258+ var bold = { 'type': 'bold', 'hash': '#bold' },
 259+ italic = { 'type': 'italic', 'hash': '#italic' },
 260+ nothing = { 'type': 'nothing', 'hash': '#nothing' },
 261+ character = ['a', bold, italic];
 262+
 263+ equal( es.DocumentModel.getIndexOfAnnotation( character, bold ), 1 );
 264+
 265+ equal( es.DocumentModel.getIndexOfAnnotation( character, italic ), 2 );
 266+
 267+ equal( es.DocumentModel.getIndexOfAnnotation( character, nothing ), -1 );
250268 } );
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -264,10 +264,9 @@
265265 es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) {
266266 if ( $.isArray( character ) ) {
267267 // Find the index of a comparable annotation (checking for same value, not reference)
268 - var index;
269 - for ( var i = 0; i < character.length; i++ ) {
270 - if ( character[i].hash === op.annotation.hash ) {
271 - return index;
 268+ for ( var i = 1; i < character.length; i++ ) {
 269+ if ( character[i].hash === annotation.hash ) {
 270+ return i;
272271 }
273272 }
274273 }

Status & tagging log