r102607 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102606‎ | r102607 | r102608 >
Date:23:39, 9 November 2011
Author:tparscal
Status:deferred (Comments)
Tags:
Comment:
Updated tests and test data to support listItem nodes being branches instead of leafs
Modified paths:
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.testData.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js
@@ -60,37 +60,62 @@
6161 }
6262 } );
6363
64 -test( 'es.DocumentBranchNode.getNodeFromOffset', 22, function() {
 64+test( 'es.DocumentBranchNode.getNodeFromOffset', 23, function() {
6565 // Tests 1 .. 22
6666 var getNodeFromOffsetTests = [
 67+ // Test 1 - |[<a></a><b> </b><c> </c><d> </d><e> </e>]
6768 { 'input': -1, 'output': null },
68 - { 'input': 0, 'output': a },
 69+ // Test 2 - [|<a></a><b> </b><c> </c><d> </d><e> </e>]
 70+ { 'input': 0, 'output': root1 },
 71+ // Test 3 - [<a>|</a><b> </b><c> </c><d> </d><e> </e>]
6972 { 'input': 1, 'output': a },
70 - { 'input': 2, 'output': b },
 73+ // Test 4 - [<a></a>|<b> </b><c> </c><d> </d><e> </e>]
 74+ { 'input': 2, 'output': root1 },
 75+ // Test 5 - [<a></a><b>| </b><c> </c><d> </d><e> </e>]
7176 { 'input': 3, 'output': b },
 77+ // Test 6 - [<a></a><b> |</b><c> </c><d> </d><e> </e>]
7278 { 'input': 4, 'output': b },
73 - { 'input': 5, 'output': c },
 79+ // Test 7 - [<a></a><b> </b>|<c> </c><d> </d><e> </e>]
 80+ { 'input': 5, 'output': root1 },
 81+ // Test 8 - [<a></a><b> </b><c>| </c><d> </d><e> </e>]
7482 { 'input': 6, 'output': c },
 83+ // Test 9 - [<a></a><b> </b><c> | </c><d> </d><e> </e>]
7584 { 'input': 7, 'output': c },
 85+ // Test 10 - [<a></a><b> </b><c> |</c><d> </d><e> </e>]
7686 { 'input': 8, 'output': c },
77 - { 'input': 9, 'output': d },
 87+ // Test 11 - [<a></a><b> </b><c> </c>|<d> </d><e> </e>]
 88+ { 'input': 9, 'output': root1 },
 89+ // Test 12 - [<a></a><b> </b><c> </c><d>| </d><e> </e>]
7890 { 'input': 10, 'output': d },
 91+ // Test 13 - [<a></a><b> </b><c> </c><d> | </d><e> </e>]
7992 { 'input': 11, 'output': d },
 93+ // Test 14 - [<a></a><b> </b><c> </c><d> | </d><e> </e>]
8094 { 'input': 12, 'output': d },
 95+ // Test 15 - [<a></a><b> </b><c> </c><d> |</d><e> </e>]
8196 { 'input': 13, 'output': d },
82 - { 'input': 14, 'output': e },
 97+ // Test 16 - [<a></a><b> </b><c> </c><d> </d>|<e> </e>]
 98+ { 'input': 14, 'output': root1 },
 99+ // Test 17 - [<a></a><b> </b><c> </c><d> </d><e>| </e>]
83100 { 'input': 15, 'output': e },
 101+ // Test 18 - [<a></a><b> </b><c> </c><d> </d><e> | </e>]
84102 { 'input': 16, 'output': e },
 103+ // Test 19 - [<a></a><b> </b><c> </c><d> </d><e> | </e>]
85104 { 'input': 17, 'output': e },
 105+ // Test 20 - [<a></a><b> </b><c> </c><d> </d><e> | </e>]
86106 { 'input': 18, 'output': e },
 107+ // Test 21 - [<a></a><b> </b><c> </c><d> </d><e> |</e>]
87108 { 'input': 19, 'output': e },
88 - { 'input': 20, 'output': null }
 109+ // Test 22 - [<a></a><b> </b><c> </c><d> </d><e> </e>|]
 110+ { 'input': 20, 'output': root1 },
 111+ // Test 22 - [<a></a><b> </b><c> </c><d> </d><e> </e>]|
 112+ { 'input': 21, 'output': null }
89113 ];
90114 for ( var i = 0; i < getNodeFromOffsetTests.length; i++ ) {
91 - strictEqual(
92 - root1.getNodeFromOffset( getNodeFromOffsetTests[i].input ),
 115+ ok(
 116+ root1.getNodeFromOffset( getNodeFromOffsetTests[i].input ) ===
93117 getNodeFromOffsetTests[i].output,
94 - 'getNodeFromOffset finds the right item or returns null when out of range'
 118+ 'getNodeFromOffset finds the right item or returns null when out of range ' +
 119+ '(' + getNodeFromOffsetTests[i].input + ')'
95120 );
96121 }
97122 } );
@@ -137,109 +162,130 @@
138163 // * past end
139164 var selectNodesTests = [
140165 // Complete set of combinations within the same node:
 166+
 167+ // Test 1
141168 {
142169 'node': root2,
143170 'input': new es.Range( 0, 0 ),
144171 'output': [],
145172 'desc': 'Zero-length range before the beginning of a node'
146173 },
 174+ // Test 2
147175 {
148176 'node': root2,
149177 'input': new es.Range( 0, 1 ),
150178 'output': [{ 'node': f, 'range': new es.Range( 0, 0 ) }],
151179 'desc': 'Range starting before the beginning of a node and ending at the beginning'
152180 },
 181+ // Test 3
153182 {
154183 'node': root2,
155184 'input': new es.Range( 10, 15 ),
156185 'output': [{ 'node': g, 'range': new es.Range( 0, 4 ) }],
157186 'desc': 'Range starting before the beginning of a node and ending in the middle'
158187 },
 188+ // Test 4
159189 {
160190 'node': root2,
161191 'input': new es.Range( 20, 29 ),
162192 'output': [{ 'node': h, 'range': new es.Range( 0, 8 ) }],
163193 'desc': 'Range starting before the beginning of a node and ending at the end'
164194 },
 195+ // Test 5
165196 {
166197 'node': root2,
167198 'input': new es.Range( 0, 10 ),
168199 'output': [{ 'node': f } ],
169200 'desc': 'Range starting before the beginning of a node and ending past the end'
170201 },
 202+ // Test 6
171203 {
172204 'node': root2,
173205 'input': new es.Range( 11, 11 ),
174206 'output': [{ 'node': g, 'range': new es.Range( 0, 0 ) }],
175207 'desc': 'Zero-length range at the beginning of a node'
176208 },
 209+ // Test 7
177210 {
178211 'node': root2,
179212 'input': new es.Range( 21, 26 ),
180213 'output': [{ 'node': h, 'range': new es.Range( 0, 5 ) }],
181214 'desc': 'Range starting at the beginning of a node and ending in the middle'
182215 },
 216+ // Test 8
183217 {
184218 'node': root2,
185219 'input': new es.Range( 1, 9 ),
186220 'output': [{ 'node': f, 'range': new es.Range( 0, 8 ) }],
187221 'desc': 'Range starting at the beginning of a node and ending at the end'
188222 },
 223+ // Test 9
189224 {
190225 'node': root2,
191226 'input': new es.Range( 11, 20 ),
192227 'output': [{ 'node': g, 'range': new es.Range( 0, 8 ) }],
193228 'desc': 'Range starting at the beginning of a node and ending past the end'
194229 },
 230+ // Test 10
195231 {
196232 'node': root2,
197233 'input': new es.Range( 22, 22 ),
198234 'output': [{ 'node': h, 'range': new es.Range( 1, 1 ) }],
199235 'desc': 'Zero-length range in the middle of a node'
200236 },
 237+ // Test 11
201238 {
202239 'node': root2,
203240 'input': new es.Range( 2, 7 ),
204241 'output': [{ 'node': f, 'range': new es.Range( 1, 6 ) }],
205242 'desc': 'Range starting and ending in the middle of the same node'
206243 },
 244+ // Test 12
207245 {
208246 'node': root2,
209247 'input': new es.Range( 13, 19 ),
210248 'output': [{ 'node': g, 'range': new es.Range( 2, 8 ) }],
211249 'desc': 'Range starting in the middle of a node and ending at the end'
212250 },
 251+ // Test 13
213252 {
214253 'node': root2,
215254 'input': new es.Range( 24, 30 ),
216255 'output': [{ 'node': h, 'range': new es.Range( 3, 8 ) }],
217256 'desc': 'Range starting in the middle of a node and ending past the end'
218257 },
 258+ // Test 14
219259 {
220260 'node': root2,
221261 'input': new es.Range( 9, 9 ),
222262 'output': [{ 'node': f, 'range': new es.Range( 8, 8 ) }],
223263 'desc': 'Zero-length range at the end of a node'
224264 },
 265+ // Test 15
225266 {
226267 'node': root2,
227268 'input': new es.Range( 19, 20 ),
228269 'output': [{ 'node': g, 'range': new es.Range( 8, 8 ) }],
229270 'desc': 'Range starting at the end of a node and ending past the end'
230271 },
 272+ // Test 16
231273 {
232274 'node': root2,
233275 'input': new es.Range( 30, 30 ),
234276 'output': [],
235277 'desc': 'Zero-length range past the end of a node'
236278 },
 279+ // Test 17
237280 {
238281 'node': root2,
239282 'input': new es.Range( 20, 20 ),
240283 'output': [],
241284 'desc': 'Zero-length range between two nodes'
242285 },
 286+
243287 // Complete set of combinations for cross-node selections. Generated with help of a script
 288+
 289+ // Test 18
244290 {
245291 'node': root2,
246292 'input': new es.Range( 0, 11 ),
@@ -249,6 +295,7 @@
250296 ],
251297 'desc': 'Range starting before the beginning of the first node and ending at the beginning of the second node'
252298 },
 299+ // Test 19
253300 {
254301 'node': root2,
255302 'input': new es.Range( 0, 14 ),
@@ -258,6 +305,7 @@
259306 ],
260307 'desc': 'Range starting before the beginning of the first node and ending in the middle of the second node'
261308 },
 309+ // Test 20
262310 {
263311 'node': root2,
264312 'input': new es.Range( 0, 19 ),
@@ -267,6 +315,7 @@
268316 ],
269317 'desc': 'Range starting before the beginning of the first node and ending at the end of the second node'
270318 },
 319+ // Test 21
271320 {
272321 'node': root2,
273322 'input': new es.Range( 0, 20 ),
@@ -276,6 +325,7 @@
277326 ],
278327 'desc': 'Range starting before the beginning of the first node and ending between the second and the third node'
279328 },
 329+ // Test 22
