mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Cleanup MapCache tests.
This commit is contained in:
29
test/test.js
29
test/test.js
@@ -12703,23 +12703,22 @@
|
|||||||
QUnit.test('should implement a `Map` interface on the cache object', function(assert) {
|
QUnit.test('should implement a `Map` interface on the cache object', function(assert) {
|
||||||
assert.expect(164);
|
assert.expect(164);
|
||||||
|
|
||||||
function getValue(key) {
|
|
||||||
var lastIndex = cacheKeys.length - 1;
|
|
||||||
return cacheKeys[lastIndex - lodashStable.indexOf(cacheKeys, key)];
|
|
||||||
}
|
|
||||||
|
|
||||||
var symbol = Symbol ? Symbol() : undefined,
|
var symbol = Symbol ? Symbol() : undefined,
|
||||||
cacheKeys = [true, false, 1, -Infinity, NaN, { 'a': 1 }, null, 'a', symbol, undefined];
|
keys = [true, false, 1, -Infinity, NaN, { 'a': 1 }, null, 'a', symbol, undefined];
|
||||||
|
|
||||||
|
var pairs = lodashStable.map(keys, function(key, index) {
|
||||||
|
var lastIndex = keys.length - 1;
|
||||||
|
return [key, keys[lastIndex - index]];
|
||||||
|
});
|
||||||
|
|
||||||
lodashStable.times(2, function(index) {
|
lodashStable.times(2, function(index) {
|
||||||
var func = (index ? (lodashBizarro || {}) : _).memoize,
|
var memoize = (index ? (lodashBizarro || {}) : _).memoize,
|
||||||
memoized = func ? func(getValue) : noop,
|
Cache = memoize ? memoize.Cache : undefined,
|
||||||
cache = memoized.cache;
|
cache = Cache ? new Cache(pairs) : undefined;
|
||||||
|
|
||||||
lodashStable.each(cacheKeys, function(key, index) {
|
lodashStable.each(keys, function(key, index) {
|
||||||
if (func) {
|
if (cache) {
|
||||||
var value = getValue(key);
|
var value = pairs[index][1];
|
||||||
memoized(key);
|
|
||||||
|
|
||||||
assert.deepEqual(cache.get(key), value);
|
assert.deepEqual(cache.get(key), value);
|
||||||
assert.strictEqual(cache.has(key), true);
|
assert.strictEqual(cache.has(key), true);
|
||||||
@@ -12735,9 +12734,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (func) {
|
if (cache) {
|
||||||
assert.strictEqual(cache.clear(), undefined);
|
assert.strictEqual(cache.clear(), undefined);
|
||||||
assert.ok(lodashStable.every(cacheKeys, function(key) {
|
assert.ok(lodashStable.every(keys, function(key) {
|
||||||
return !cache.has(key);
|
return !cache.has(key);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user