mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Ensure fp options works when applied individually.
This commit is contained in:
@@ -89,7 +89,19 @@ function baseConvert(util, name, func, options) {
|
||||
};
|
||||
|
||||
var immutWrap = function(func, cloner) {
|
||||
return overArg(func, cloner, true);
|
||||
return function() {
|
||||
var length = arguments.length;
|
||||
if (!length) {
|
||||
return result;
|
||||
}
|
||||
var args = Array(length);
|
||||
while (length--) {
|
||||
args[length] = arguments[length];
|
||||
}
|
||||
var result = args[0] = cloner(args[0]);
|
||||
func.apply(undefined, args);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
var iterateeAry = function(func, n) {
|
||||
@@ -107,15 +119,17 @@ function baseConvert(util, name, func, options) {
|
||||
|
||||
var overArg = function(func, iteratee, retArg) {
|
||||
return function() {
|
||||
var length = arguments.length,
|
||||
args = Array(length);
|
||||
|
||||
var length = arguments.length;
|
||||
if (!length) {
|
||||
return func();
|
||||
}
|
||||
var args = Array(length);
|
||||
while (length--) {
|
||||
args[length] = arguments[length];
|
||||
}
|
||||
args[0] = iteratee(args[0]);
|
||||
var result = func.apply(undefined, args);
|
||||
return retArg ? args[0] : result;
|
||||
var index = config.rearg ? 0 : (length - 1);
|
||||
args[index] = iteratee(args[index]);
|
||||
return func.apply(undefined, args);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -197,10 +211,11 @@ function baseConvert(util, name, func, options) {
|
||||
reargIndexes = mapping.iterateeRearg[name],
|
||||
spreadStart = mapping.methodSpread[name];
|
||||
|
||||
result = wrapped;
|
||||
if (config.fixed) {
|
||||
result = spreadStart === undefined
|
||||
? ary(wrapped, cap)
|
||||
: spread(wrapped, spreadStart);
|
||||
? ary(result, cap)
|
||||
: spread(result, spreadStart);
|
||||
}
|
||||
if (config.rearg && cap > 1 && (forceRearg || !mapping.skipRearg[name])) {
|
||||
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
|
||||
@@ -221,7 +236,7 @@ function baseConvert(util, name, func, options) {
|
||||
return !result;
|
||||
});
|
||||
|
||||
result || (result = func);
|
||||
result || (result = wrapped);
|
||||
if (mapping.placeholder[name]) {
|
||||
func.placeholder = result.placeholder = placeholder;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,41 @@
|
||||
assert.deepEqual(remove(), []);
|
||||
});
|
||||
|
||||
QUnit.test('should accept a variety of options', function(assert) {
|
||||
assert.expect(8);
|
||||
|
||||
var array = [1, 2, 3, 4],
|
||||
predicate = function(n) { return n % 2 == 0; },
|
||||
value = _.clone(array),
|
||||
remove = convert('remove', _.remove, { 'cap': false }),
|
||||
actual = remove(function(n, index) { return index % 2 == 0; })(value);
|
||||
|
||||
assert.deepEqual(value, [1, 2, 3, 4]);
|
||||
assert.deepEqual(actual, [2, 4]);
|
||||
|
||||
remove = convert('remove', _.remove, { 'curry': false });
|
||||
actual = remove(predicate);
|
||||
|
||||
assert.deepEqual(actual, []);
|
||||
|
||||
var trim = convert('trim', _.trim, { 'fixed': false });
|
||||
assert.strictEqual(trim('_-abc-_', '_-'), 'abc');
|
||||
|
||||
value = _.clone(array);
|
||||
remove = convert('remove', _.remove, { 'immutable': false });
|
||||
actual = remove(predicate)(value);
|
||||
|
||||
assert.deepEqual(value, [1, 3]);
|
||||
assert.deepEqual(actual, [2, 4]);
|
||||
|
||||
value = _.clone(array);
|
||||
remove = convert('remove', _.remove, { 'rearg': false });
|
||||
actual = remove(value, predicate);
|
||||
|
||||
assert.deepEqual(value, [1, 2, 3, 4]);
|
||||
assert.deepEqual(actual, [1, 3]);
|
||||
});
|
||||
|
||||
QUnit.test('should respect the `cap` option', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user