280330 {
281331 'node': root2,
282332 'input': new es.Range( 0, 21 ),
@@ -286,6 +336,7 @@
287337 ],
288338 'desc': 'Range starting before the beginning of the first node and ending at the beginning of the third node'
289339 },
 340+ // Test 23
290341 {
291342 'node': root2,
292343 'input': new es.Range( 0, 27 ),
@@ -296,6 +347,7 @@
297348 ],
298349 'desc': 'Range starting before the beginning of the first node and ending in the middle of the third node'
299350 },
 351+ // Test 24
300352 {
301353 'node': root2,
302354 'input': new es.Range( 0, 29 ),
@@ -306,6 +358,7 @@
307359 ],
308360 'desc': 'Range starting before the beginning of the first node and ending at the end of the third node'
309361 },
 362+ // Test 25
310363 {
311364 'node': root2,
312365 'input': new es.Range( 0, 30 ),
@@ -316,6 +369,7 @@
317370 ],
318371 'desc': 'Range starting before the beginning of the first node and ending past the end of the third node'
319372 },
 373+ // Test 26
320374 {
321375 'node': root2,
322376 'input': new es.Range( 1, 11 ),
@@ -325,6 +379,7 @@
326380 ],
327381 'desc': 'Range starting at the beginning of the first node and ending at the beginning of the second node'
328382 },
 383+ // Test 27
