mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Enable shortcut fusion for _.find and _.findLast.
This commit is contained in:
committed by
John-David Dalton
parent
1e344455b8
commit
39068730e2
38
test/test.js
38
test/test.js
@@ -3977,6 +3977,44 @@
|
||||
|
||||
deepEqual(actual, expecting);
|
||||
});
|
||||
|
||||
if (!/(Index|Key)/.test(methodName)) {
|
||||
test('should enable shortcut fusion in chaining', 2, function() {
|
||||
if (!isNpm) {
|
||||
var callCount = 0;
|
||||
var items = _.range(0, LARGE_ARRAY_SIZE + 1);
|
||||
var expectedCalls = LARGE_ARRAY_SIZE / 2 + 1;
|
||||
var expected = LARGE_ARRAY_SIZE / 2 - 25;
|
||||
var result = _(items).map(function(x) {
|
||||
callCount++;
|
||||
return x - 25;
|
||||
})[methodName](function(x) {
|
||||
return x === expected;
|
||||
});
|
||||
strictEqual(callCount, expectedCalls);
|
||||
strictEqual(result, expected);
|
||||
} else {
|
||||
skipTest(2);
|
||||
}
|
||||
});
|
||||
|
||||
test('should function when the only action in chaining', 2, function() {
|
||||
if (!isNpm) {
|
||||
var callCount = 0;
|
||||
var items = _.range(0, LARGE_ARRAY_SIZE + 1);
|
||||
var expectedCalls = LARGE_ARRAY_SIZE / 2 + 1;
|
||||
var expected = LARGE_ARRAY_SIZE / 2;
|
||||
var result = _(items)[methodName](function(x) {
|
||||
callCount++;
|
||||
return x === expected;
|
||||
});
|
||||
strictEqual(callCount, expectedCalls);
|
||||
strictEqual(result, expected);
|
||||
} else {
|
||||
skipTest(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}());
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user