r103171 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103170‎ | r103171 | r103172 >
Date:13:50, 15 November 2011
Author:catrope
Status:deferred
Tags:
Comment:
Add more tests
Modified paths:
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js
@@ -939,7 +939,7 @@
940940 }
941941 } );
942942
943 -test( 'es.DocumentBranchNode.traverseLeafNodes', 6, function() {
 943+test( 'es.DocumentBranchNode.traverseLeafNodes', 10, function() {
944944 var root3 = es.DocumentModel.newFromPlainObject( esTest.obj );
945945
946946 // Test 1
@@ -1015,4 +1015,55 @@
10161016 es.compareArrays( realLeaves, expectedLeaves ),
10171017 'Starting at a non-leaf node returns all leaf nodes before it and none inside (in reverse)'
10181018 );
 1019+
 1020+ // Test 7
 1021+ realLeaves = [];
 1022+ expectedLeaves = [
 1023+ root3.children[1].children[0].children[0].children[0],
 1024+ root3.children[1].children[0].children[0].children[1].children[0].children[0],
 1025+ root3.children[1].children[0].children[0].children[1].children[1].children[0],
 1026+ root3.children[1].children[0].children[0].children[1].children[2].children[0]
 1027+ ];
 1028+ root3.children[1].traverseLeafNodes( function( node ) { realLeaves.push( node ); } );
 1029+ ok(
 1030+ es.compareArrays( realLeaves, expectedLeaves ),
 1031+ 'Calling traverseLeafNodes() on a non-root node only returns leaf nodes inside that node'
 1032+ );
 1033+ // Test 8
 1034+ realLeaves = [];
 1035+ expectedLeaves = expectedLeaves.reverse();
 1036+ root3.children[1].traverseLeafNodes( function( node ) { realLeaves.push( node ); }, undefined, true );
 1037+ ok(
 1038+ es.compareArrays( realLeaves, expectedLeaves ),
 1039+ 'Calling traverseLeafNodes() on a non-root node only returns leaf nodes inside that node (in reverse)'
 1040+ );
 1041+
 1042+ // Test 9
 1043+ realLeaves = [];
 1044+ raises(
 1045+ function() {
 1046+ root3.children[1].traverseLeafNodes( function( node ) { realLeaves.push( node ); }, root3.children[2] );
 1047+ },
 1048+ /^from parameter passed to traverseLeafNodes\(\) must be a descendant$/,
 1049+ 'Passing a sibling for from results in an exception'
 1050+ );
 1051+
 1052+ // Test 10
 1053+ // TODO this should be after test 1
 1054+ realLeaves = [];
 1055+ expectedLeaves = [
 1056+ root3.children[0],
 1057+ root3.children[1].children[0].children[0].children[0],
 1058+ root3.children[1].children[0].children[0].children[1].children[0].children[0]
 1059+ ];
 1060+ root3.traverseLeafNodes( function( node ) {
 1061+ realLeaves.push( node );
 1062+ if ( node === root3.children[1].children[0].children[0].children[1].children[0].children[0] ) {
 1063+ return false;
 1064+ }
 1065+ } );
 1066+ ok(
 1067+ es.compareArrays( realLeaves, expectedLeaves ),
 1068+ 'Returning false from the callback stops the traversal'
 1069+ );
10191070 } );
\ No newline at end of file

Status & tagging log