329384 {
330385 'node': root2,
331386 'input': new es.Range( 1, 14 ),
@@ -334,6 +389,7 @@
335390 ],
336391 'desc': 'Range starting at the beginning of the first node and ending in the middle of the second node'
337392 },
 393+ // Test 28
338394 {
339395 'node': root2,
340396 'input': new es.Range( 1, 19 ),
@@ -343,6 +399,7 @@
344400 ],
345401 'desc': 'Range starting at the beginning of the first node and ending at the end of the second node'
346402 },
 403+ // Test 29
347404 {
348405 'node': root2,
349406 'input': new es.Range( 1, 20 ),
@@ -352,6 +409,7 @@
353410 ],
354411 'desc': 'Range starting at the beginning of the first node and ending between the second and the third node'
355412 },
 413+ // Test 30
356414 {
357415 'node': root2,
358416 'input': new es.Range( 1, 21 ),
@@ -362,6 +420,7 @@
363421 ],
364422 'desc': 'Range starting at the beginning of the first node and ending at the beginning of the third node'
365423 },
 424+ // Test 31
366425 {
367426 'node': root2,
368427 'input': new es.Range( 1, 27 ),
@@ -372,6 +431,7 @@
373432 ],
374433 'desc': 'Range starting at the beginning of the first node and ending in the middle of the third node'
375434 },
 435+ // Test 32
376436 {
377437 'node': root2,
378438 'input': new es.Range( 1, 29 ),
@@ -382,6 +442,7 @@
383443 ],
384444 'desc': 'Range starting at the beginning of the first node and ending at the end of the third node'
385445 },
 446+ // Test 33
386447 {
387448 'node': root2,
388449 'input': new es.Range( 1, 30 ),
@@ -392,6 +453,7 @@
393454 ],
394455 'desc': 'Range starting at the beginning of the first node and ending past the end of the third node'
395456 },
 457+ // Test 34
396458 {
397459 'node': root2,
398460 'input': new es.Range( 5, 11 ),
@@ -401,6 +463,7 @@
402464 ],
403465 'desc': 'Range starting in the middle of the first node and ending at the beginning of the second node'
404466 },
 467+ // Test 35
405468 {
406469 'node': root2,
407470 'input': new es.Range( 5, 14 ),
@@ -410,6 +473,7 @@
411474 ],
412475 'desc': 'Range starting in the middle of the first node and ending in the middle of the second node'
413476 },
 477+ // Test 36
414478 {
415479 'node': root2,
416480 'input': new es.Range( 5, 19 ),
@@ -419,6 +483,7 @@
420484 ],
421485 'desc': 'Range starting in the middle of the first node and ending at the end of the second node'
422486 },
 487+ // Test 37
423488 {
424489 'node': root2,
425490 'input': new es.Range( 5, 20 ),
@@ -428,6 +493,7 @@
429494 ],
430495 'desc': 'Range starting in the middle of the first node and ending between the second and the third node'
431496 },
 497+ // Test 38
432498 {
433499 'node': root2,
434500 'input': new es.Range( 5, 21 ),
@@ -438,6 +504,7 @@
439505 ],
440506 'desc': 'Range starting in the middle of the first node and ending at the beginning of the third node'
441507 },
 508+ // Test 39
442509 {
443510 'node': root2,
444511 'input': new es.Range( 5, 27 ),
@@ -448,6 +515,7 @@
449516 ],
450517 'desc': 'Range starting in the middle of the first node and ending in the middle of the third node'
451518 },
 519+ // Test 40
