jenkins-bot has submitted this change and it was merged. Change subject: Add tests for ve.dm.Document.getNearestWordBoundary ......................................................................
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 --- M modules/ve/dm/ve.dm.Document.js M modules/ve/test/dm/ve.dm.Document.test.js 2 files changed, 39 insertions(+), 1 deletion(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ve/dm/ve.dm.Document.js b/modules/ve/dm/ve.dm.Document.js index c8ba4e0..31eb36d 100644 --- a/modules/ve/dm/ve.dm.Document.js +++ b/modules/ve/dm/ve.dm.Document.js @@ -164,7 +164,7 @@ * * 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. diff --git a/modules/ve/test/dm/ve.dm.Document.test.js b/modules/ve/test/dm/ve.dm.Document.test.js index 64e7c44..8c0051a 100644 --- a/modules/ve/test/dm/ve.dm.Document.test.js +++ b/modules/ve/test/dm/ve.dm.Document.test.js @@ -1332,6 +1332,44 @@ } } ); +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 ) ), -- To view, visit https://gerrit.wikimedia.org/r/53564 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idc315e2dce79be8f028b5681c60f74e175b9d869 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits