diff --git a/modules/ve2/dm/ve.dm.Document.js b/modules/ve2/dm/ve.dm.Document.js index 028f8137f7..c7d922c765 100644 --- a/modules/ve2/dm/ve.dm.Document.js +++ b/modules/ve2/dm/ve.dm.Document.js @@ -70,8 +70,8 @@ ve.dm.Document.prototype.rebuildNodes = function( parent, index, numNodes, offse * * @method * @param {ve.Range} range Range within document to select nodes - * @param {String} [mode='leaves'] Type of selection to perform, currently only 'leaves' is supported - * 'leaves': Return all leaf nodes in the given range + * @param {String} [mode='leaves'] Type of selection to perform + * 'leaves': Return all leaf nodes in the given range * @returns {Array} List of objects describing nodes in the selection and the ranges therein * @throws 'Invalid start offset' if range.start is out of range * @throws 'Invalid end offset' if range.end is out of range diff --git a/tests/ve2/dm/ve.dm.Document.test.js b/tests/ve2/dm/ve.dm.Document.test.js index 42538e2f52..27619cb8a5 100644 --- a/tests/ve2/dm/ve.dm.Document.test.js +++ b/tests/ve2/dm/ve.dm.Document.test.js @@ -32,30 +32,38 @@ test( 'rebuildNodes', function() { ve.dm.example.nodeTreeEqual( documentNode, tree ); } ); -test( 'selectNodes', 14, function() { +test( 'selectNodes', 17, function() { var doc = new ve.dm.Document( ve.dm.example.data ), documentNode = doc.getDocumentNode(), lookup = ve.dm.example.lookupNode; + // Test count: ( 1 test + ( 2 tests x 1 results ) ) = 3 + ve.dm.example.nodeSelectionEqual( + doc.selectNodes( new ve.Range( 0, 3 ), 'leaves' ), + [ + // heading/text - tests partial leaf results have ranges with global offsets + { 'node': lookup( documentNode, 0, 0 ), 'range': new ve.Range( 1, 3 ) } + ] + ); // Test count: ( 1 test + ( 2 tests x 2 results ) ) = 5 ve.dm.example.nodeSelectionEqual( doc.selectNodes( new ve.Range( 0, 10 ), 'leaves' ), [ - // heading/text + // heading/text - tests full coverage leaf nodes do not have ranges { 'node': lookup( documentNode, 0, 0 ) }, - // table/tableRow/tableCell/paragraph/text + // table/tableRow/tableCell/paragraph/text - tests leaf nodes from different levels { 'node': lookup( documentNode, 1, 0, 0, 0, 0 ) } ] ); // Test count: ( 1 test + ( 2 tests x 4 results ) ) = 9 ve.dm.example.nodeSelectionEqual( - doc.selectNodes( new ve.Range( 28, 41 ) ), + doc.selectNodes( new ve.Range( 28, 41 ), 'leaves' ), [ // table/tableRow/tableCell/list/listItem/paragraph/text { 'node': lookup( documentNode, 1, 0, 0, 2, 0, 0, 0 ) }, // preformatted/text { 'node': lookup( documentNode, 2, 0 ) }, - // preformatted/image + // preformatted/image - tests leaf nodes that are not text nodes { 'node': lookup( documentNode, 2, 1 ) }, // preformatted/text { 'node': lookup( documentNode, 2, 2 ) }