452520 {
453521 'node': root2,
454522 'input': new es.Range( 5, 29 ),
@@ -458,6 +526,7 @@
459527 ],
460528 'desc': 'Range starting in the middle of the first node and ending at the end of the third node'
461529 },
 530+ // Test 41
462531 {
463532 'node': root2,
464533 'input': new es.Range( 5, 30 ),
@@ -468,6 +537,7 @@
469538 ],
470539 'desc': 'Range starting in the middle of the first node and ending past the end of the third node'
471540 },
 541+ // Test 42
472542 {
473543 'node': root2,
474544 'input': new es.Range( 9, 11 ),
@@ -477,6 +547,7 @@
478548 ],
479549 'desc': 'Range starting at the end of the first node and ending at the beginning of the second node'
480550 },
 551+ // Test 43
481552 {
482553 'node': root2,
483554 'input': new es.Range( 9, 14 ),
@@ -486,6 +557,7 @@
487558 ],
488559 'desc': 'Range starting at the end of the first node and ending in the middle of the second node'
489560 },
 561+ // Test 44
490562 {
491563 'node': root2,
492564 'input': new es.Range( 9, 19 ),
@@ -495,6 +567,7 @@
496568 ],
497569 'desc': 'Range starting at the end of the first node and ending at the end of the second node'
498570 },
 571+ // Test 45
499572 {
500573 'node': root2,
501574 'input': new es.Range( 9, 20 ),
@@ -504,6 +577,7 @@
505578 ],
506579 'desc': 'Range starting at the end of the first node and ending between the second and the third node'
507580 },
 581+ // Test 46
508582 {
509583 'node': root2,
510584 'input': new es.Range( 9, 21 ),
@@ -514,6 +588,7 @@
515589 ],
516590 'desc': 'Range starting at the end of the first node and ending at the beginning of the third node'
517591 },
 592+ // Test 47
518593 {
519594 'node': root2,
520595 'input': new es.Range( 9, 27 ),
@@ -524,6 +599,7 @@
525600 ],
526601 'desc': 'Range starting at the end of the first node and ending in the middle of the third node'
527602 },
 603+ // Test 48
528604 {
529605 'node': root2,
530606 'input': new es.Range( 9, 29 ),
@@ -534,6 +610,7 @@
535611 ],
536612 'desc': 'Range starting at the end of the first node and ending at the end of the third node'
537613 },
 614+ // Test 49
538615 {
539616 'node': root2,
540617 'input': new es.Range( 9, 30 ),
@@ -544,6 +621,7 @@
545622 ],
546623 'desc': 'Range starting at the end of the first node and ending past the end of the third node'
547624 },
 625+ // Test 50
548626 {
549627 'node': root2,
550628 'input': new es.Range( 10, 21 ),
@@ -553,6 +631,7 @@
554632 ],
555633 'desc': 'Range starting between the first and the second node and ending at the beginning of the third node'
556634 },
 635+ // Test 51
557636 {
558637 'node': root2,
559638 'input': new es.Range( 10, 27 ),
@@ -562,6 +641,7 @@
563642 ],
564643 'desc': 'Range starting between the first and the second node and ending in the middle of the third node'
565644 },
 645+ // Test 56
566646 {
567647 'node': root2,
568648 'input': new es.Range( 10, 29 ),
@@ -571,6 +651,7 @@
572652 ],
573653 'desc': 'Range starting between the first and the second node and ending at the end of the third node'
574654 },
 655+ // Test 57
575656 {
576657 'node': root2,
577658 'input': new es.Range( 10, 30 ),
@@ -580,6 +661,7 @@
581662 ],
582663 'desc': 'Range starting between the first and the second node and ending past the end of the third node'
583664 },
 665+ // Test 58
584666 {
585667 'node': root2,
586668 'input': new es.Range( 11, 21 ),
@@ -589,6 +671,7 @@
590672 ],
591673 'desc': 'Range starting at the beginning of the second node and ending at the beginning of the third node'
592674 },
 675+ // Test 59
593676 {
594677 'node': root2,
595678 'input': new es.Range( 11, 27 ),
@@ -598,6 +681,7 @@
599682 ],
600683 'desc': 'Range starting at the beginning of the second node and ending in the middle of the third node'
601684 },
 685+ // Test 60
602686 {
603687 'node': root2,
604688 'input': new es.Range( 11, 29 ),
@@ -607,6 +691,7 @@
608692 ],
609693 'desc': 'Range starting at the beginning of the second node and ending at the end of the third node'
610694 },
 695+ // Test 61
611696 {
612697 'node': root2,
613698 'input': new es.Range( 11, 30 ),
@@ -616,6 +701,7 @@
617702 ],
618703 'desc': 'Range starting at the beginning of the second node and ending past the end of the third node'
619704 },
 705+ // Test 62
620706 {
621707 'node': root2,
622708 'input': new es.Range( 14, 21 ),
@@ -625,6 +711,7 @@
626712 ],
627713 'desc': 'Range starting in the middle of the second node and ending at the beginning of the third node'
628714 },
 715+ // Test 63
629716 {
630717 'node': root2,
631718 'input': new es.Range( 14, 27 ),
@@ -634,6 +721,7 @@
635722 ],
636723 'desc': 'Range starting in the middle of the second node and ending in the middle of the third node'
637724 },
 725+ // Test 64
