mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +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) {
|
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) {
|
var iterateeAry = function(func, n) {
|
||||||
@@ -107,15 +119,17 @@ function baseConvert(util, name, func, options) {
|
|||||||
|
|
||||||
var overArg = function(func, iteratee, retArg) {
|
var overArg = function(func, iteratee, retArg) {
|
||||||
return function() {
|
return function() {
|
||||||
var length = arguments.length,
|
var length = arguments.length;
|
||||||
args = Array(length);
|
if (!length) {
|
||||||
|
return func();
|
||||||
|
}
|
||||||
|
var args = Array(length);
|
||||||
while (length--) {
|
while (length--) {
|
||||||
args[length] = arguments[length];
|
args[length] = arguments[length];
|
||||||
}
|
}
|
||||||
args[0] = iteratee(args[0]);
|
var index = config.rearg ? 0 : (length - 1);
|
||||||
var result = func.apply(undefined, args);
|
args[index] = iteratee(args[index]);
|
||||||
return retArg ? args[0] : result;
|
return func.apply(undefined, args);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -197,10 +211,11 @@ function baseConvert(util, name, func, options) {
|
|||||||
reargIndexes = mapping.iterateeRearg[name],
|
reargIndexes = mapping.iterateeRearg[name],
|
||||||
spreadStart = mapping.methodSpread[name];
|
spreadStart = mapping.methodSpread[name];
|
||||||
|
|
||||||
|
result = wrapped;
|
||||||
if (config.fixed) {
|
if (config.fixed) {
|
||||||
result = spreadStart === undefined
|
result = spreadStart === undefined
|
||||||
? ary(wrapped, cap)
|
? ary(result, cap)
|
||||||
: spread(wrapped, spreadStart);
|
: spread(result, spreadStart);
|
||||||
}
|
}
|
||||||
if (config.rearg && cap > 1 && (forceRearg || !mapping.skipRearg[name])) {
|
if (config.rearg && cap > 1 && (forceRearg || !mapping.skipRearg[name])) {
|
||||||
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
|
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
|
||||||
@@ -221,7 +236,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
return !result;
|
return !result;
|
||||||
});
|
});
|
||||||
|
|
||||||
result || (result = func);
|
result || (result = wrapped);
|
||||||
if (mapping.placeholder[name]) {
|
if (mapping.placeholder[name]) {
|
||||||
func.placeholder = result.placeholder = placeholder;
|
func.placeholder = result.placeholder = placeholder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,41 @@
|
|||||||
assert.deepEqual(remove(), []);
|
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) {
|
QUnit.test('should respect the `cap` option', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user