mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add tests for MapCache values.
This commit is contained in:
19
test/test.js
19
test/test.js
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user