Add _.words tests and tweak reWords regexp.

This commit is contained in:
John-David Dalton
2014-09-22 22:16:48 -07:00
parent 41f1fb8d95
commit 8256579310
2 changed files with 13 additions and 4 deletions

View File

@@ -105,11 +105,10 @@
/** Used to match words to create compound words */ /** Used to match words to create compound words */
var reWords = (function() { var reWords = (function() {
var nums = '[0-9]', var upper = '[A-Z\\xC0-\\xD6\\xD8-\\xDE]',
upper = '[A-Z\\xC0-\\xD6\\xD8-\\xDE]', lower = '[a-z\\xDF-\\xF6\\xF8-\\xFF]+';
lower = '[a-z\\xDF-\\xF6\\xF8-\\xFF]+' + nums + '*';
return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|' + nums + '+', 'g'); return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
}()); }());
/** Used to detect and test whitespace */ /** Used to detect and test whitespace */

View File

@@ -11657,6 +11657,16 @@
deepEqual(actual, [['a'], ['b'], ['c']]); deepEqual(actual, [['a'], ['b'], ['c']]);
}); });
test('should work with compound words', 6, function() {
deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
deepEqual(_.words('aeiou2Consonants'), ['aeiou', '2', 'Consonants']);
deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
});
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/