mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add _.rearg tests.
This commit is contained in:
66
test/test.js
66
test/test.js
@@ -9459,6 +9459,69 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('lodash.rearg');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
function fn(a, b, c) {
|
||||||
|
return slice.call(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('should reorder arguments provided to `func`', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, [2, 0, 1]);
|
||||||
|
deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should work with repeated indexes', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, [1, 1, 1]);
|
||||||
|
deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should use `undefined` for nonexistent indexes', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, [1, 4]);
|
||||||
|
deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should use `undefined` for non-index values', 1, function() {
|
||||||
|
var values = _.reject(empties, function(value) {
|
||||||
|
return value === 0 || _.isArray(value);
|
||||||
|
}).concat(-1, 1.1);
|
||||||
|
|
||||||
|
var expected = _.map(values, _.constant([undefined, 'b', 'c']));
|
||||||
|
|
||||||
|
var actual = _.map(values, function(value) {
|
||||||
|
var rearged = _.rearg(fn, [value]);
|
||||||
|
return rearged('a', 'b', 'c');
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not rearrange arguments when no indexes are provided', 2, function() {
|
||||||
|
var rearged = _.rearg(fn);
|
||||||
|
deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
|
||||||
|
|
||||||
|
rearged = _.rearg(fn, [], []);
|
||||||
|
deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should accept multiple index arguments', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, 2, 0, 1);
|
||||||
|
deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should accept multiple arrays of indexes', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, [2], [0, 1]);
|
||||||
|
deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should work with fewer indexes than arguments', 1, function() {
|
||||||
|
var rearged = _.rearg(fn, [1, 0]);
|
||||||
|
deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.reduce');
|
QUnit.module('lodash.reduce');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -13066,6 +13129,7 @@
|
|||||||
'once',
|
'once',
|
||||||
'partial',
|
'partial',
|
||||||
'partialRight',
|
'partialRight',
|
||||||
|
'rearg',
|
||||||
'tap',
|
'tap',
|
||||||
'throttle',
|
'throttle',
|
||||||
'thru',
|
'thru',
|
||||||
@@ -13140,7 +13204,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw a TypeError for falsey arguments', 21, function() {
|
test('should throw a TypeError for falsey arguments', 22, function() {
|
||||||
_.each(rejectFalsey, function(methodName) {
|
_.each(rejectFalsey, function(methodName) {
|
||||||
var expected = _.map(falsey, _.constant(true)),
|
var expected = _.map(falsey, _.constant(true)),
|
||||||
func = _[methodName];
|
func = _[methodName];
|
||||||
|
|||||||
Reference in New Issue
Block a user