638726 {
639727 'node': root2,
640728 'input': new es.Range( 14, 29 ),
@@ -643,6 +731,7 @@
644732 ],
645733 'desc': 'Range starting in the middle of the second node and ending at the end of the third node'
646734 },
 735+ // Test 65
647736 {
648737 'node': root2,
649738 'input': new es.Range( 14, 30 ),
@@ -652,6 +741,7 @@
653742 ],
654743 'desc': 'Range starting in the middle of the second node and ending past the end of the third node'
655744 },
 745+ // Test 66
656746 {
657747 'node': root2,
658748 'input': new es.Range( 19, 21 ),
@@ -661,6 +751,7 @@
662752 ],
663753 'desc': 'Range starting at the end of the second node and ending at the beginning of the third node'
664754 },
 755+ // Test 67
665756 {
666757 'node': root2,
667758 'input': new es.Range( 19, 27 ),
@@ -670,6 +761,7 @@
671762 ],
672763 'desc': 'Range starting at the end of the second node and ending in the middle of the third node'
673764 },
 765+ // Test 68
674766 {
675767 'node': root2,
676768 'input': new es.Range( 19, 29 ),
@@ -679,6 +771,7 @@
680772 ],
681773 'desc': 'Range starting at the end of the second node and ending at the end of the third node'
682774 },
 775+ // Test 69
683776 {
684777 'node': root2,
685778 'input': new es.Range( 19, 30 ),
@@ -689,6 +782,8 @@
690783 'desc': 'Range starting at the end of the second node and ending past the end of the third node'
691784 },
692785 // Tests for childless nodes
 786+
 787+ // Test 70
693788 {
694789 'node': g,
695790 'input': new es.Range( 1, 3 ),
@@ -697,6 +792,7 @@
698793 ],
699794 'desc': 'Childless node given, range not out of bounds'
700795 },
 796+ // Test 72
701797 {
702798 'node': g,
703799 'input': new es.Range( 0, 8 ),
@@ -706,24 +802,29 @@
707803 'desc': 'Childless node given, range covers entire node'
708804 },
709805 // Tests for out-of-bounds cases
 806+
 807+ // Test 73
710808 {
711809 'node': g,
712810 'input': new es.Range( -1, 3 ),
713811 'exception': /^The start offset of the range is negative$/,
714812 'desc': 'Childless node given, range start out of bounds'
715813 },
 814+ // Test 74
716815 {
717816 'node': g,
718817 'input': new es.Range( 1, 9 ),
719818 'exception': /^The end offset of the range is past the end of the node$/,
720819 'desc': 'Childless node given, range end out of bounds'
721820 },
 821+ // Test 75
722822 {
723823 'node': root2,
724824 'input': new es.Range( 31, 35 ),
725825 'exception': /^The start offset of the range is past the end of the node$/,
726826 'desc': 'Node with children given, range start out of bounds'
727827 },
 828+ // Test 76
728829 {
729830 'node': root2,
730831 'input': new es.Range( 30, 35 ),
@@ -731,6 +832,8 @@
732833 'desc': 'Node with children given, range end out of bounds'
733834 },
734835 // Tests for recursion cases
 836+
 837+ // Test 77
735838 {
736839 'node': big,
737840 'input': new es.Range( 2, 10 ),
@@ -740,16 +843,18 @@
741844 ],
742845 'desc': 'Select from before the b to after the d'
743846 },
 847+ // Test 78
744848 {
745849 'node': big,
746 - 'input': new es.Range( 3, 27 ),
 850+ 'input': new es.Range( 3, 29 ),
747851 'output': [
748 - { 'node': big.children[0], 'range': new es.Range( 2, 3 ) },
 852+ { 'node': big.children[0], 'range': new es.Range( 2, 8 ) },
749853 { 'node': big.children[1] },
750 - { 'node': big.children[2], 'range': new es.Range( 0, 1 ) }
 854+ { 'node': big.children[2], 'range': new es.Range( 0, 8 ) }
751855 ],
752856 'desc': 'Select from before the c to after the h'
753857 },
 858+ // Test 79
754859 {
755860 'node': big,
756861 'input': new es.Range( 9, 17 ),
@@ -759,6 +864,7 @@
760865 ],
761866 'desc': 'Select from before the d to after the f, with recursion'
762867 },
 868+ // Test 80
763869 {
764870 'node': big,
765871 'input': new es.Range( 9, 17 ),
@@ -769,18 +875,53 @@
770876 'desc': 'Select from before the d to after the f, without recursion'
771877 }
772878 ];
773 -
 879+
 880+ function compare( a, b ) {
 881+ if ( $.isArray( a ) && $.isArray( b ) && a.length === b.length ) {
 882+ for ( var i = 0; i < a.length; i++ ) {
 883+ if (
 884+ a[i].node !== b[i].node ||
 885+ (
 886+ ( typeof a[i].range !== typeof b[i].range ) ||
 887+ (
 888+ a[i].range !== undefined &&
 889+ (
 890+ a[i].range.start !== b[i].range.start ||
 891+ a[i].range.end !== b[i].range.end
 892+ )
 893+ )
 894+ )
 895+ ) {
 896+ return false;
 897+ }
 898+ }
 899+ }
 900+ return true;
 901+ }
 902+ function select( input, shallow ) {
 903+ return function() {
 904+ selectNodesTests[i].node.selectNodes( input, shallow );
 905+ };
 906+ }
 907+
