Add test for modularized flow and flowRight.

This commit is contained in:
jdalton
2015-05-16 08:02:14 -07:00
parent d6937baa8e
commit 48a56a848a

View File

@@ -624,9 +624,10 @@
// Expose internal modules for better code coverage. // Expose internal modules for better code coverage.
_.attempt(function() { _.attempt(function() {
if (isModularize && !(amd || isNpm)) { if (isModularize && !(amd || isNpm)) {
_.each(['baseEach', 'isIndex', 'isIterateeCall', 'isLength'], function(funcName) { _.each(['internal/baseEach', 'internal/isIndex', 'internal/isIterateeCall',
var path = require('path'), 'internal/isLength', 'function/flow', 'function/flowRight'], function(id) {
func = require(path.join(path.dirname(filePath), 'internal', funcName + '.js')); var func = require(id),
funcName = _.last(id.split('/'));
_['_' + funcName] = func[funcName] || func['default'] || func; _['_' + funcName] = func[funcName] || func['default'] || func;
}); });
@@ -2312,9 +2313,9 @@
notStrictEqual(combined, _.identity); notStrictEqual(combined, _.identity);
}); });
test('`_.' + methodName + '` should support shortcut fusion', 3, function() { test('`_.' + methodName + '` should support shortcut fusion', 6, function() {
var filterCount = 0, var filterCount,
mapCount = 0; mapCount;
var map = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2), var map = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
filter = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2), filter = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
@@ -2324,19 +2325,27 @@
partialFilter = filter(function(value) { filterCount++; return value % 2 == 0; }), partialFilter = filter(function(value) { filterCount++; return value % 2 == 0; }),
partialTake = take(2); partialTake = take(2);
var combined = isFlow _.times(2, function(index) {
? func(partialMap, partialFilter, _.compact, partialTake) var fn = index ? _['_' + methodName] : func;
: func(partialTake, _.compact, partialFilter, partialMap); if (!fn) {
skipTest(3);
return;
}
var combined = isFlow
? fn(partialMap, partialFilter, _.compact, partialTake)
: fn(partialTake, _.compact, partialFilter, partialMap);
deepEqual(combined(_.range(100)), [4, 16]); filterCount = mapCount = 0;
deepEqual(combined(_.range(100)), [4, 16]);
if (!isNpm && WeakMap && _.support.funcNames) { if (!isNpm && WeakMap && _.support.funcNames) {
strictEqual(filterCount, 5, 'filterCount'); strictEqual(filterCount, 5, 'filterCount');
strictEqual(mapCount, 5, 'mapCount'); strictEqual(mapCount, 5, 'mapCount');
} }
else { else {
skipTest(2); skipTest(2);
} }
});
}); });
test('`_.' + methodName + '` should work with curried functions with placeholders', 1, function() { test('`_.' + methodName + '` should work with curried functions with placeholders', 1, function() {