Add tests for MapCache values.

This commit is contained in:
John-David Dalton
2015-12-28 15:18:45 -06:00
parent a5b733998d
commit 95c6dd8992

View File

@@ -12701,25 +12701,26 @@
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]; cacheKeys = [true, false, 1, -Infinity, NaN, { 'a': 1 }, null, 'a', symbol, undefined];
lodashStable.times(2, function(index) { lodashStable.times(2, function(index) {
var func = (index ? (lodashBizarro || {}) : _).memoize; var func = (index ? (lodashBizarro || {}) : _).memoize,
memoized = func ? func(getValue) : noop,
var memoized = !func ? noop : func(function(key) { cache = memoized.cache;
return 'value:' + lodashStable.indexOf(cacheKeys, key);
});
var cache = memoized.cache;
lodashStable.each(cacheKeys, function(key, index) { lodashStable.each(cacheKeys, function(key, index) {
if (func) { if (func) {
var value = 'value:' + index; var value = getValue(key);
memoized(key); memoized(key);
assert.deepEqual(cache.get(key), value);
assert.strictEqual(cache.has(key), true); assert.strictEqual(cache.has(key), true);
assert.strictEqual(cache.get(key), value);
assert.strictEqual(cache['delete'](key), true); assert.strictEqual(cache['delete'](key), true);
assert.strictEqual(cache.has(key), false); assert.strictEqual(cache.has(key), false);
assert.strictEqual(cache.get(key), undefined); assert.strictEqual(cache.get(key), undefined);