mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Test internal caches instead of cache modules.
This commit is contained in:
58
test/test.js
58
test/test.js
@@ -683,15 +683,11 @@
|
|||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
basePath = path.dirname(filePath);
|
basePath = path.dirname(filePath);
|
||||||
|
|
||||||
if (coverage || (isModularize && !(amd || isNpm))) {
|
if (isModularize && !(amd || isNpm)) {
|
||||||
lodashStable.each([
|
lodashStable.each([
|
||||||
'baseEach',
|
'baseEach',
|
||||||
'Hash',
|
|
||||||
'isIndex',
|
'isIndex',
|
||||||
'isIterateeCall',
|
'isIterateeCall'
|
||||||
'ListCache',
|
|
||||||
'MapCache',
|
|
||||||
'Stack'
|
|
||||||
], function(funcName) {
|
], function(funcName) {
|
||||||
var func = require(path.join(basePath, '_' + funcName));
|
var func = require(path.join(basePath, '_' + funcName));
|
||||||
_['_' + funcName] = func[funcName] || func['default'] || func;
|
_['_' + funcName] = func[funcName] || func['default'] || func;
|
||||||
@@ -998,23 +994,35 @@
|
|||||||
|
|
||||||
QUnit.module('map caches');
|
QUnit.module('map caches');
|
||||||
|
|
||||||
lodashStable.each(['_Hash', '_ListCache', '_MapCache', '_Stack'], function(ctorName) {
|
(function() {
|
||||||
var Ctor = _[ctorName];
|
var MapCache = _.memoize.Cache;
|
||||||
|
|
||||||
QUnit.test('`' + ctorName + '` should implement a `Map` interface', function(assert) {
|
var caches = {
|
||||||
assert.expect(82);
|
'Hash': new MapCache().__data__.hash.constructor,
|
||||||
|
'MapCache': MapCache
|
||||||
|
};
|
||||||
|
|
||||||
var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || {}];
|
var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || {}];
|
||||||
|
|
||||||
var pairs = lodashStable.map(keys, function(key, index) {
|
var pairs = lodashStable.map(keys, function(key, index) {
|
||||||
var lastIndex = keys.length - 1;
|
var lastIndex = keys.length - 1;
|
||||||
return [key, keys[lastIndex - index]];
|
return [key, keys[lastIndex - index]];
|
||||||
});
|
});
|
||||||
|
|
||||||
var cache = Ctor ? new Ctor(pairs) : undefined;
|
_.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
|
||||||
|
var stack = lodashStable.last(arguments);
|
||||||
|
caches.ListCache = stack.__data__.constructor;
|
||||||
|
caches.Stack = stack.constructor;
|
||||||
|
});
|
||||||
|
|
||||||
lodashStable.each(keys, function(key, index) {
|
lodashStable.each(['Hash', 'ListCache', 'MapCache', 'Stack'], function(ctorName) {
|
||||||
if (cache) {
|
QUnit.test('`' + ctorName + '` should implement a `Map` interface', function(assert) {
|
||||||
|
assert.expect(82);
|
||||||
|
|
||||||
|
var Ctor = caches[ctorName],
|
||||||
|
cache = new Ctor(pairs);
|
||||||
|
|
||||||
|
lodashStable.each(keys, function(key, index) {
|
||||||
var value = pairs[index][1];
|
var value = pairs[index][1];
|
||||||
|
|
||||||
assert.deepEqual(cache.get(key), value);
|
assert.deepEqual(cache.get(key), value);
|
||||||
@@ -1025,23 +1033,15 @@
|
|||||||
assert.strictEqual(cache['delete'](key), false);
|
assert.strictEqual(cache['delete'](key), false);
|
||||||
assert.strictEqual(cache.set(key, value), cache);
|
assert.strictEqual(cache.set(key, value), cache);
|
||||||
assert.strictEqual(cache.has(key), true);
|
assert.strictEqual(cache.has(key), true);
|
||||||
}
|
});
|
||||||
else {
|
|
||||||
skipAssert(assert, 8);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (cache) {
|
|
||||||
assert.strictEqual(cache.clear(), undefined);
|
assert.strictEqual(cache.clear(), undefined);
|
||||||
assert.ok(lodashStable.every(keys, function(key) {
|
assert.ok(lodashStable.every(keys, function(key) {
|
||||||
return !cache.has(key);
|
return !cache.has(key);
|
||||||
}));
|
}));
|
||||||
}
|
});
|
||||||
else {
|
|
||||||
skipAssert(assert, 2);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user