774908 for ( var i = 0; i < selectNodesTests.length; i++ ) {
775909 if ( 'output' in selectNodesTests[i] ) {
776 - deepEqual(
777 - selectNodesTests[i].node.selectNodes( selectNodesTests[i].input, selectNodesTests[i].shallow ),
778 - selectNodesTests[i].output,
779 - selectNodesTests[i].desc
 910+ var result = selectNodesTests[i].node.selectNodes(
 911+ selectNodesTests[i].input, selectNodesTests[i].shallow
 912+ );
 913+ ok(
 914+ compare( result, selectNodesTests[i].output ),
 915+ selectNodesTests[i].desc +
 916+ ' (from ' + selectNodesTests[i].input.start +
 917+ ' to ' + selectNodesTests[i].input.end + ')'
780918 );
781919 } else if ( 'exception' in selectNodesTests[i] ) {
782920 raises(
783921 function() {
784 - selectNodesTests[i].node.selectNodes( selectNodesTests[i].input, selectNodesTests[i].shallow );
 922+ selectNodesTests[i].node.selectNodes(
 923+ selectNodesTests[i].input,
 924+ selectNodesTests[i].shallow
 925+ );
785926 },
786927 selectNodesTests[i].exception,
787928 selectNodesTests[i].desc
Index: trunk/extensions/VisualEditor/tests/es/es.testData.js
@@ -67,27 +67,42 @@
6868 'attributes': {
6969 'styles': ['bullet']
7070 },
71 - 'content': {
72 - 'text': 'e'
73 - }
 71+ 'children': [
 72+ {
 73+ 'type': 'paragraph',
 74+ 'content': {
 75+ 'text': 'e'
 76+ }
 77+ }
 78+ ]
7479 },
7580 {
7681 'type': 'listItem',
7782 'attributes': {
7883 'styles': ['bullet', 'bullet']
7984 },
80 - 'content': {
81 - 'text': 'f'
82 - }
 85+ 'children': [
 86+ {
 87+ 'type': 'paragraph',
 88+ 'content': {
 89+ 'text': 'f'
 90+ }
 91+ }
 92+ ]
8393 },
8494 {
8595 'type': 'listItem',
8696 'attributes': {
8797 'styles': ['number']
8898 },
89 - 'content': {
90 - 'text': 'g'
91 - }
 99+ 'children': [
 100+ {
 101+ 'type': 'paragraph',
 102+ 'content': {
 103+ 'text': 'g'
 104+ }
 105+ }
 106+ ]
92107 }
93108 ]
94109 }
@@ -150,35 +165,47 @@
151166 { 'type': 'list' },
152167 // 12 - Beginning of bullet list item
153168 { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
154 - // 13 - Plain content
 169+ // 13 - Beginning of paragraph
 170+ { 'type': 'paragraph' },
 171+ // 14 - Plain content
155172 'e',
156 - // 14 - End of item
 173+ // 15 - End of paragraph
 174+ { 'type': '/paragraph' },
 175+ // 16 - End of item
157176 { 'type': '/listItem' },
158 - // 15 - Beginning of nested bullet list item
 177+ // 17 - Beginning of nested bullet list item
159178 { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
160 - // 16 - Plain content
 179+ // 18 - Beginning of paragraph
 180+ { 'type': 'paragraph' },
 181+ // 19 - Plain content
161182 'f',
162 - // 17 - End of item
 183+ // 20 - End of paragraph
 184+ { 'type': '/paragraph' },
 185+ // 21 - End of item
163186 { 'type': '/listItem' },
164 - // 18 - Beginning of numbered list item
 187+ // 22 - Beginning of numbered list item
165188 { 'type': 'listItem', 'attributes': { 'styles': ['number'] } },
166 - // 19 - Plain content
 189+ // 23 - Beginning of paragraph
 190+ { 'type': 'paragraph' },
 191+ // 24 - Plain content
167192 'g',
168 - // 20 - End of item
 193+ // 25 - End of paragraph
 194+ { 'type': '/paragraph' },
 195+ // 26 - End of item
169196 { 'type': '/listItem' },
170 - // 21 - End of list
 197+ // 27 - End of list
171198 { 'type': '/list' },
172 - // 22 - End of cell
 199+ // 28 - End of cell
173200 { 'type': '/tableCell' },
174 - // 23 - End of row
 201+ // 29 - End of row
175202 { 'type': '/tableRow' },
176 - // 24 - End of table
 203+ // 30 - End of table
177204 { 'type': '/table' },
178 - // 25 - Beginning of paragraph
 205+ // 31 - Beginning of paragraph
179206 { 'type': 'paragraph' },
180 - // 26 - Plain content
 207+ // 32 - Plain content
181208 'h',
182 - // 27 - End of paragraph
 209+ // 33 - End of paragraph
183210 { 'type': '/paragraph' }
184211 ];
185212
@@ -195,12 +222,18 @@
196223 new es.TableCellModel( esTest.data[7], [
197224 new es.ParagraphModel( esTest.data[8], 1 ),
198225 new es.ListModel( esTest.data[11], [
199 - new es.ListItemModel( esTest.data[12], 1 ),
200 - new es.ListItemModel( esTest.data[15], 1 ),
201 - new es.ListItemModel( esTest.data[18], 1 )
 226+ new es.ListItemModel( esTest.data[12], [
 227+ new es.ParagraphModel( esTest.data[13], 1 )
 228+ ] ),
 229+ new es.ListItemModel( esTest.data[17], [
 230+ new es.ParagraphModel( esTest.data[18], 1 )
 231+ ] ),
 232+ new es.ListItemModel( esTest.data[22], [
 233+ new es.ParagraphModel( esTest.data[23], 1 )
 234+ ] )
202235 ] )
203236 ] )
204237 ] )
205238 ] ),
206 - new es.ParagraphModel( esTest.data[25], 1 )
 239+ new es.ParagraphModel( esTest.data[31], 1 )
