mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add fp tests for cherry-picked reduce and reduce iterating an object.
This commit is contained in:
@@ -218,21 +218,45 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
|
QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(4);
|
||||||
|
|
||||||
if (!document) {
|
if (!document) {
|
||||||
var args,
|
var args,
|
||||||
array = [1, 2, 3],
|
array = [1, 2, 3],
|
||||||
map = convert('map', _.map);
|
object = { 'a': 1, 'b': 2 },
|
||||||
|
isFIFO = _.keys(object)[0] == 'a',
|
||||||
|
map = convert('map', _.map),
|
||||||
|
reduce = convert('reduce', _.reduce);
|
||||||
|
|
||||||
map(function() {
|
map(function() {
|
||||||
args || (args = slice.call(arguments));
|
args || (args = slice.call(arguments));
|
||||||
})(array);
|
})(array);
|
||||||
|
|
||||||
assert.deepEqual(args, [1]);
|
assert.deepEqual(args, [1]);
|
||||||
|
|
||||||
|
args = undefined;
|
||||||
|
map(function() {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
})(object);
|
||||||
|
|
||||||
|
assert.deepEqual(args, isFIFO ? [1] : [2]);
|
||||||
|
|
||||||
|
args = undefined;
|
||||||
|
reduce(function() {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
})(0, array);
|
||||||
|
|
||||||
|
assert.deepEqual(args, [0, 1]);
|
||||||
|
|
||||||
|
args = undefined;
|
||||||
|
reduce(function() {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
})(0, object);
|
||||||
|
|
||||||
|
assert.deepEqual(args, isFIFO ? [0, 1] : [0, 2]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(assert);
|
skipTest(assert, 4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -571,13 +595,13 @@
|
|||||||
|
|
||||||
_.each(['reduce', 'reduceRight'], function(methodName) {
|
_.each(['reduce', 'reduceRight'], function(methodName) {
|
||||||
var func = fp[methodName],
|
var func = fp[methodName],
|
||||||
array = [1, 2, 3],
|
|
||||||
isReduce = methodName == 'reduce';
|
isReduce = methodName == 'reduce';
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
|
QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments when iterating an array', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var args;
|
var args,
|
||||||
|
array = [1, 2, 3];
|
||||||
|
|
||||||
func(function() {
|
func(function() {
|
||||||
args || (args = slice.call(arguments));
|
args || (args = slice.call(arguments));
|
||||||
@@ -585,6 +609,24 @@
|
|||||||
|
|
||||||
assert.deepEqual(args, isReduce ? [0, 1] : [0, 3]);
|
assert.deepEqual(args, isReduce ? [0, 1] : [0, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments when iterating an object', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var args,
|
||||||
|
object = { 'a': 1, 'b': 2 },
|
||||||
|
isFIFO = _.keys(object)[0] == 'a';
|
||||||
|
|
||||||
|
var expected = isFIFO
|
||||||
|
? (isReduce ? [0, 1] : [0, 2])
|
||||||
|
: (isReduce ? [0, 2] : [0, 1]);
|
||||||
|
|
||||||
|
func(function() {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
})(0, object);
|
||||||
|
|
||||||
|
assert.deepEqual(args, expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -812,9 +854,8 @@
|
|||||||
|
|
||||||
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.assignWith');
|
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.assignWith');
|
||||||
|
|
||||||
args = null;
|
args = undefined;
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
|
|
||||||
actual = fp.extendWith(function(objValue, srcValue) {
|
actual = fp.extendWith(function(objValue, srcValue) {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
return srcValue;
|
return srcValue;
|
||||||
@@ -822,12 +863,11 @@
|
|||||||
|
|
||||||
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.extendWith');
|
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.extendWith');
|
||||||
|
|
||||||
args = null;
|
|
||||||
value = { 'a': [1] };
|
|
||||||
|
|
||||||
var stack = { '__data__': { 'array': [], 'map': null } },
|
var stack = { '__data__': { 'array': [], 'map': null } },
|
||||||
expected = [[1], [2, 3], 'a', { 'a': [ 1 ] }, { 'a': [2, 3] }, stack];
|
expected = [[1], [2, 3], 'a', { 'a': [ 1 ] }, { 'a': [2, 3] }, stack];
|
||||||
|
|
||||||
|
args = undefined;
|
||||||
|
value = { 'a': [1] };
|
||||||
actual = fp.mergeWith(function(objValue, srcValue) {
|
actual = fp.mergeWith(function(objValue, srcValue) {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
if (_.isArray(objValue)) {
|
if (_.isArray(objValue)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user