Add large stack test to other cache tests.

This commit is contained in:
John-David Dalton
2016-05-02 19:42:23 -07:00
parent 264d68dec9
commit b8fa0d9b29

View File

@@ -323,6 +323,21 @@
(_.runInContext ? _.runInContext(root) : _) (_.runInContext ? _.runInContext(root) : _)
)); ));
/** Used to test pseudo private map caches. */
var mapCaches = (function() {
var MapCache = _.memoize.Cache;
var result = {
'Hash': new MapCache().__data__.hash.constructor,
'MapCache': MapCache
};
_.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
var stack = lodashStable.last(arguments);
result.ListCache = stack.__data__.constructor;
result.Stack = stack.constructor;
});
return result;
}());
/** Used to detect instrumented istanbul code coverage runs. */ /** Used to detect instrumented istanbul code coverage runs. */
var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) { var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) {
return /^(?:\$\$cov_\d+\$\$)$/.test(key); return /^(?:\$\$cov_\d+\$\$)$/.test(key);
@@ -995,13 +1010,6 @@
QUnit.module('map caches'); QUnit.module('map caches');
(function() { (function() {
var MapCache = _.memoize.Cache;
var caches = {
'Hash': new MapCache().__data__.hash.constructor,
'MapCache': MapCache
};
var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop]; var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop];
var pairs = lodashStable.map(keys, function(key, index) { var pairs = lodashStable.map(keys, function(key, index) {
@@ -1009,18 +1017,23 @@
return [key, keys[lastIndex - index]]; return [key, keys[lastIndex - index]];
}); });
_.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() { var largeStack = new mapCaches.Stack(pairs);
var stack = lodashStable.last(arguments);
caches.ListCache = stack.__data__.constructor; lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
caches.Stack = stack.constructor; largeStack.set({}, {});
}); });
lodashStable.each(['Hash', 'ListCache', 'MapCache', 'Stack'], function(ctorName) { var caches = {
QUnit.test('`' + ctorName + '` should implement a `Map` interface', function(assert) { 'hashes': new mapCaches.Hash(pairs),
assert.expect(82); 'list caches': new mapCaches.ListCache(pairs),
'map caches': new mapCaches.MapCache(pairs),
'stack caches': new mapCaches.Stack(pairs),
'large stacks': largeStack
};
var Ctor = caches[ctorName], lodashStable.forOwn(caches, function(cache, key) {
cache = new Ctor(pairs); QUnit.test('should implement a `Map` interface for ' + key, function(assert) {
assert.expect(82);
lodashStable.each(keys, function(key, index) { lodashStable.each(keys, function(key, index) {
var value = pairs[index][1]; var value = pairs[index][1];
@@ -2690,47 +2703,17 @@
}); });
QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) { QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
assert.expect(164); assert.expect(1);
var Stack, var actual;
keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop];
var pairs = lodashStable.map(keys, function(key, index) {
var lastIndex = keys.length - 1;
return [key, keys[lastIndex - index]];
});
_.cloneDeepWith({ 'a': 1 }, function() { _.cloneDeepWith({ 'a': 1 }, function() {
if (arguments.length > 1) { if (arguments.length > 1) {
Stack || (Stack = _.last(arguments).constructor); actual || (actual = _.last(arguments));
} }
}); });
var stacks = [new Stack(pairs), new Stack(pairs)]; assert.ok(actual instanceof mapCaches.Stack);
lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
stacks[1].set({}, {});
});
lodashStable.each(stacks, function(stack) {
lodashStable.each(keys, function(key, index) {
var value = pairs[index][1];
assert.deepEqual(stack.get(key), value);
assert.strictEqual(stack.has(key), true);
assert.strictEqual(stack['delete'](key), true);
assert.strictEqual(stack.has(key), false);
assert.strictEqual(stack.get(key), undefined);
assert.strictEqual(stack['delete'](key), false);
assert.strictEqual(stack.set(key, value), stack);
assert.strictEqual(stack.has(key), true);
});
assert.strictEqual(stack.clear(), undefined);
assert.ok(lodashStable.every(keys, function(key) {
return !stack.has(key);
}));
});
}); });
lodashStable.each(['clone', 'cloneDeep'], function(methodName) { lodashStable.each(['clone', 'cloneDeep'], function(methodName) {