Rename _.truncate to _.trunc to align with ES6.

This commit is contained in:
John-David Dalton
2014-05-30 12:26:52 -04:00
parent 95db668c3c
commit f4a1573586
4 changed files with 25 additions and 25 deletions

View File

@@ -9148,55 +9148,55 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.truncate');
QUnit.module('lodash.trunc');
(function() {
var string = 'hi-diddly-ho there, neighborino';
test('should truncate to a length of `30` by default', 1, function() {
strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
strictEqual(_.trunc(string), 'hi-diddly-ho there, neighbo...');
});
test('should not truncate if `string` is <= `length`', 2, function() {
strictEqual(_.truncate(string, string.length), string);
strictEqual(_.truncate(string, string.length + 2), string);
strictEqual(_.trunc(string, string.length), string);
strictEqual(_.trunc(string, string.length + 2), string);
});
test('should truncate string the given length', 1, function() {
strictEqual(_.truncate(string, 24), 'hi-diddly-ho there, n...');
strictEqual(_.trunc(string, 24), 'hi-diddly-ho there, n...');
});
test('should support a `omission` option', 1, function() {
strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
strictEqual(_.trunc(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
});
test('should support a `length` option', 1, function() {
strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
strictEqual(_.trunc(string, { 'length': 4 }), 'h...');
});
test('should support a `separator` option', 2, function() {
strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
strictEqual(_.trunc(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
strictEqual(_.trunc(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
});
test('should treat negative `length` as `0`', 4, function() {
_.each([0, -2], function(length) {
strictEqual(_.truncate(string, length), '...');
strictEqual(_.truncate(string, { 'length': length }), '...');
strictEqual(_.trunc(string, length), '...');
strictEqual(_.trunc(string, { 'length': length }), '...');
});
});
test('should coerce `length` to a number', 4, function() {
_.each(['', '4'], function(length, index) {
var actual = index ? 'h...' : '...';
strictEqual(_.truncate(string, length), actual);
strictEqual(_.truncate(string, { 'length': { 'valueOf': _.constant(length) } }), actual);
strictEqual(_.trunc(string, length), actual);
strictEqual(_.trunc(string, { 'length': { 'valueOf': _.constant(length) } }), actual);
});
});
test('should coerce `string` to a string', 2, function() {
strictEqual(_.truncate(Object(string), 4), 'h...');
strictEqual(_.truncate({ 'toString': _.constant(string) }, 5), 'hi...');
strictEqual(_.trunc(Object(string), 4), 'h...');
strictEqual(_.trunc({ 'toString': _.constant(string) }, 5), 'hi...');
});
}());
@@ -10747,7 +10747,7 @@
'trim',
'trimLeft',
'trimRight',
'truncate',
'trunc',
'unescape'
];