mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
Improve verbosity of selectNodes test descriptions
* Make nodeSelectionEqual() accept a desc parameter and use it for building descriptions * Put the array element number in the desciption too * Add descriptions for selectNodes tests and pass them through Change-Id: Icd2894d11516234598cbd984cc8d88f705bfc1d6
This commit is contained in:
parent
0f0c3c9939
commit
cdda5e7920
|
@ -6,6 +6,6 @@ test( 'selectNodes', function() {
|
||||||
var doc = new ve.ce.Document( new ve.dm.Document( ve.dm.example.data ) ),
|
var doc = new ve.ce.Document( new ve.dm.Document( ve.dm.example.data ) ),
|
||||||
cases = ve.example.getSelectNodesCases( doc );
|
cases = ve.example.getSelectNodesCases( doc );
|
||||||
for ( var i = 0; i < cases.length; i++ ) {
|
for ( var i = 0; i < cases.length; i++ ) {
|
||||||
ve.example.nodeSelectionEqual( cases[i].actual, cases[i].expected );
|
ve.example.nodeSelectionEqual( cases[i].actual, cases[i].expected, cases[i].msg );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -347,6 +347,6 @@ test( 'selectNodes', function() {
|
||||||
var doc = new ve.dm.Document( ve.dm.example.data ),
|
var doc = new ve.dm.Document( ve.dm.example.data ),
|
||||||
cases = ve.example.getSelectNodesCases( doc );
|
cases = ve.example.getSelectNodesCases( doc );
|
||||||
for ( var i = 0; i < cases.length; i++ ) {
|
for ( var i = 0; i < cases.length; i++ ) {
|
||||||
ve.example.nodeSelectionEqual( cases[i].actual, cases[i].expected );
|
ve.example.nodeSelectionEqual( cases[i].actual, cases[i].expected, cases[i].msg );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -11,31 +11,33 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 0, 3 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 0, 3 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
// heading/text - partial leaf results have ranges with global offsets
|
// heading/text
|
||||||
{
|
{
|
||||||
'node': lookup( documentNode, 0, 0 ),
|
'node': lookup( documentNode, 0, 0 ),
|
||||||
'range': new ve.Range( 1, 3 ),
|
'range': new ve.Range( 1, 3 ),
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 1, 4 )
|
'nodeRange': new ve.Range( 1, 4 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'partial leaf results have ranges with global offsets',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 0, 10 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 0, 10 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
// heading/text - full coverage leaf nodes do not have ranges
|
// heading/text
|
||||||
{
|
{
|
||||||
'node': lookup( documentNode, 0, 0 ),
|
'node': lookup( documentNode, 0, 0 ),
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 1, 4 )
|
'nodeRange': new ve.Range( 1, 4 )
|
||||||
},
|
},
|
||||||
// table/tableRow/tableCell/paragraph/text - leaf nodes from different levels
|
// table/tableRow/tableCell/paragraph/text
|
||||||
{
|
{
|
||||||
'node': lookup( documentNode, 1, 0, 0, 0, 0 ),
|
'node': lookup( documentNode, 1, 0, 0, 0, 0 ),
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 9, 10 )
|
'nodeRange': new ve.Range( 9, 10 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'leaf nodes do not have ranges, leaf nodes from different levels'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 28, 41 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 28, 41 ), 'leaves' ),
|
||||||
|
@ -52,7 +54,7 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 36, 37 )
|
'nodeRange': new ve.Range( 36, 37 )
|
||||||
},
|
},
|
||||||
// preformatted/image - leaf nodes that are not text nodes
|
// preformatted/image
|
||||||
{
|
{
|
||||||
'node': lookup( documentNode, 2, 1 ),
|
'node': lookup( documentNode, 2, 1 ),
|
||||||
'index': 1,
|
'index': 1,
|
||||||
|
@ -64,7 +66,8 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 2,
|
'index': 2,
|
||||||
'nodeRange': new ve.Range( 39, 40 )
|
'nodeRange': new ve.Range( 39, 40 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'leaf nodes that are not text nodes'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 2, 15 ), 'siblings' ),
|
'actual': doc.selectNodes( new ve.Range( 2, 15 ), 'siblings' ),
|
||||||
|
@ -83,7 +86,8 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 1,
|
'index': 1,
|
||||||
'nodeRange': new ve.Range( 6, 34 )
|
'nodeRange': new ve.Range( 6, 34 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'siblings at the document level'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 2, 49 ), 'siblings' ),
|
'actual': doc.selectNodes( new ve.Range( 2, 49 ), 'siblings' ),
|
||||||
|
@ -114,10 +118,9 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 3,
|
'index': 3,
|
||||||
'nodeRange': new ve.Range( 42, 52 )
|
'nodeRange': new ve.Range( 42, 52 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'more than 2 siblings at the document level'
|
||||||
},
|
},
|
||||||
// Zero-length range at the edge of a text node returns that text node rather than
|
|
||||||
// its parent
|
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 1, 1 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 1, 1 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
|
@ -128,7 +131,8 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 1, 4 )
|
'nodeRange': new ve.Range( 1, 4 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'zero-length range at the start of a text node returns text node rather than parent'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 4, 4 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 4, 4 ), 'leaves' ),
|
||||||
|
@ -140,9 +144,9 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 1, 4 )
|
'nodeRange': new ve.Range( 1, 4 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'zero-length range at the end of a text node returns text node rather than parent'
|
||||||
},
|
},
|
||||||
// Range entirely within one leaf node
|
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 2, 3 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 2, 3 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
|
@ -153,9 +157,9 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'index': 0,
|
'index': 0,
|
||||||
'nodeRange': new ve.Range( 1, 4 )
|
'nodeRange': new ve.Range( 1, 4 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'range entirely within one leaf node'
|
||||||
},
|
},
|
||||||
// Zero-length range between two children of the document
|
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 5, 5 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 5, 5 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
|
@ -167,9 +171,9 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'indexInNode': 1,
|
'indexInNode': 1,
|
||||||
'nodeRange': new ve.Range( 0, 53 )
|
'nodeRange': new ve.Range( 0, 53 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'zero-length range between two children of the document'
|
||||||
},
|
},
|
||||||
// Zero-length range at the beginning of the document
|
|
||||||
{
|
{
|
||||||
'actual': doc.selectNodes( new ve.Range( 0, 0 ), 'leaves' ),
|
'actual': doc.selectNodes( new ve.Range( 0, 0 ), 'leaves' ),
|
||||||
'expected': [
|
'expected': [
|
||||||
|
@ -181,7 +185,8 @@ ve.example.getSelectNodesCases = function( doc ) {
|
||||||
'indexInNode': 0,
|
'indexInNode': 0,
|
||||||
'nodeRange': new ve.Range( 0, 53 )
|
'nodeRange': new ve.Range( 0, 53 )
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'msg': 'zero-length range at the start of the document'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -224,19 +229,24 @@ ve.example.nodeTreeEqual = function( a, b, desc, typePath ) {
|
||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
*/
|
*/
|
||||||
ve.example.nodeSelectionEqual = function( a, b ) {
|
ve.example.nodeSelectionEqual = function( a, b, desc ) {
|
||||||
|
var descPrefix = desc ? desc + ': ' : '';
|
||||||
|
// Prevent crashes if a and b have different lengths
|
||||||
var minLength = a.length < b.length ? a.length : b.length;
|
var minLength = a.length < b.length ? a.length : b.length;
|
||||||
equal( a.length, b.length, 'length match' );
|
equal( a.length, b.length, descPrefix + 'length match' );
|
||||||
for ( var i = 0; i < minLength; i++ ) {
|
for ( var i = 0; i < minLength; i++ ) {
|
||||||
ok( a[i].node === b[i].node, 'node match' );
|
ok( a[i].node === b[i].node, descPrefix + 'node match (element ' + i + ')' );
|
||||||
if ( a[i].range && b[i].range ) {
|
if ( a[i].range && b[i].range ) {
|
||||||
deepEqual( a[i].range, b[i].range, 'range match' );
|
deepEqual( a[i].range, b[i].range, descPrefix + 'range match (element ' + i + ')' );
|
||||||
} else {
|
} else {
|
||||||
strictEqual( 'range' in a[i], 'range' in b[i], 'range existence match' );
|
strictEqual( 'range' in a[i], 'range' in b[i],
|
||||||
|
descPrefix + 'range existence match (element ' + i + ')' );
|
||||||
}
|
}
|
||||||
deepEqual( a[i].index, b[i].index, 'index match' );
|
deepEqual( a[i].index, b[i].index, descPrefix + 'index match (element ' + i + ')' );
|
||||||
deepEqual( a[i].indexInNode, b[i].indexInNode, 'indexInNode match' );
|
deepEqual( a[i].indexInNode, b[i].indexInNode,
|
||||||
deepEqual( a[i].nodeRange, b[i].nodeRange, 'nodeRange match' );
|
descPrefix + 'indexInNode match (element ' + i + ')' );
|
||||||
|
deepEqual( a[i].nodeRange, b[i].nodeRange,
|
||||||
|
descPrefix + 'nodeRange match (element ' + i +')' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue