r100606 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100605‎ | r100606 | r100607 >
Date:16:09, 24 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed some syntax errors and commented out debugger statements
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
@@ -204,10 +204,13 @@
205205 test( 'es.DocumentModel', 23, function() {
206206 var documentModel = es.DocumentModel.newFromPlainObject( obj );
207207
 208+ // Test 1
208209 deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' );
209 -
 210+
 211+ // Test 2
210212 deepEqual( documentModel.slice( 0 ), tree, 'Nodes in the model tree contain correct lengths' );
211213
 214+ // Test 3
212215 deepEqual(
213216 documentModel[0].getContent( new es.Range( 1, 3 ) ),
214217 [
@@ -216,13 +219,15 @@
217220 ],
218221 'getContent can return an ending portion of the content'
219222 );
220 -
 223+
 224+ // Test 4
221225 deepEqual(
222226 documentModel[0].getContent( new es.Range( 0, 2 ) ),
223227 ['a', ['b', { 'type': 'bold', 'hash': '#bold' }]],
224228 'getContent can return a beginning portion of the content'
225229 );
226230
 231+ // Test 5
227232 deepEqual(
228233 documentModel[0].getContent( new es.Range( 1, 2 ) ),
229234 [['b', { 'type': 'bold', 'hash': '#bold' }]],
@@ -232,15 +237,18 @@
233238 try {
234239 documentModel[0].getContent( new es.Range( -1, 3 ) );
235240 } catch ( negativeIndexError ) {
 241+ // Test 6
236242 ok( true, 'getContent throws exceptions when given a range with start < 0' );
237243 }
238244
239245 try {
240246 documentModel[0].getContent( new es.Range( 0, 4 ) );
241247 } catch ( outOfRangeError ) {
 248+ // Test 7
242249 ok( true, 'getContent throws exceptions when given a range with end > length' );
243250 }
244251
 252+ // Test 8
245253 deepEqual( documentModel[2].getContent(), ['a'], 'Content can be extracted from nodes' );
246254
247255 var bold = { 'type': 'bold', 'hash': '#bold' },
@@ -248,24 +256,28 @@
249257 nothing = { 'type': 'nothing', 'hash': '#nothing' },
250258 character = ['a', bold, italic];
251259
 260+ // Test 9
252261 equal(
253262 es.DocumentModel.getIndexOfAnnotation( character, bold ),
254263 1,
255264 'getIndexOfAnnotation get the correct index'
256265 );
257266
 267+ // Test 10
258268 equal(
259269 es.DocumentModel.getIndexOfAnnotation( character, italic ),
260270 2,
261271 'getIndexOfAnnotation get the correct index'
262272 );
263273
 274+ // Test 11
264275 equal(
265276 es.DocumentModel.getIndexOfAnnotation( character, nothing ),
266277 -1,
267278 'getIndexOfAnnotation returns -1 if the annotation was not found'
268279 );
269280
 281+ // Test 12
270282 deepEqual(
271283 documentModel.prepareElementAttributeChange( 0, 'set', 'test', 1234 ),
272284 [
@@ -275,6 +287,7 @@
276288 'prepareElementAttributeChange retains data after attribute change for first element'
277289 );
278290
 291+ // Test 13
279292 deepEqual(
280293 documentModel.prepareElementAttributeChange( 5, 'set', 'test', 1234 ),
281294 [
@@ -288,6 +301,7 @@
289302 try {
290303 documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 );
291304 } catch ( invalidOffsetError ) {
 305+ // Test 14
292306 ok(
293307 true,
294308 'prepareElementAttributeChange throws an exception when offset is not an element'
@@ -297,12 +311,14 @@
298312 try {
299313 documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 );
300314 } catch ( closingElementError ) {
 315+ // Test 15
301316 ok(
302317 true,
303318 'prepareElementAttributeChange throws an exception when offset is a closing element'
304319 );
305320 }
306321
 322+ // Test 16
307323 deepEqual(
308324 documentModel.prepareContentAnnotation( new es.Range( 1, 4 ), 'set', { 'type': 'bold' } ),
309325 [
@@ -339,6 +355,7 @@
340356 'prepareContentAnnotation skips over content that is already set or cleared'
341357 );
342358
 359+ // Test 17
343360 deepEqual(
344361 documentModel.prepareRemoval( new es.Range( 1, 4 ) ),
345362 [
@@ -356,6 +373,7 @@
357374 'prepareRemoval includes the content being removed'
358375 );
359376
 377+ // Test 18
360378 deepEqual(
361379 documentModel.prepareRemoval( new es.Range( 15, 18 ) ),
362380 [
@@ -373,6 +391,7 @@
374392 'prepareRemoval removes entire elements'
375393 );
376394
 395+ // Test 19
377396 deepEqual(
378397 documentModel.prepareRemoval( new es.Range( 17, 19 ) ),
379398 [
@@ -389,6 +408,7 @@
390409 'prepareRemoval merges two list items'
391410 );
392411
 412+ // Test 20
393413 deepEqual(
394414 documentModel.prepareInsertion( 1, ['d', 'e', 'f'] ),
395415 [
@@ -399,6 +419,7 @@
400420 'prepareInsertion retains data up to the offset and includes the content being inserted'
401421 );
402422
 423+ // Test 21
403424 deepEqual(
404425 documentModel.prepareInsertion(
405426 5,
@@ -415,6 +436,7 @@
416437 'prepareInsertion inserts a paragraph between two structural elements'
417438 );
418439
 440+ // Test 22
419441 deepEqual(
420442 documentModel.prepareInsertion(
421443 5,
@@ -431,6 +453,7 @@
432454 'prepareInsertion wraps unstructured content inserted between elements in a paragraph'
433455 );
434456
 457+ // Test 23
435458 deepEqual(
436459 documentModel.prepareInsertion(
437460 5,
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -502,7 +502,8 @@
503503 nodeLength = this[i].getElementLength();
504504 if ( offset >= nodeOffset && offset < nodeOffset + nodeLength ) {
505505 return this[i].length ?
506 - es.DocumentModel.prototype.getNode.call( this[i], offset - nodeOffset ) : this[i];
 506+ es.DocumentModel.prototype.getNodeFromOffset.call( this[i], offset - nodeOffset ) :
 507+ this[i];
507508 }
508509 nodeOffset += nodeLength;
509510 }
@@ -614,7 +615,7 @@
615616 */
616617 es.DocumentModel.prototype.prepareRemoval = function( range ) {
617618 var doc = this;
618 - debugger;
 619+ //debugger;
619620
620621 /**
621622 * Return true if can merge the remaining contents of the elements after a selection is deleted across them.
@@ -634,11 +635,9 @@
635636 // wait, some nodes don't have types? Is this the top document node?
636637 return (
637638 (
638 - ( node1.type !== undefined && node2.type !== undefined )
639 - &&
 639+ ( node1.type !== undefined && node2.type !== undefined ) &&
640640 ( node1.type === node2.type )
641 - )
642 - &&
 641+ ) &&
643642 ( node1.getParent() === node2.getParent() )
644643 );
645644 }
@@ -653,13 +652,14 @@
654653 function stripDelete( range, tx ) {
655654 var lastOperation, operationStart;
656655
657 - var ops = [];
658 - debugger;
 656+ var ops = [],
 657+ op;
 658+ //debugger;
659659
660660 // get a list of operations, with 0-based indexes
661661 for (var i = range.start; i < range.end; i++ ) {
662662 var neededOp = doc.data[i].type === undefined ? 'remove' : 'retain';
663 - var op = ops[ ops.length - 1 ];
 663+ op = ops[ ops.length - 1 ];
664664 if ( op === undefined || op.type !== neededOp ) {
665665 ops.push( { type: neededOp, start: i, end: i } );
666666 } else {
@@ -667,10 +667,10 @@
668668 }
669669 }
670670
671 - debugger;
 671+ //debugger;
672672 // insert operations as transactions (end must be adjusted)
673673 for (var j = 0; j < ops.length; j++ ) {
674 - var op = ops[j];
 674+ op = ops[j];
675675 if ( op.type === 'retain' ) {
676676 // we add one because retain(3,3) really means retain 1 char at pos 3
677677 tx.pushRetain( op.end - op.start + 1 );

Status & tagging log