mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Add support for ordinals to _.words.
This commit is contained in:
90
test/test.js
90
test/test.js
@@ -4454,7 +4454,7 @@
|
||||
QUnit.module('lodash.deburr');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should convert Latin-1 Supplement letters to basic Latin', function(assert) {
|
||||
QUnit.test('should convert Latin Unicode letters to basic Latin', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var actual = lodashStable.map(burredLetters, _.deburr);
|
||||
@@ -25109,7 +25109,7 @@
|
||||
QUnit.module('lodash.words');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should match words containing Latin-1 Supplement letters', function(assert) {
|
||||
QUnit.test('should match words containing Latin Unicode letters', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = lodashStable.map(burredLetters, function(letter) {
|
||||
@@ -25123,31 +25123,6 @@
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should not treat mathematical operators as words', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
|
||||
expected = lodashStable.map(operators, stubArray),
|
||||
actual = lodashStable.map(operators, _.words);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should not treat punctuation as words', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var marks = [
|
||||
'\u2012', '\u2013', '\u2014', '\u2015',
|
||||
'\u2024', '\u2025', '\u2026',
|
||||
'\u205d', '\u205e'
|
||||
];
|
||||
|
||||
var expected = lodashStable.map(marks, stubArray),
|
||||
actual = lodashStable.map(marks, _.words);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should support a `pattern` argument', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
@@ -25180,24 +25155,73 @@
|
||||
assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
|
||||
});
|
||||
|
||||
QUnit.test('should work with contractions', function(assert) {
|
||||
assert.expect(2);
|
||||
QUnit.test('should not treat contractions as separate words', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
|
||||
|
||||
lodashStable.each(["'", '\u2019'], function(apos) {
|
||||
var actual = lodashStable.map(postfixes, function(postfix) {
|
||||
return _.words('a b' + apos + postfix + ' c');
|
||||
lodashStable.times(2, function(index) {
|
||||
var actual = lodashStable.map(postfixes, function(postfix) {
|
||||
var string = 'a b' + apos + postfix + ' c';
|
||||
return _.words(string[index ? 'toUpperCase' : 'toLowerCase']());
|
||||
});
|
||||
|
||||
var expected = lodashStable.map(postfixes, function(postfix) {
|
||||
var words = ['a', 'b' + apos + postfix, 'c'];
|
||||
return lodashStable.map(words, function(word) {
|
||||
return word[index ? 'toUpperCase' : 'toLowerCase']();
|
||||
});
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should not treat ordinal numbers as separate words', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var ordinals = ['1st', '2nd', '3rd', '4th'];
|
||||
|
||||
lodashStable.times(2, function(index) {
|
||||
var expected = lodashStable.map(ordinals, function(ordinal) {
|
||||
return [ordinal[index ? 'toUpperCase' : 'toLowerCase']()];
|
||||
});
|
||||
|
||||
var expected = lodashStable.map(postfixes, function(postfix) {
|
||||
return ['a', 'b' + apos + postfix, 'c'];
|
||||
var actual = lodashStable.map(expected, function(words) {
|
||||
return _.words(words[0]);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should not treat mathematical operators as words', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
|
||||
expected = lodashStable.map(operators, stubArray),
|
||||
actual = lodashStable.map(operators, _.words);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should not treat punctuation as words', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var marks = [
|
||||
'\u2012', '\u2013', '\u2014', '\u2015',
|
||||
'\u2024', '\u2025', '\u2026',
|
||||
'\u205d', '\u205e'
|
||||
];
|
||||
|
||||
var expected = lodashStable.map(marks, stubArray),
|
||||
actual = lodashStable.map(marks, _.words);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user