Add _.trunc tests for astrals as separators.

This commit is contained in:
John-David Dalton
2015-09-18 23:48:19 -07:00
parent a4b333ceb8
commit f4ff336636
2 changed files with 27 additions and 12 deletions

View File

@@ -11149,15 +11149,14 @@
if (isRegExp(separator)) { if (isRegExp(separator)) {
if (string.slice(end).search(separator)) { if (string.slice(end).search(separator)) {
var match, var match,
newEnd,
substring = result; substring = result;
if (!separator.global) { if (!separator.global) {
separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g'); separator = RegExp(separator.source, baseToString(reFlags.exec(separator)) + 'g');
} }
separator.lastIndex = 0; separator.lastIndex = 0;
while ((match = separator.exec(substring))) { while ((match = separator.exec(substring))) {
newEnd = match.index; var newEnd = match.index;
} }
result = result.slice(0, newEnd == null ? end : newEnd); result = result.slice(0, newEnd == null ? end : newEnd);
} }

View File

@@ -18888,12 +18888,15 @@
QUnit.module('astral symbols'); QUnit.module('astral symbols');
(function() { (function() {
var hearts = '\uD83D\uDC95', var flag = '\uD83C\uDDFA\uD83C\uDDF8',
leafs = '\uD83C\uDF42', hearts = '\uD83D\uDC95',
string = 'I ' + hearts + ' the ' + leafs; leafs = '\uD83C\uDF42';
QUnit.test('should account for astral symbols', function(assert) { QUnit.test('should account for astral symbols', function(assert) {
assert.expect(17); assert.expect(25);
var allHearts = _.repeat(hearts, 10),
string = 'I ' + hearts + ' the ' + leafs;
assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs); assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
assert.strictEqual(_.camelCase(string), 'i' + hearts + 'The' + leafs); assert.strictEqual(_.camelCase(string), 'i' + hearts + 'The' + leafs);
@@ -18918,17 +18921,30 @@
assert.strictEqual(_.trunc(string, { 'length': 6 }), 'I ' + hearts + '...'); assert.strictEqual(_.trunc(string, { 'length': 6 }), 'I ' + hearts + '...');
assert.deepEqual(_.words(string), ['I', hearts, 'the', leafs]); assert.deepEqual(_.words(string), ['I', hearts, 'the', leafs]);
_.times(2, function(index) {
var separator = index ? RegExp(hearts) : hearts,
options = { 'length': 4, 'separator': separator },
actual = _.trunc(string, options);
assert.strictEqual(actual, 'I...');
assert.strictEqual(actual.length, 4);
actual = _.trunc(allHearts, options);
assert.strictEqual(actual, hearts + '...');
assert.strictEqual(actual.length, 5);
});
}); });
QUnit.test('should match lone surrogates', function(assert) { QUnit.test('should match lone surrogates', function(assert) {
assert.expect(3); assert.expect(3);
var pairs = hearts.split(''), var pair = hearts.split(''),
loneSurrogates = pairs[0] + ' ' + pairs[1]; surrogates = pair[0] + ' ' + pair[1];
assert.strictEqual(_.size(loneSurrogates), 3); assert.strictEqual(_.size(surrogates), 3);
assert.deepEqual(_.toArray(loneSurrogates), [pairs[0], ' ', pairs[1]]); assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
assert.deepEqual(_.words(loneSurrogates), []); assert.deepEqual(_.words(surrogates), []);
}); });
}()); }());