mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Add tests for ve.dm.Document.getNearestWordBoundary
Also in this commit is a minor fix to the regular expression so it behaves as documented (the hyphen needed escaping). Bug: 44085 Change-Id: Idc315e2dce79be8f028b5681c60f74e175b9d869
This commit is contained in:
parent
acf72c72c4
commit
981bb3ae7c
|
@ -164,7 +164,7 @@ ve.inheritClass( ve.dm.Document, ve.Document );
|
|||
*
|
||||
* This pattern is tested against one character at a time.
|
||||
*/
|
||||
ve.dm.SurfaceFragment.wordBoundaryPattern = /[^\w'"-\(\)\[\]]+/;
|
||||
ve.dm.SurfaceFragment.wordBoundaryPattern = /[^\w'"\-\(\)\[\]]+/;
|
||||
|
||||
/**
|
||||
* Apply annotations to content data.
|
||||
|
|
|
@ -1332,6 +1332,44 @@ QUnit.test( 'getNearestStructuralOffset', function ( assert ) {
|
|||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'getNearestWordBoundary', function ( assert ) {
|
||||
var i, doc, left, right, word,
|
||||
cases = [
|
||||
{
|
||||
'phrase': 'visual editor test',
|
||||
'msg': 'simple Latin word',
|
||||
'offset': 10,
|
||||
'expected': 'editor'
|
||||
},
|
||||
{
|
||||
'phrase': 'Computer-aided design',
|
||||
'msg': 'hyphenated Latin word',
|
||||
'offset': 2,
|
||||
'expected': 'Computer-aided'
|
||||
},
|
||||
{
|
||||
'phrase': 'Water (l\'eau) is',
|
||||
'msg': 'apostrophe and parentheses (Latin)',
|
||||
'offset': 8,
|
||||
'expected': '(l\'eau)'
|
||||
},
|
||||
{
|
||||
'phrase': 'Water (H2O) is',
|
||||
'msg': 'number in word (Latin)',
|
||||
'offset': 9,
|
||||
'expected': '(H2O)'
|
||||
}
|
||||
];
|
||||
QUnit.expect( cases.length );
|
||||
for ( i = 0; i < cases.length; i++ ) {
|
||||
doc = new ve.dm.Document( cases[i].phrase.split('') );
|
||||
left = doc.getNearestWordBoundary( cases[i].offset, -1 );
|
||||
right = doc.getNearestWordBoundary( cases[i].offset, 1 );
|
||||
word = cases[i].phrase.substring( left, right );
|
||||
assert.strictEqual( word, cases[i].expected, cases[i].msg );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'selectNodes', 21, function ( assert ) {
|
||||
var i,
|
||||
doc = new ve.dm.Document( ve.copyArray( ve.dm.example.data ) ),
|
||||
|
|
Loading…
Reference in a new issue