207240 ];
Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js
@@ -67,8 +67,8 @@
6868 );
6969 // Test 4
7070 equal(
71 - documentModel.getRelativeContentOffset( 27, 1 ),
72 - 27,
 71+ documentModel.getRelativeContentOffset( 32, 1 ),
 72+ 32,
7373 'getRelativeContentOffset treats the end a document as a non-content offset'
7474 );
7575 // Test 5
@@ -79,8 +79,8 @@
8080 );
8181 // Test 6
8282 equal(
83 - documentModel.getRelativeContentOffset( 26, -1 ),
84 - 20,
 83+ documentModel.getRelativeContentOffset( 32, -1 ),
 84+ 25,
8585 'getRelativeContentOffset advances backwards between elements'
8686 );
8787 } );
@@ -221,7 +221,7 @@
222222 documentModel.prepareElementAttributeChange( 0, 'set', 'test', 1234 ).getOperations(),
223223 [
224224 { 'type': 'attribute', 'method': 'set', 'key': 'test', 'value': 1234 },
225 - { 'type': 'retain', 'length': 28 }
 225+ { 'type': 'retain', 'length': 34 }
226226 ],
227227 'prepareElementAttributeChange retains data after attribute change for first element'
228228 );
@@ -232,7 +232,7 @@
233233 [
234234 { 'type': 'retain', 'length': 5 },
235235 { 'type': 'attribute', 'method': 'set', 'key': 'test', 'value': 1234 },
236 - { 'type': 'retain', 'length': 23 }
 236+ { 'type': 'retain', 'length': 29 }
237237 ],
238238 'prepareElementAttributeChange retains data before and after attribute change'
239239 );
@@ -295,7 +295,7 @@
296296 'bias': 'stop',
297297 'annotation': { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }
298298 },
299 - { 'type': 'retain', 'length': 24 }
 299+ { 'type': 'retain', 'length': 30 }
300300 ],
301301 'prepareContentAnnotation skips over content that is already set or cleared'
302302 );
@@ -317,34 +317,36 @@
318318 ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
319319 ]
320320 },
321 - { 'type': 'retain', 'length': 24 }
 321+ { 'type': 'retain', 'length': 30 }
322322 ],
323323 'prepareRemoval includes the content being removed'
324324 );
325325
326326 // Test 2
327327 deepEqual(
328 - documentModel.prepareRemoval( new es.Range( 15, 18 ) ).getOperations(),
 328+ documentModel.prepareRemoval( new es.Range( 17, 22 ) ).getOperations(),
329329 [
330 - { 'type': 'retain', 'length': 15 },
 330+ { 'type': 'retain', 'length': 17 },
331331 {
332332 'type': 'remove',
333333 'data': [
334334 { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
 335+ { 'type': 'paragraph' },
335336 'f',
 337+ { 'type': '/paragraph' },
336338 { 'type': '/listItem' }
337339 ]
338340 },
339 - { 'type': 'retain', 'length': 10 }
 341+ { 'type': 'retain', 'length': 12 }
340342 ],
341343 'prepareRemoval removes entire elements'
342344 );
343345
344346 // Test 3
345347 deepEqual(
346 - documentModel.prepareRemoval( new es.Range( 17, 19 ) ).getOperations(),
 348+ documentModel.prepareRemoval( new es.Range( 21, 23 ) ).getOperations(),
347349 [
348 - { 'type': 'retain', 'length': 17 },
 350+ { 'type': 'retain', 'length': 21 },
349351 {
350352 'type': 'remove',
351353 'data': [
@@ -352,7 +354,7 @@
353355 { 'type': 'listItem', 'attributes': { 'styles': ['number'] } }
354356 ]
355357 },
356 - { 'type': 'retain', 'length': 9 }
 358+ { 'type': 'retain', 'length': 11 }
357359 ],
358360 'prepareRemoval merges two list items'
359361 );
@@ -368,7 +370,7 @@
369371 ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
370372 ]
371373 },
372 - { 'type': 'retain', 'length': 24 }
 374+ { 'type': 'retain', 'length': 30 }
373375 ],
374376 'prepareRemoval works across structural nodes'
375377 );
@@ -383,7 +385,7 @@
384386 [
385387 { 'type': 'retain', 'length': 1 },
386388 { 'type': 'insert', 'data': ['d', 'e', 'f'] },
387 - { 'type': 'retain', 'length': 27 }
 389+ { 'type': 'retain', 'length': 33 }
388390 ],
389391 'prepareInsertion retains data up to the offset and includes the content being inserted'
390392 );
@@ -399,7 +401,7 @@
400402 'type': 'insert',
401403 'data': [{ 'type': 'paragraph' }, 'd', 'e', 'f', { 'type': '/paragraph' }]
402404 },
403 - { 'type': 'retain', 'length': 23 }
 405+ { 'type': 'retain', 'length': 29 }
404406 ],
405407 'prepareInsertion inserts a paragraph between two structural elements'
406408 );
@@ -413,7 +415,7 @@
414416 'type': 'insert',
415417 'data': [{ 'type': 'paragraph' }, 'd', 'e', 'f', { 'type': '/paragraph' }]
416418 },
417 - { 'type': 'retain', 'length': 23 }
 419+ { 'type': 'retain', 'length': 29 }
418420 ],
419421 'prepareInsertion wraps unstructured content inserted between elements in a paragraph'
420422 );
@@ -429,7 +431,7 @@
430432 'type': 'insert',
431433 'data': [{ 'type': 'paragraph' }, 'd', 'e', 'f', { 'type': '/paragraph' }]
432434 },
433 - { 'type': 'retain', 'length': 23 }
 435+ { 'type': 'retain', 'length': 29 }
434436 ],
435437 'prepareInsertion completes opening elements in inserted content'
436438 );
@@ -450,7 +452,7 @@
451453 { 'type': 'paragraph' }
452454 ]
453455 },
454 - { 'type': 'retain', 'length': 26 }
 456+ { 'type': 'retain', 'length': 32 }
455457 ],
456458 'prepareInsertion splits up paragraph when inserting a table in the middle'
457459 );
@@ -475,7 +477,7 @@
476478 'r'
477479 ]
478480 },
479 - { 'type': 'retain', 'length': 26 }
 481+ { 'type': 'retain', 'length': 32 }
480482 ],
481483 'prepareInsertion splits paragraph when inserting a paragraph closing and opening inside it'
482484 );
@@ -490,7 +492,7 @@
491493 'type': 'insert',
492494 'data': [ { 'type': 'paragraph' }, 'f', 'o', 'o', { 'type': '/paragraph' } ]
493495 },
494 - { 'type': 'retain', 'length': 28 }
 496+ { 'type': 'retain', 'length': 34 }
495497 ],
496498 'prepareInsertion inserts at the beginning, then retains up to the end'
497499 );
@@ -498,10 +500,10 @@
499501 // Test 8
500502 deepEqual(
501503 documentModel.prepareInsertion(
502 - 28, [ { 'type': 'paragraph' }, 'f', 'o', 'o', { 'type': '/paragraph' } ]
 504+ 34, [ { 'type': 'paragraph' }, 'f', 'o', 'o', { 'type': '/paragraph' } ]
503505 ).getOperations(),
504506 [
505 - { 'type': 'retain', 'length': 28 },
 507+ { 'type': 'retain', 'length': 34 },
506508 {
507509 'type': 'insert',
508510 'data': [ { 'type': 'paragraph' }, 'f', 'o', 'o', { 'type': '/paragraph' } ]
@@ -526,11 +528,11 @@
527529 raises(
528530 function() {
529531 documentModel.prepareInsertion(
530 - 29,
 532+ 35,
531533 [ { 'type': 'paragraph' }, 'f', 'o', 'o', { 'type': '/paragraph' } ]
532534 );
533535 },
534 - /^Offset 29 out of bounds/,
 536+ /^Offset 35 out of bounds/,
535537 'prepareInsertion throws exception for offset past the end'
536538 );
537539

Comments

#Comment by Catrope (talk | contribs)   12:24, 10 November 2011
-			deepEqual(
-				selectNodesTests[i].node.selectNodes( selectNodesTests[i].input, selectNodesTests[i].shallow ),
-				selectNodesTests[i].output,
-				selectNodesTests[i].desc
+			var result = selectNodesTests[i].node.selectNodes(
+					selectNodesTests[i].input, selectNodesTests[i].shallow
+				);
+			ok(
+				compare( result, selectNodesTests[i].output ),

WHYYYYYYY? deepEqual() gives very useful diff output when the comparison fails. Your ok()+compare() combo just gives a red box and no other information whatsoever. (But it is hella faster.)

#Comment by Trevor Parscal (WMF) (talk | contribs)   18:15, 10 November 2011

Deep equal pisses me off because it goes bonkers on our nodes, and make the output as useless as the red box. This way, we can know if a test is failing quickly doing a "what matters" comparison, and if something is broken, we can just add a debugger or console.dir statement to the code to fix it.

Unit testing and debug output don't need to always be united - as long as the results are correct we are in good shape. I say use deep equal unless it's ridiculous to do so, and in this case I think it is.

#Comment by Catrope (talk | contribs)   12:59, 11 November 2011

I wonder if there's some way that we can implement our own comparison function that compares the nodes by reference and compares the ranges correctly (just like compare()), but also outputs useful debugging output. I feel there has to be some way to do that in qUnit, much like the way deepEqual() itself is implemented.

Status & tagging log