slice = arrayProto.slice,
WeakMap = root.WeakMap;
- // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
- root.msWDfn = undefined;
-
/*--------------------------------------------------------------------------*/
/** Use a single "load" function. */
};
}());
- var allFalseOptions = {
- 'cap': false,
- 'curry': false,
- 'fixed': false,
- 'immutable': false,
- 'rearg': false
- };
-
var fp = root.fp
? (fp = _.noConflict(), _ = root._, fp)
: convert(_.runInContext());
console.log('Running lodash/fp tests.');
}
- QUnit.module('convert module');
+ QUnit.module('convert');
(function() {
- QUnit.test('should work with `name` and `func`', function(assert) {
- assert.expect(2);
-
- var array = [1, 2, 3, 4],
- remove = convert('remove', _.remove);
-
- var actual = remove(function(n) {
- return n % 2 == 0;
- })(array);
-
- assert.deepEqual(array, [1, 2, 3, 4]);
- assert.deepEqual(actual, [1, 3]);
- });
-
- QUnit.test('should work with `name`, `func`, and `options`', function(assert) {
- assert.expect(3);
-
- var array = [1, 2, 3, 4],
- remove = convert('remove', _.remove, allFalseOptions);
-
- var actual = remove(array, function(n, index) {
- return index % 2 == 0;
- });
-
- assert.deepEqual(array, [2, 4]);
- assert.deepEqual(actual, [1, 3]);
- assert.deepEqual(remove(), []);
- });
+ var allFalseOptions = {
+ 'cap': false,
+ 'curry': false,
+ 'fixed': false,
+ 'immutable': false,
+ 'rearg': false
+ };
- QUnit.test('should work with an object', function(assert) {
+ QUnit.test('should work when given an object', function(assert) {
assert.expect(2);
if (!document) {
}
});
- QUnit.test('should work with an object and `options`', function(assert) {
- assert.expect(3);
+ QUnit.test('should only add a `placeholder` property if needed', function(assert) {
+ assert.expect(2);
if (!document) {
- var array = [1, 2, 3, 4],
- lodash = convert({ 'remove': _.remove }, allFalseOptions);
+ var methodNames = _.keys(mapping.placeholder),
+ expected = _.map(methodNames, _.constant(true));
- var actual = lodash.remove(array, function(n, index) {
- return index % 2 == 0;
+ var actual = _.map(methodNames, function(methodName) {
+ var object = {};
+ object[methodName] = _[methodName];
+
+ var lodash = convert(object);
+ return methodName in lodash;
});
- assert.deepEqual(array, [2, 4]);
- assert.deepEqual(actual, [1, 3]);
- assert.deepEqual(lodash.remove(), []);
+ assert.deepEqual(actual, expected);
+
+ var lodash = convert({ 'add': _.add });
+ assert.notOk('placeholder' in lodash);
}
else {
- skipAssert(assert, 3);
+ skipAssert(assert, 2);
}
});
- QUnit.test('should work with lodash and `options`', function(assert) {
- assert.expect(3);
-
- var array = [1, 2, 3, 4],
- lodash = convert(_.runInContext(), allFalseOptions);
-
- var actual = lodash.remove(array, function(n, index) {
- return index % 2 == 0;
- });
-
- assert.deepEqual(array, [2, 4]);
- assert.deepEqual(actual, [1, 3]);
- assert.deepEqual(lodash.remove(), []);
- });
-
- QUnit.test('should work with `runInContext` and `options`', function(assert) {
+ QUnit.test('should accept an `options` argument', function(assert) {
assert.expect(3);
var array = [1, 2, 3, 4],
- runInContext = convert('runInContext', _.runInContext, allFalseOptions),
- lodash = runInContext();
+ remove = convert('remove', _.remove, allFalseOptions);
- var actual = lodash.remove(array, function(n, index) {
+ var actual = remove(array, function(n, index) {
return index % 2 == 0;
});
assert.deepEqual(array, [2, 4]);
assert.deepEqual(actual, [1, 3]);
- assert.deepEqual(lodash.remove(), []);
+ assert.deepEqual(remove(), []);
});
QUnit.test('should accept a variety of options', function(assert) {
assert.strictEqual(add('2')('1'), '12');
});
- QUnit.test('should only add a `placeholder` property if needed', function(assert) {
- assert.expect(2);
-
- if (!document) {
- var methodNames = _.keys(mapping.placeholder),
- expected = _.map(methodNames, _.constant(true));
-
- var actual = _.map(methodNames, function(methodName) {
- var object = {};
- object[methodName] = _[methodName];
-
- var lodash = convert(object);
- return methodName in lodash;
- });
-
- assert.deepEqual(actual, expected);
-
- var lodash = convert({ 'add': _.add });
- assert.notOk('placeholder' in lodash);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('method.convert');
+ QUnit.test('should use `options` in `runInContext`', function(assert) {
+ assert.expect(3);
- (function() {
- QUnit.test('should exist on unconverted methods', function(assert) {
- assert.expect(2);
+ var array = [1, 2, 3, 4],
+ runInContext = convert('runInContext', _.runInContext, allFalseOptions),
+ lodash = runInContext();
- var array = [],
- isArray = fp.isArray.convert({ 'curry': true });
+ var actual = lodash.remove(array, function(n, index) {
+ return index % 2 == 0;
+ });
- assert.strictEqual(fp.isArray(array), true);
- assert.strictEqual(isArray()(array), true);
+ assert.deepEqual(array, [2, 4]);
+ assert.deepEqual(actual, [1, 3]);
+ assert.deepEqual(lodash.remove(), []);
});
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('convert methods');
- _.each(['fp.convert', 'method.convert'], function(methodName) {
- var isFp = methodName == 'fp.convert',
- func = isFp ? fp.convert : fp.remove.convert;
-
- QUnit.test('`' + methodName + '` should work with an object', function(assert) {
+ QUnit.test('should work when given lodash and `options`', function(assert) {
assert.expect(3);
var array = [1, 2, 3, 4],
- lodash = func(allFalseOptions),
- remove = isFp ? lodash.remove : lodash;
+ lodash = convert(_.runInContext(), allFalseOptions);
- var actual = remove(array, function(n, index) {
+ var actual = lodash.remove(array, function(n, index) {
return index % 2 == 0;
});
assert.deepEqual(array, [2, 4]);
assert.deepEqual(actual, [1, 3]);
- assert.deepEqual(remove(), []);
+ assert.deepEqual(lodash.remove(), []);
});
- QUnit.test('`' + methodName + '` should extend existing configs', function(assert) {
- assert.expect(2);
+ QUnit.test('should work when given an object and `options`', function(assert) {
+ assert.expect(3);
- var array = [1, 2, 3, 4],
- lodash = func({ 'cap': false }),
- remove = (isFp ? lodash.remove : lodash).convert({ 'rearg': false });
+ if (!document) {
+ var array = [1, 2, 3, 4],
+ lodash = convert({ 'remove': _.remove }, allFalseOptions);
- var actual = remove(array)(function(n, index) {
- return index % 2 == 0;
- });
+ var actual = lodash.remove(array, function(n, index) {
+ return index % 2 == 0;
+ });
- assert.deepEqual(array, [1, 2, 3, 4]);
- assert.deepEqual(actual, [2, 4]);
+ assert.deepEqual(array, [2, 4]);
+ assert.deepEqual(actual, [1, 3]);
+ assert.deepEqual(lodash.remove(), []);
+ }
+ else {
+ skipAssert(assert, 3);
+ }
});
- });
+ }());
/*--------------------------------------------------------------------------*/
assert.expect(1);
var funcMethods = [
- 'after', 'ary', 'before', 'bind', 'bindKey', 'curryN', 'debounce',
- 'delay', 'overArgs', 'partial', 'partialRight', 'rearg', 'throttle',
- 'wrap'
+ 'after', 'ary', 'before', 'bind', 'bindKey', 'curryN', 'debounce', 'delay',
+ 'overArgs', 'partial', 'partialRight', 'rearg', 'throttle', 'wrap'
];
var exceptions = _.difference(funcMethods.concat('matchesProperty'), ['cloneDeepWith', 'cloneWith', 'delay']),
assert.expect(10);
var array = ['a', 'b', 'c'],
- other = ['b', 'd', 'b'],
+ other = ['b', 'b', 'd'],
object = { 'a': 1, 'b': 2, 'c': 2 },
actual = fp.difference(array)(other);
actual = fp.uniqBy(_.identity, other);
assert.deepEqual(actual, ['b', 'd'], 'fp.uniqBy');
- actual = fp.without(array)(other);
+ actual = fp.without('b')(array);
assert.deepEqual(actual, ['a', 'c'], 'fp.without');
actual = fp.xor(other)(array);
deepObject = { 'a': { 'b': 2, 'c': 3 } };
QUnit.test('should not mutate values', function(assert) {
- assert.expect(42);
+ assert.expect(38);
function Foo() {}
Foo.prototype = { 'b': 2 };
assert.deepEqual(value, deepObject, 'fp.unset');
assert.deepEqual(actual, { 'a': { 'c': 3 } }, 'fp.unset');
-
- value = _.cloneDeep(deepObject);
- actual = fp.update('a.b')(function(n) { return n * n; })(value);
-
- assert.deepEqual(value, deepObject, 'fp.update');
- assert.deepEqual(actual, { 'a': { 'b': 4, 'c': 3 } }, 'fp.update');
-
- value = _.cloneDeep(deepObject);
- actual = fp.updateWith(Object)('d.e')(_.constant(4))(value);
-
- assert.deepEqual(value, deepObject, 'fp.updateWith');
- assert.deepEqual(actual, { 'a': { 'b': 2, 'c': 3 }, 'd': { 'e': 4 } }, 'fp.updateWith');
});
}());
QUnit.module('placeholder methods');
(function() {
- QUnit.test('should use `fp` as the default placeholder', function(assert) {
- assert.expect(3);
-
- var actual = fp.add(fp, 'b')('a');
- assert.strictEqual(actual, 'ab');
-
- actual = fp.slice(fp, 2)(1)(['a', 'b', 'c']);
- assert.deepEqual(actual, ['b']);
-
- actual = fp.fill(fp, 2)(1, '*')([1, 2, 3]);
- assert.deepEqual(actual, [1, '*', 3]);
- });
-
- QUnit.test('should support `fp.placeholder`', function(assert) {
+ QUnit.test('should support placeholders', function(assert) {
assert.expect(6);
_.each([[], fp.__], function(ph) {
QUnit.module('set methods');
(function() {
+ var array = [1, 2, 3],
+ object = { 'a': 1 },
+ deepObject = { 'a': { 'b': 2, 'c': 3 } };
+
QUnit.test('should only clone objects in `path`', function(assert) {
- assert.expect(11);
+ assert.expect(8);
- var object = { 'a': { 'b': 2, 'c': 3 }, 'd': { 'e': 4 } },
+ var object = { 'a': { 'b': { 'c': 1 }, 'd': { 'e': 1 } } },
value = _.cloneDeep(object),
- actual = fp.set('a.b.c.d', 5, value);
+ actual = fp.set('a.b.c.d.e', 3, value);
- assert.ok(_.isObject(actual.a.b), 'fp.set');
- assert.ok(_.isNumber(actual.a.b), 'fp.set');
+ assert.ok(_.isObject(actual.a.b.c), 'fp.set');
+ assert.ok(_.isNumber(actual.a.b.c), 'fp.set');
- assert.strictEqual(actual.a.b.c.d, 5, 'fp.set');
+ assert.strictEqual(actual.a.b.c.d.e, 3, 'fp.set');
assert.strictEqual(actual.d, value.d, 'fp.set');
value = _.cloneDeep(object);
- actual = fp.setWith(Object)('[0][1]')('a')(value);
+ actual = fp.setWith(Object)('a.b.c')(2)(value);
- assert.deepEqual(actual[0], { '1': 'a' }, 'fp.setWith');
+ assert.strictEqual(actual.a.b.c, 2, 'fp.setWith');
+ assert.strictEqual(actual.d, value.d, 'fp.setWith');
value = _.cloneDeep(object);
actual = fp.unset('a.b')(value);
- assert.notOk('b' in actual.a, 'fp.unset');
- assert.strictEqual(actual.a.c, value.a.c, 'fp.unset');
-
- value = _.cloneDeep(object);
- actual = fp.update('a.b')(function(n) { return n * n; })(value);
-
- assert.strictEqual(actual.a.b, 4, 'fp.update');
- assert.strictEqual(actual.d, value.d, 'fp.update');
-
- value = _.cloneDeep(object);
- actual = fp.updateWith(Object)('[0][1]')(_.constant('a'))(value);
-
- assert.deepEqual(actual[0], { '1': 'a' }, 'fp.updateWith');
- assert.strictEqual(actual.d, value.d, 'fp.updateWith');
+ assert.notOk('b' in actual, 'fp.unset');
+ assert.strictEqual(actual.d, value.d, 'fp.unset');
});
}());
QUnit.module('with methods');
(function() {
- var object = { 'a': 1 };
+ var array = [1, 2, 3],
+ object = { 'a': 1 };
QUnit.test('should provide the correct `customizer` arguments', function(assert) {
- assert.expect(7);
+ assert.expect(4);
var args,
value = _.clone(object);
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.extendWith');
- var iteration = 0,
- objects = [{ 'a': 1 }, { 'a': 2 }],
- stack = { '__data__': { 'array': [[objects[0], objects[1]]], 'map': null } },
- expected = [1, 2, 'a', objects[0], objects[1], stack];
-
- args = undefined;
-
- fp.isEqualWith(function() {
- if (++iteration == 2) {
- args = _.map(arguments, _.cloneDeep);
- }
- })(objects[0])(objects[1]);
-
- args[5] = _.omitBy(args[5], _.isFunction);
- assert.deepEqual(args, expected, 'fp.isEqualWith');
-
- args = undefined;
- stack = { '__data__': { 'array': [], 'map': null } };
- expected = [2, 1, 'a', objects[1], objects[0], stack];
-
- fp.isMatchWith(function() {
- args || (args = _.map(arguments, _.cloneDeep));
- })(objects[0])(objects[1]);
-
- args[5] = _.omitBy(args[5], _.isFunction);
- assert.deepEqual(args, expected, 'fp.isMatchWith');
+ var stack = { '__data__': { 'array': [], 'map': null } },
+ expected = [[1], [2, 3], 'a', { 'a': [1] }, { 'a': [2, 3] }, stack];
args = undefined;
value = { 'a': [1] };
- expected = [[1], [2, 3], 'a', { 'a': [1] }, { 'a': [2, 3] }, stack];
fp.mergeWith(function() {
args || (args = _.map(arguments, _.cloneDeep));
})('b.c')(2)(value);
assert.deepEqual(args, [undefined, 'b', { 'a': 1 }], 'fp.setWith');
-
- args = undefined;
- value = _.clone(object);
-
- fp.updateWith(function() {
- args || (args = _.map(arguments, _.cloneDeep));
- })('b.c')(_.constant(2))(value);
-
- assert.deepEqual(args, [undefined, 'b', { 'a': 1 }], 'fp.updateWith');
});
}());
var func = fp[methodName],
isAdd = methodName == 'add';
- QUnit.test('`fp.' + methodName + '` should not have `rearg` applied', function(assert) {
+ QUnit.test('`fp.' + methodName + '` should have `rearg` applied', function(assert) {
assert.expect(1);
assert.strictEqual(func('1')('2'), isAdd ? '12' : -1);
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.divide and fp.multiply');
-
- _.each(['divide', 'multiply'], function(methodName) {
- var func = fp[methodName],
- isDivide = methodName == 'divide';
-
- QUnit.test('`fp.' + methodName + '` should not have `rearg` applied', function(assert) {
- assert.expect(1);
-
- assert.strictEqual(func('2')('4'), isDivide ? 0.5 : 8);
- });
- });
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.extend');
(function() {
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.flatMapDepth');
-
- (function() {
- QUnit.test('should have an argument order of `iteratee`, `depth`, then `collection`', function(assert) {
- assert.expect(2);
-
- function duplicate(n) {
- return [[[n, n]]];
- }
-
- var array = [1, 2],
- object = { 'a': 1, 'b': 2 },
- expected = [[1, 1], [2, 2]];
-
- assert.deepEqual(fp.flatMapDepth(duplicate)(2)(array), expected);
- assert.deepEqual(fp.flatMapDepth(duplicate)(2)(object), expected);
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.flow and fp.flowRight');
_.each(['flow', 'flowRight'], function(methodName) {
QUnit.module('fp.getOr');
- (function() {
- QUnit.test('should accept a `defaultValue` param', function(assert) {
- assert.expect(1);
+ QUnit.test('should accept a `defaultValue` param', function(assert) {
+ assert.expect(1);
- var actual = fp.getOr('default')('path')({});
- assert.strictEqual(actual, 'default');
- });
- }());
+ var actual = fp.getOr('default')('path')({});
+ assert.strictEqual(actual, 'default');
+ });
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.invoke');
-
- (function() {
- QUnit.test('should not accept an `args` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.invoke('toUpperCase')('a');
- assert.strictEqual(actual, 'A');
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('fp.invokeMap');
-
- (function() {
- QUnit.test('should not accept an `args` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.invokeMap('toUpperCase')(['a', 'b']);
- assert.deepEqual(actual, ['A', 'B']);
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('fp.invokeArgs');
-
- (function() {
- QUnit.test('should accept an `args` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.invokeArgs('concat')(['b', 'c'])('a');
- assert.strictEqual(actual, 'abc');
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('fp.invokeArgsMap');
-
- (function() {
- QUnit.test('should accept an `args` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.invokeArgsMap('concat')(['b', 'c'])(['a', 'A']);
- assert.deepEqual(actual, ['abc', 'Abc']);
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.iteratee');
(function() {
var args,
object = { 'a': 1 };
- fp.mapKeys(function() {
+ var actual = fp.mapKeys(function() {
args || (args = slice.call(arguments));
}, object);
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.over');
-
- (function() {
- QUnit.test('should not cap iteratee args', function(assert) {
- assert.expect(2);
-
- _.each([fp.over, convert('over', _.over)], function(func) {
- var over = func([Math.max, Math.min]);
- assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
- });
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.omitBy and fp.pickBy');
_.each(['omitBy', 'pickBy'], function(methodName) {
/*--------------------------------------------------------------------------*/
- QUnit.module('padChars methods');
-
- _.each(['padChars', 'padCharsStart', 'padCharsEnd'], function(methodName) {
- var func = fp[methodName],
- isPad = methodName == 'padChars',
- isStart = methodName == 'padCharsStart';
-
- QUnit.test('`_.' + methodName + '` should truncate pad characters to fit the pad length', function(assert) {
- assert.expect(1);
-
- if (isPad) {
- assert.strictEqual(func('_-')(8)('abc'), '_-abc_-_');
- } else {
- assert.strictEqual(func('_-')(6)('abc'), isStart ? '_-_abc' : 'abc_-_');
- }
- });
- });
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.partial and fp.partialRight');
_.each(['partial', 'partialRight'], function(methodName) {
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.restFrom');
-
- (function() {
- QUnit.test('should accept a `start` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.restFrom(2)(function() {
- return slice.call(arguments);
- })('a', 'b', 'c', 'd');
-
- assert.deepEqual(actual, ['a', 'b', ['c', 'd']]);
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
QUnit.module('fp.runInContext');
(function() {
/*--------------------------------------------------------------------------*/
- QUnit.module('fp.spreadFrom');
-
- (function() {
- QUnit.test('should accept a `start` param', function(assert) {
- assert.expect(1);
-
- var actual = fp.spreadFrom(2)(function() {
- return slice.call(arguments);
- })('a', 'b', ['c', 'd']);
-
- assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
- });
- }());
-
- /*--------------------------------------------------------------------------*/
-
- QUnit.module('trimChars methods');
+ QUnit.module('fp.trimChars');
_.each(['trimChars', 'trimCharsStart', 'trimCharsEnd'], function(methodName, index) {
var func = fp[methodName],