From f14a829d7627c6face7dfbc8663b73fafa0e0ff8 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Tue, 25 Feb 2014 14:54:44 -0700 Subject: [PATCH] Fixes #105. Stable Version 3.0.0-beta.2 --- CHANGELOG.md | 5 + bower.json | 2 +- dist/angular-cache.js | 320 +++++++++--------- dist/angular-cache.min.js | 4 +- karma.start.js | 10 +- package.json | 2 +- src/DSBinaryHeap/index.js | 303 +++++++++-------- src/DSCache/index.js | 3 +- src/index.js | 2 +- test/unit/DSBinaryHeap/index.peek.test.js | 4 +- test/unit/DSBinaryHeap/index.pop.test.js | 4 +- test/unit/DSBinaryHeap/index.push.test.js | 4 +- test/unit/DSBinaryHeap/index.remove.test.js | 4 +- .../unit/DSBinaryHeap/index.removeAll.test.js | 4 +- test/unit/DSBinaryHeap/index.test.js | 4 +- test/unit/DSCache/index.destroy.test.js | 8 +- test/unit/DSCache/index.get.test.js | 22 +- test/unit/DSCache/index.info.test.js | 14 +- test/unit/DSCache/index.keySet.test.js | 2 +- test/unit/DSCache/index.keys.test.js | 2 +- test/unit/DSCache/index.put.test.js | 22 +- test/unit/DSCache/index.remove.test.js | 8 +- test/unit/DSCache/index.removeAll.test.js | 6 +- test/unit/DSCache/index.removeExpired.test.js | 6 +- test/unit/DSCache/index.setOptions.test.js | 14 +- ...heFactoryProvider.setCacheDefaults.test.js | 8 +- .../DSCacheFactory/index.clearAll.test.js | 16 +- .../DSCacheFactory/index.destroyAll.test.js | 22 +- .../DSCacheFactory/index.disableAll.test.js | 20 +- .../DSCacheFactory/index.enableAll.test.js | 20 +- test/unit/DSCacheFactory/index.get.test.js | 12 +- test/unit/DSCacheFactory/index.info.test.js | 8 +- test/unit/DSCacheFactory/index.keySet.test.js | 20 +- test/unit/DSCacheFactory/index.keys.test.js | 20 +- test/unit/DSCacheFactory/index.test.js | 48 +-- 35 files changed, 493 insertions(+), 480 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94868ee..ac5fcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +##### 3.0.0-beta.2 25 February 2014 + +###### Backwards compatible bug fixes +- Fixed missing reference to DSBinaryHeap #105 + ##### 3.0.0-beta.1 24 February 2014 ###### Breaking API changes diff --git a/bower.json b/bower.json index e2ba1e5..7f80597 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "author": "Jason Dobry", "name": "angular-cache", "description": "angular-cache is a very useful replacement for Angular's $cacheFactory.", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "homepage": "https://github.com/jmdobry/angular-cache", "repository": { "type": "git", diff --git a/dist/angular-cache.js b/dist/angular-cache.js index bdbf8fa..edfa4cf 100644 --- a/dist/angular-cache.js +++ b/dist/angular-cache.js @@ -1,7 +1,7 @@ /** * @author Jason Dobry * @file angular-cache.js - * @version 3.0.0-beta.1 - Homepage + * @version 3.0.0-beta.2 - Homepage * @copyright (c) 2013 Jason Dobry * @license MIT * @@ -9,180 +9,183 @@ */ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - // Compute the parent element's index, and fetch it. - var parentN = Math.floor((n + 1) / 2) - 1, - parent = heap[parentN]; - // If the parent has a lesser weight, things are in order and we - // are done. - if (weight >= weightFunc(parent)) { - break; - } else { - heap[parentN] = element; - heap[n] = parent; - n = parentN; - } - } +function bubbleUp(heap, weightFunc, n) { + var element = heap[n], + weight = weightFunc(element); + // When at 0, an element can not go up any further. + while (n > 0) { + // Compute the parent element's index, and fetch it. + var parentN = Math.floor((n + 1) / 2) - 1, + parent = heap[parentN]; + // If the parent has a lesser weight, things are in order and we + // are done. + if (weight >= weightFunc(parent)) { + break; + } else { + heap[parentN] = element; + heap[n] = parent; + n = parentN; } + } +} - /** - * @method bubbleDown - * @param {array} heap The heap. - * @param {function} weightFunc The weight function. - * @param {number} n The index of the element to sink down. - */ - function bubbleDown(heap, weightFunc, n) { - var length = heap.length, - node = heap[n], - nodeWeight = weightFunc(node); - - while (true) { - var child2N = (n + 1) * 2, - child1N = child2N - 1; - var swap = null; - if (child1N < length) { - var child1 = heap[child1N], - child1Weight = weightFunc(child1); - // If the score is less than our node's, we need to swap. - if (child1Weight < nodeWeight) { - swap = child1N; - } - } - // Do the same checks for the other child. - if (child2N < length) { - var child2 = heap[child2N], - child2Weight = weightFunc(child2); - if (child2Weight < (swap === null ? nodeWeight : weightFunc(heap[child1N]))) { - swap = child2N; - } - } - - if (swap === null) { - break; - } else { - heap[n] = heap[swap]; - heap[swap] = node; - n = swap; - } +/** + * @method bubbleDown + * @param {array} heap The heap. + * @param {function} weightFunc The weight function. + * @param {number} n The index of the element to sink down. + */ +function bubbleDown(heap, weightFunc, n) { + var length = heap.length, + node = heap[n], + nodeWeight = weightFunc(node); + + while (true) { + var child2N = (n + 1) * 2, + child1N = child2N - 1; + var swap = null; + if (child1N < length) { + var child1 = heap[child1N], + child1Weight = weightFunc(child1); + // If the score is less than our node's, we need to swap. + if (child1Weight < nodeWeight) { + swap = child1N; + } + } + // Do the same checks for the other child. + if (child2N < length) { + var child2 = heap[child2N], + child2Weight = weightFunc(child2); + if (child2Weight < (swap === null ? nodeWeight : weightFunc(heap[child1N]))) { + swap = child2N; } } - /** - * @class DSBinaryHeap - * @desc DSBinaryHeap implementation of a priority queue. - * @param {function} weightFunc Function that returns the value that should be used for node value comparison. - * @example - * angular.module('app').controller(function (DSBinaryHeap) { + if (swap === null) { + break; + } else { + heap[n] = heap[swap]; + heap[swap] = node; + n = swap; + } + } +} + +/** + * @class DSBinaryHeap + * @desc DSBinaryHeap implementation of a priority queue. + * @param {function} weightFunc Function that returns the value that should be used for node value comparison. + * @example + * angular.module('app').controller(function (DSBinaryHeap) { * var bHeap = new DSBinaryHeap(function (x) { * return x.value; * }); * ); */ - function DSBinaryHeap(weightFunc) { - if (weightFunc && !angular.isFunction(weightFunc)) { - throw new Error('DSBinaryHeap(weightFunc): weightFunc: must be a function!'); - } - weightFunc = weightFunc || function (x) { - return x; - }; - this.weightFunc = weightFunc; - this.heap = []; - } +function DSBinaryHeap(weightFunc) { + if (weightFunc && !angular.isFunction(weightFunc)) { + throw new Error('DSBinaryHeap(weightFunc): weightFunc: must be a function!'); + } + weightFunc = weightFunc || function (x) { + return x; + }; + this.weightFunc = weightFunc; + this.heap = []; +} - /** - * @method DSBinaryHeap.push - * @desc Push an element into the binary heap. - * @param {*} node The element to push into the binary heap. - */ - DSBinaryHeap.prototype.push = function (node) { - this.heap.push(node); - bubbleUp(this.heap, this.weightFunc, this.heap.length - 1); - }; +/** + * @method DSBinaryHeap.push + * @desc Push an element into the binary heap. + * @param {*} node The element to push into the binary heap. + */ +DSBinaryHeap.prototype.push = function (node) { + this.heap.push(node); + bubbleUp(this.heap, this.weightFunc, this.heap.length - 1); +}; - /** - * @method DSBinaryHeap.peek - * @desc Return, but do not remove, the minimum element in the binary heap. - * @returns {*} - */ - DSBinaryHeap.prototype.peek = function () { - return this.heap[0]; - }; +/** + * @method DSBinaryHeap.peek + * @desc Return, but do not remove, the minimum element in the binary heap. + * @returns {*} + */ +DSBinaryHeap.prototype.peek = function () { + return this.heap[0]; +}; - /** - * @method DSBinaryHeap.pop - * @desc Remove and return the minimum element in the binary heap. - * @returns {*} - */ - DSBinaryHeap.prototype.pop = function () { - var front = this.heap[0], - end = this.heap.pop(); - if (this.heap.length > 0) { - this.heap[0] = end; - bubbleDown(this.heap, this.weightFunc, 0); - } - return front; - }; +/** + * @method DSBinaryHeap.pop + * @desc Remove and return the minimum element in the binary heap. + * @returns {*} + */ +DSBinaryHeap.prototype.pop = function () { + var front = this.heap[0], + end = this.heap.pop(); + if (this.heap.length > 0) { + this.heap[0] = end; + bubbleDown(this.heap, this.weightFunc, 0); + } + return front; +}; - /** - * @method DSBinaryHeap.remove - * @desc Remove the first node in the priority queue that satisfies angular.equals comparison with - * the given node. - * @param {*} node The node to remove. - * @returns {*} The removed node. - */ - DSBinaryHeap.prototype.remove = function (node) { - var length = this.heap.length; - for (var i = 0; i < length; i++) { - if (angular.equals(this.heap[i], node)) { - var removed = this.heap[i], - end = this.heap.pop(); - if (i !== length - 1) { - this.heap[i] = end; - bubbleUp(this.heap, this.weightFunc, i); - bubbleDown(this.heap, this.weightFunc, i); - } - return removed; - } +/** + * @method DSBinaryHeap.remove + * @desc Remove the first node in the priority queue that satisfies angular.equals comparison with + * the given node. + * @param {*} node The node to remove. + * @returns {*} The removed node. + */ +DSBinaryHeap.prototype.remove = function (node) { + var length = this.heap.length; + for (var i = 0; i < length; i++) { + if (angular.equals(this.heap[i], node)) { + var removed = this.heap[i], + end = this.heap.pop(); + if (i !== length - 1) { + this.heap[i] = end; + bubbleUp(this.heap, this.weightFunc, i); + bubbleDown(this.heap, this.weightFunc, i); } - return null; - }; + return removed; + } + } + return null; +}; - /** - * @method DSBinaryHeap.removeAll - * @desc Remove all nodes from this DSBinaryHeap. - */ - DSBinaryHeap.prototype.removeAll = function () { - this.heap = []; - }; +/** + * @method DSBinaryHeap.removeAll + * @desc Remove all nodes from this DSBinaryHeap. + */ +DSBinaryHeap.prototype.removeAll = function () { + this.heap = []; +}; - /** - * @method DSBinaryHeap.size - * @desc Return the size of the priority queue. - * @returns {number} The size of the priority queue. - */ - DSBinaryHeap.prototype.size = function () { - return this.heap.length; - }; +/** + * @method DSBinaryHeap.size + * @desc Return the size of the priority queue. + * @returns {number} The size of the priority queue. + */ +DSBinaryHeap.prototype.size = function () { + return this.heap.length; +}; +/** + * @desc Provider for the DSBinaryHeap. + */ +function DSBinaryHeapProvider() { + this.$get = function () { return DSBinaryHeap; }; } -module.exports = DSBinaryHeapProvider; +module.exports = { + DSBinaryHeapProvider: DSBinaryHeapProvider, + DSBinaryHeap: DSBinaryHeap +}; },{}],2:[function(require,module,exports){ /** @@ -408,7 +411,8 @@ module.exports = function get(key, options) { }; },{"../utils":22}],4:[function(require,module,exports){ -var defaults = require('../defaults'); +var defaults = require('../defaults'), + DSBinaryHeap = require('../DSBinaryHeap').DSBinaryHeap; /*! * Configure the cache to use webStorage. @@ -804,7 +808,7 @@ DSCache.prototype.enable = function () { module.exports = DSCache; -},{"../defaults":"Gv0+ce","./destroy":2,"./get":3,"./info":5,"./keySet":6,"./keys":7,"./put":8,"./remove":9,"./removeAll":10,"./removeExpired":11,"./setCacheFlushInterval":12,"./setCapacity":13,"./setDeleteOnExpire":14,"./setMaxAge":15,"./setOnExpire":16,"./setRecycleFreq":17}],5:[function(require,module,exports){ +},{"../DSBinaryHeap":1,"../defaults":"Gv0+ce","./destroy":2,"./get":3,"./info":5,"./keySet":6,"./keys":7,"./put":8,"./remove":9,"./removeAll":10,"./removeExpired":11,"./setCacheFlushInterval":12,"./setCapacity":13,"./setDeleteOnExpire":14,"./setMaxAge":15,"./setOnExpire":16,"./setRecycleFreq":17}],5:[function(require,module,exports){ /** * @doc method * @id DSCache.methods:info @@ -1650,7 +1654,7 @@ module.exports = function setRecycleFreq(recycleFreq) { },{}],18:[function(require,module,exports){ var defaults = require('../defaults'), DSCache = require('../DSCache'), - version = '3.0.0-beta.1'; + version = '3.0.0-beta.2'; /** * @doc function @@ -2224,14 +2228,14 @@ module.exports = { }; angular.module('angular-data.DSBinaryHeap', []) - .provider('DSBinaryHeap', require('./DSBinaryHeap')); + .provider('DSBinaryHeap', require('./DSBinaryHeap').DSBinaryHeapProvider); /** * @doc overview * @id angular-cache * @name Overview * @description - * __Version:__ 3.0.0-beta.1 + * __Version:__ 3.0.0-beta.2 * * ## Install * @@ -2251,7 +2255,7 @@ module.exports = { * also consumable by Browserify and you should be able to `require('angular-cache')`. The `main` file is `src/index.js`. * * #### Manual download - * Download angular-cache.3.0.0-beta.1.js from the [Releases](https://github.com/jmdobry/angular-cache/releases) + * Download angular-cache.3.0.0-beta.2.js from the [Releases](https://github.com/jmdobry/angular-cache/releases) * section of the angular-cache GitHub project. * * ## Load into Angular diff --git a/dist/angular-cache.min.js b/dist/angular-cache.min.js index a78436a..9d33a99 100644 --- a/dist/angular-cache.min.js +++ b/dist/angular-cache.min.js @@ -1,10 +1,10 @@ /** * @author Jason Dobry * @file angular-cache.min.js -* @version 3.0.0-beta.1 - Homepage +* @version 3.0.0-beta.2 - Homepage * @copyright (c) 2013 Jason Dobry * @license MIT * * @overview angular-cache is a very useful replacement for Angular's $cacheFactory. */ -require=function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0;){var f=Math.floor((c+1)/2)-1,g=a[f];if(e>=b(g))break;a[f]=d,a[c]=g,c=f}}function b(a,b,c){for(var d=a.length,e=a[c],f=b(e);;){var g=2*(c+1),h=g-1,i=null;if(d>h){var j=a[h],k=b(j);f>k&&(i=h)}if(d>g){var l=a[g],m=b(l);m<(null===i?f:b(a[h]))&&(i=g)}if(null===i)break;a[c]=a[i],a[i]=e,c=i}}function c(a){if(a&&!angular.isFunction(a))throw new Error("DSBinaryHeap(weightFunc): weightFunc: must be a function!");a=a||function(a){return a},this.weightFunc=a,this.heap=[]}return c.prototype.push=function(b){this.heap.push(b),a(this.heap,this.weightFunc,this.heap.length-1)},c.prototype.peek=function(){return this.heap[0]},c.prototype.pop=function(){var a=this.heap[0],c=this.heap.pop();return this.heap.length>0&&(this.heap[0]=c,b(this.heap,this.weightFunc,0)),a},c.prototype.remove=function(c){for(var d=this.heap.length,e=0;d>e;e++)if(angular.equals(this.heap[e],c)){var f=this.heap[e],g=this.heap.pop();return e!==d-1&&(this.heap[e]=g,a(this.heap,this.weightFunc,e),b(this.heap,this.weightFunc,e)),f}return null},c.prototype.removeAll=function(){this.heap=[]},c.prototype.size=function(){return this.heap.length},c}}b.exports=c},{}],2:[function(a,b){b.exports=function(){clearInterval(this.$$cacheFlushIntervalId),clearInterval(this.$$recycleFreqId),this.removeAll(),this.$$storage&&(this.$$storage.removeItem(this.$$prefix+".keys"),this.$$storage.removeItem(this.$$prefix)),this.$$storage=null,this.$$data=null,this.$$lruHeap=null,this.$$expiresHeap=null,this.$$prefix=null}},{}],3:[function(a,b){var c=a("../utils");b.exports=function(a,b){var d=this;if(angular.isArray(a)){var e=a,f=[];return angular.forEach(e,function(a){var c=d.get(a,b);null!==c&&void 0!==c&&f.push(c)}),f}if(a=c.stringifyNumber(a),!this.$$disabled){if(b=b||{},!angular.isString(a))throw angular.$$minErr("ng")("areq","Expected key to be a string! Found: {0}.",typeof a);if(b&&!angular.isObject(b))throw angular.$$minErr("ng")("areq","Expected options to be an object! Found: {0}.",typeof b);if(b.onExpire&&!angular.isFunction(b.onExpire))throw angular.$$minErr("ng")("areq","Expected options.onExpire to be a function! Found: {0}.",typeof b.onExpire);var g;if(this.$$storage){var h=this.$$storage.getItem(this.$$prefix+".data."+a);if(!h)return;g=angular.fromJson(h)}else{if(!(a in this.$$data))return;g=this.$$data[a]}var i=g.value,j=(new Date).getTime();return this.$$storage?(this.$$lruHeap.remove({key:a,accessed:g.accessed}),g.accessed=j,this.$$lruHeap.push({key:a,accessed:j})):(this.$$lruHeap.remove(g),g.accessed=j,this.$$lruHeap.push(g)),"passive"===this.$$deleteOnExpire&&"expires"in g&&g.expiresthis.$$maxAge}}return void 0}return{id:this.$$id,capacity:this.$$capacity,maxAge:this.$$maxAge,deleteOnExpire:this.$$deleteOnExpire,onExpire:this.$$onExpire,cacheFlushInterval:this.$$cacheFlushInterval,recycleFreq:this.$$recycleFreq,storageMode:this.$$storageMode,storageImpl:this.$$storageImpl,disabled:this.$$disabled,size:this.$$lruHeap&&this.$$lruHeap.size()||0}}},{}],6:[function(a,b){var c=a("../utils");b.exports=function(){if(this.$$storage){var a=this.$$storage.getItem(this.$$prefix+".keys"),b={};if(a)for(var d=angular.fromJson(a),e=0;ethis.$$capacity&&this.remove(this.$$lruHeap.peek().key),b}}},{"../utils":22}],9:[function(a,b){b.exports=function(a){if(!this.$$storage){var b=this.$$data[a]?this.$$data[a].value:void 0;return this.$$lruHeap.remove(this.$$data[a]),this.$$expiresHeap.remove(this.$$data[a]),this.$$data[a]=null,delete this.$$data[a],b}var c=this.$$storage.getItem(this.$$prefix+".data."+a);if(c){var d=angular.fromJson(c);this.$$lruHeap.remove({key:a,accessed:d.accessed}),this.$$expiresHeap.remove({key:a,expires:d.expires}),this.$$storage.removeItem(this.$$prefix+".data."+a);var e=this.$$storage.getItem(this.$$prefix+".keys"),f=e?angular.fromJson(e):[],g=f.indexOf(a);return g>=0&&f.splice(g,1),this.$$storage.setItem(this.$$prefix+".keys",angular.toJson(f)),d.value}}},{}],10:[function(a,b){b.exports=function(){if(this.$$storage){this.$$lruHeap.removeAll(),this.$$expiresHeap.removeAll();var a=this.$$storage.getItem(this.$$prefix+".keys");if(a)for(var b=angular.fromJson(a),c=0;ca)throw angular.$$minErr("ng")("areq","Expected cacheFlushInterval to be greater than zero! Found: {0}.",a);a!==this.$$cacheFlushInterval&&(this.$$cacheFlushInterval=a,clearInterval(this.$$cacheFlushIntervalId),function(a){a.$$cacheFlushIntervalId=setInterval(function(){a.removeAll()},a.$$cacheFlushInterval)}(this))}}},{}],13:[function(a,b){b.exports=function(a){if(null===a)delete this.$$capacity;else{if(!angular.isNumber(a))throw angular.$$minErr("ng")("areq","Expected capacity to be a number! Found: {0}.",typeof a);if(0>a)throw angular.$$minErr("ng")("areq","Expected capacity to be greater than zero! Found: {0}.",a);this.$$capacity=a}for(var b={};this.$$lruHeap.size()>this.$$capacity;)b[this.$$lruHeap.peek().key]=this.remove(this.$$lruHeap.peek().key);return b}},{}],14:[function(a,b){b.exports=function(a){if(null===a)delete this.$$deleteOnExpire;else{if(!angular.isString(a))throw angular.$$minErr("ng")("areq","Expected deleteOnExpire to be a string! Found: {0}.",typeof a);if("none"!==a&&"passive"!==a&&"aggressive"!==a)throw angular.$$minErr("ng")("areq",'Expected deleteOnExpire to be "none", "passive" or "aggressive"! Found: {0}.',a);this.$$deleteOnExpire=a}this.setRecycleFreq(this.$$recycleFreq)}},{}],15:[function(a,b){var c=a("../utils");b.exports=function(a){if(null===a)delete this.$$maxAge;else{if(!angular.isNumber(a))throw angular.$$minErr("ng")("areq","Expected maxAge to be a number! Found: {0}.",typeof a);if(0>a)throw angular.$$minErr("ng")("areq","Expected maxAge to be greater than zero! Found: {0}.",a);this.$$maxAge=a}var b,d,e;if(this.$$expiresHeap.removeAll(),this.$$storage){var f=this.$$storage.getItem(this.$$prefix+".keys");for(d=f?angular.fromJson(f):[],b=0;ba)throw angular.$$minErr("ng")("areq","Expected recycleFreq to be greater than zero! Found: {0}.",a);this.$$recycleFreq=a}clearInterval(this.$$recycleFreqId),"aggressive"===this.$$deleteOnExpire?!function(a){a.$$recycleFreqId=setInterval(function(){a.removeExpired()},a.$$recycleFreq)}(this):delete this.$$recycleFreqId}},{}],18:[function(a,b){function c(){var a=new d.Config;this.version=f,this.setCacheDefaults=function(b){if(b=b||{},!angular.isObject(b))throw angular.$$minErr("ng")("areq","Expected options to be an object! Found: {0}.",typeof b);for(var c in d.defaults)c in b&&(a[c]=b[c]);"disabled"in b&&(a.$$disabled=!!b.disabled)},this.$get=function(){function b(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c}function c(b,c){if(b in g)throw angular.$$minErr("$cacheFactory")("iid","CacheId '{0}' is already taken!",b);if(!angular.isString(b))throw angular.$$minErr("ng")("areq","Expected cacheId to be a string! Found: {0}.",typeof b);return g[b]=new e(b,angular.extend({},a,c)),g[b].destroy=function(){this.constructor.prototype.destroy.call(this),delete g[this.$$id]},g[b]}var g={};return c.version=f,c.info=function(){for(var c=b(g),e={size:c.length,caches:{}},f=0;f0;){var f=Math.floor((c+1)/2)-1,g=a[f];if(e>=b(g))break;a[f]=d,a[c]=g,c=f}}function d(a,b,c){for(var d=a.length,e=a[c],f=b(e);;){var g=2*(c+1),h=g-1,i=null;if(d>h){var j=a[h],k=b(j);f>k&&(i=h)}if(d>g){var l=a[g],m=b(l);m<(null===i?f:b(a[h]))&&(i=g)}if(null===i)break;a[c]=a[i],a[i]=e,c=i}}function e(a){if(a&&!angular.isFunction(a))throw new Error("DSBinaryHeap(weightFunc): weightFunc: must be a function!");a=a||function(a){return a},this.weightFunc=a,this.heap=[]}function f(){this.$get=function(){return e}}e.prototype.push=function(a){this.heap.push(a),c(this.heap,this.weightFunc,this.heap.length-1)},e.prototype.peek=function(){return this.heap[0]},e.prototype.pop=function(){var a=this.heap[0],b=this.heap.pop();return this.heap.length>0&&(this.heap[0]=b,d(this.heap,this.weightFunc,0)),a},e.prototype.remove=function(a){for(var b=this.heap.length,e=0;b>e;e++)if(angular.equals(this.heap[e],a)){var f=this.heap[e],g=this.heap.pop();return e!==b-1&&(this.heap[e]=g,c(this.heap,this.weightFunc,e),d(this.heap,this.weightFunc,e)),f}return null},e.prototype.removeAll=function(){this.heap=[]},e.prototype.size=function(){return this.heap.length},b.exports={DSBinaryHeapProvider:f,DSBinaryHeap:e}},{}],2:[function(a,b){b.exports=function(){clearInterval(this.$$cacheFlushIntervalId),clearInterval(this.$$recycleFreqId),this.removeAll(),this.$$storage&&(this.$$storage.removeItem(this.$$prefix+".keys"),this.$$storage.removeItem(this.$$prefix)),this.$$storage=null,this.$$data=null,this.$$lruHeap=null,this.$$expiresHeap=null,this.$$prefix=null}},{}],3:[function(a,b){var c=a("../utils");b.exports=function(a,b){var d=this;if(angular.isArray(a)){var e=a,f=[];return angular.forEach(e,function(a){var c=d.get(a,b);null!==c&&void 0!==c&&f.push(c)}),f}if(a=c.stringifyNumber(a),!this.$$disabled){if(b=b||{},!angular.isString(a))throw angular.$$minErr("ng")("areq","Expected key to be a string! Found: {0}.",typeof a);if(b&&!angular.isObject(b))throw angular.$$minErr("ng")("areq","Expected options to be an object! Found: {0}.",typeof b);if(b.onExpire&&!angular.isFunction(b.onExpire))throw angular.$$minErr("ng")("areq","Expected options.onExpire to be a function! Found: {0}.",typeof b.onExpire);var g;if(this.$$storage){var h=this.$$storage.getItem(this.$$prefix+".data."+a);if(!h)return;g=angular.fromJson(h)}else{if(!(a in this.$$data))return;g=this.$$data[a]}var i=g.value,j=(new Date).getTime();return this.$$storage?(this.$$lruHeap.remove({key:a,accessed:g.accessed}),g.accessed=j,this.$$lruHeap.push({key:a,accessed:j})):(this.$$lruHeap.remove(g),g.accessed=j,this.$$lruHeap.push(g)),"passive"===this.$$deleteOnExpire&&"expires"in g&&g.expiresthis.$$maxAge}}return void 0}return{id:this.$$id,capacity:this.$$capacity,maxAge:this.$$maxAge,deleteOnExpire:this.$$deleteOnExpire,onExpire:this.$$onExpire,cacheFlushInterval:this.$$cacheFlushInterval,recycleFreq:this.$$recycleFreq,storageMode:this.$$storageMode,storageImpl:this.$$storageImpl,disabled:this.$$disabled,size:this.$$lruHeap&&this.$$lruHeap.size()||0}}},{}],6:[function(a,b){var c=a("../utils");b.exports=function(){if(this.$$storage){var a=this.$$storage.getItem(this.$$prefix+".keys"),b={};if(a)for(var d=angular.fromJson(a),e=0;ethis.$$capacity&&this.remove(this.$$lruHeap.peek().key),b}}},{"../utils":22}],9:[function(a,b){b.exports=function(a){if(!this.$$storage){var b=this.$$data[a]?this.$$data[a].value:void 0;return this.$$lruHeap.remove(this.$$data[a]),this.$$expiresHeap.remove(this.$$data[a]),this.$$data[a]=null,delete this.$$data[a],b}var c=this.$$storage.getItem(this.$$prefix+".data."+a);if(c){var d=angular.fromJson(c);this.$$lruHeap.remove({key:a,accessed:d.accessed}),this.$$expiresHeap.remove({key:a,expires:d.expires}),this.$$storage.removeItem(this.$$prefix+".data."+a);var e=this.$$storage.getItem(this.$$prefix+".keys"),f=e?angular.fromJson(e):[],g=f.indexOf(a);return g>=0&&f.splice(g,1),this.$$storage.setItem(this.$$prefix+".keys",angular.toJson(f)),d.value}}},{}],10:[function(a,b){b.exports=function(){if(this.$$storage){this.$$lruHeap.removeAll(),this.$$expiresHeap.removeAll();var a=this.$$storage.getItem(this.$$prefix+".keys");if(a)for(var b=angular.fromJson(a),c=0;ca)throw angular.$$minErr("ng")("areq","Expected cacheFlushInterval to be greater than zero! Found: {0}.",a);a!==this.$$cacheFlushInterval&&(this.$$cacheFlushInterval=a,clearInterval(this.$$cacheFlushIntervalId),function(a){a.$$cacheFlushIntervalId=setInterval(function(){a.removeAll()},a.$$cacheFlushInterval)}(this))}}},{}],13:[function(a,b){b.exports=function(a){if(null===a)delete this.$$capacity;else{if(!angular.isNumber(a))throw angular.$$minErr("ng")("areq","Expected capacity to be a number! Found: {0}.",typeof a);if(0>a)throw angular.$$minErr("ng")("areq","Expected capacity to be greater than zero! Found: {0}.",a);this.$$capacity=a}for(var b={};this.$$lruHeap.size()>this.$$capacity;)b[this.$$lruHeap.peek().key]=this.remove(this.$$lruHeap.peek().key);return b}},{}],14:[function(a,b){b.exports=function(a){if(null===a)delete this.$$deleteOnExpire;else{if(!angular.isString(a))throw angular.$$minErr("ng")("areq","Expected deleteOnExpire to be a string! Found: {0}.",typeof a);if("none"!==a&&"passive"!==a&&"aggressive"!==a)throw angular.$$minErr("ng")("areq",'Expected deleteOnExpire to be "none", "passive" or "aggressive"! Found: {0}.',a);this.$$deleteOnExpire=a}this.setRecycleFreq(this.$$recycleFreq)}},{}],15:[function(a,b){var c=a("../utils");b.exports=function(a){if(null===a)delete this.$$maxAge;else{if(!angular.isNumber(a))throw angular.$$minErr("ng")("areq","Expected maxAge to be a number! Found: {0}.",typeof a);if(0>a)throw angular.$$minErr("ng")("areq","Expected maxAge to be greater than zero! Found: {0}.",a);this.$$maxAge=a}var b,d,e;if(this.$$expiresHeap.removeAll(),this.$$storage){var f=this.$$storage.getItem(this.$$prefix+".keys");for(d=f?angular.fromJson(f):[],b=0;ba)throw angular.$$minErr("ng")("areq","Expected recycleFreq to be greater than zero! Found: {0}.",a);this.$$recycleFreq=a}clearInterval(this.$$recycleFreqId),"aggressive"===this.$$deleteOnExpire?!function(a){a.$$recycleFreqId=setInterval(function(){a.removeExpired()},a.$$recycleFreq)}(this):delete this.$$recycleFreqId}},{}],18:[function(a,b){function c(){var a=new d.Config;this.version=f,this.setCacheDefaults=function(b){if(b=b||{},!angular.isObject(b))throw angular.$$minErr("ng")("areq","Expected options to be an object! Found: {0}.",typeof b);for(var c in d.defaults)c in b&&(a[c]=b[c]);"disabled"in b&&(a.$$disabled=!!b.disabled)},this.$get=function(){function b(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c}function c(b,c){if(b in g)throw angular.$$minErr("$cacheFactory")("iid","CacheId '{0}' is already taken!",b);if(!angular.isString(b))throw angular.$$minErr("ng")("areq","Expected cacheId to be a string! Found: {0}.",typeof b);return g[b]=new e(b,angular.extend({},a,c)),g[b].destroy=function(){this.constructor.prototype.destroy.call(this),delete g[this.$$id]},g[b]}var g={};return c.version=f,c.info=function(){for(var c=b(g),e={size:c.length,caches:{}},f=0;f 0) { - // Compute the parent element's index, and fetch it. - var parentN = Math.floor((n + 1) / 2) - 1, - parent = heap[parentN]; - // If the parent has a lesser weight, things are in order and we - // are done. - if (weight >= weightFunc(parent)) { - break; - } else { - heap[parentN] = element; - heap[n] = parent; - n = parentN; - } - } +function bubbleUp(heap, weightFunc, n) { + var element = heap[n], + weight = weightFunc(element); + // When at 0, an element can not go up any further. + while (n > 0) { + // Compute the parent element's index, and fetch it. + var parentN = Math.floor((n + 1) / 2) - 1, + parent = heap[parentN]; + // If the parent has a lesser weight, things are in order and we + // are done. + if (weight >= weightFunc(parent)) { + break; + } else { + heap[parentN] = element; + heap[n] = parent; + n = parentN; } + } +} - /** - * @method bubbleDown - * @param {array} heap The heap. - * @param {function} weightFunc The weight function. - * @param {number} n The index of the element to sink down. - */ - function bubbleDown(heap, weightFunc, n) { - var length = heap.length, - node = heap[n], - nodeWeight = weightFunc(node); - - while (true) { - var child2N = (n + 1) * 2, - child1N = child2N - 1; - var swap = null; - if (child1N < length) { - var child1 = heap[child1N], - child1Weight = weightFunc(child1); - // If the score is less than our node's, we need to swap. - if (child1Weight < nodeWeight) { - swap = child1N; - } - } - // Do the same checks for the other child. - if (child2N < length) { - var child2 = heap[child2N], - child2Weight = weightFunc(child2); - if (child2Weight < (swap === null ? nodeWeight : weightFunc(heap[child1N]))) { - swap = child2N; - } - } +/** + * @method bubbleDown + * @param {array} heap The heap. + * @param {function} weightFunc The weight function. + * @param {number} n The index of the element to sink down. + */ +function bubbleDown(heap, weightFunc, n) { + var length = heap.length, + node = heap[n], + nodeWeight = weightFunc(node); - if (swap === null) { - break; - } else { - heap[n] = heap[swap]; - heap[swap] = node; - n = swap; - } + while (true) { + var child2N = (n + 1) * 2, + child1N = child2N - 1; + var swap = null; + if (child1N < length) { + var child1 = heap[child1N], + child1Weight = weightFunc(child1); + // If the score is less than our node's, we need to swap. + if (child1Weight < nodeWeight) { + swap = child1N; + } + } + // Do the same checks for the other child. + if (child2N < length) { + var child2 = heap[child2N], + child2Weight = weightFunc(child2); + if (child2Weight < (swap === null ? nodeWeight : weightFunc(heap[child1N]))) { + swap = child2N; } } - /** - * @class DSBinaryHeap - * @desc DSBinaryHeap implementation of a priority queue. - * @param {function} weightFunc Function that returns the value that should be used for node value comparison. - * @example - * angular.module('app').controller(function (DSBinaryHeap) { + if (swap === null) { + break; + } else { + heap[n] = heap[swap]; + heap[swap] = node; + n = swap; + } + } +} + +/** + * @class DSBinaryHeap + * @desc DSBinaryHeap implementation of a priority queue. + * @param {function} weightFunc Function that returns the value that should be used for node value comparison. + * @example + * angular.module('app').controller(function (DSBinaryHeap) { * var bHeap = new DSBinaryHeap(function (x) { * return x.value; * }); * ); */ - function DSBinaryHeap(weightFunc) { - if (weightFunc && !angular.isFunction(weightFunc)) { - throw new Error('DSBinaryHeap(weightFunc): weightFunc: must be a function!'); - } - weightFunc = weightFunc || function (x) { - return x; - }; - this.weightFunc = weightFunc; - this.heap = []; - } +function DSBinaryHeap(weightFunc) { + if (weightFunc && !angular.isFunction(weightFunc)) { + throw new Error('DSBinaryHeap(weightFunc): weightFunc: must be a function!'); + } + weightFunc = weightFunc || function (x) { + return x; + }; + this.weightFunc = weightFunc; + this.heap = []; +} - /** - * @method DSBinaryHeap.push - * @desc Push an element into the binary heap. - * @param {*} node The element to push into the binary heap. - */ - DSBinaryHeap.prototype.push = function (node) { - this.heap.push(node); - bubbleUp(this.heap, this.weightFunc, this.heap.length - 1); - }; +/** + * @method DSBinaryHeap.push + * @desc Push an element into the binary heap. + * @param {*} node The element to push into the binary heap. + */ +DSBinaryHeap.prototype.push = function (node) { + this.heap.push(node); + bubbleUp(this.heap, this.weightFunc, this.heap.length - 1); +}; - /** - * @method DSBinaryHeap.peek - * @desc Return, but do not remove, the minimum element in the binary heap. - * @returns {*} - */ - DSBinaryHeap.prototype.peek = function () { - return this.heap[0]; - }; +/** + * @method DSBinaryHeap.peek + * @desc Return, but do not remove, the minimum element in the binary heap. + * @returns {*} + */ +DSBinaryHeap.prototype.peek = function () { + return this.heap[0]; +}; - /** - * @method DSBinaryHeap.pop - * @desc Remove and return the minimum element in the binary heap. - * @returns {*} - */ - DSBinaryHeap.prototype.pop = function () { - var front = this.heap[0], - end = this.heap.pop(); - if (this.heap.length > 0) { - this.heap[0] = end; - bubbleDown(this.heap, this.weightFunc, 0); - } - return front; - }; +/** + * @method DSBinaryHeap.pop + * @desc Remove and return the minimum element in the binary heap. + * @returns {*} + */ +DSBinaryHeap.prototype.pop = function () { + var front = this.heap[0], + end = this.heap.pop(); + if (this.heap.length > 0) { + this.heap[0] = end; + bubbleDown(this.heap, this.weightFunc, 0); + } + return front; +}; - /** - * @method DSBinaryHeap.remove - * @desc Remove the first node in the priority queue that satisfies angular.equals comparison with - * the given node. - * @param {*} node The node to remove. - * @returns {*} The removed node. - */ - DSBinaryHeap.prototype.remove = function (node) { - var length = this.heap.length; - for (var i = 0; i < length; i++) { - if (angular.equals(this.heap[i], node)) { - var removed = this.heap[i], - end = this.heap.pop(); - if (i !== length - 1) { - this.heap[i] = end; - bubbleUp(this.heap, this.weightFunc, i); - bubbleDown(this.heap, this.weightFunc, i); - } - return removed; - } +/** + * @method DSBinaryHeap.remove + * @desc Remove the first node in the priority queue that satisfies angular.equals comparison with + * the given node. + * @param {*} node The node to remove. + * @returns {*} The removed node. + */ +DSBinaryHeap.prototype.remove = function (node) { + var length = this.heap.length; + for (var i = 0; i < length; i++) { + if (angular.equals(this.heap[i], node)) { + var removed = this.heap[i], + end = this.heap.pop(); + if (i !== length - 1) { + this.heap[i] = end; + bubbleUp(this.heap, this.weightFunc, i); + bubbleDown(this.heap, this.weightFunc, i); } - return null; - }; + return removed; + } + } + return null; +}; - /** - * @method DSBinaryHeap.removeAll - * @desc Remove all nodes from this DSBinaryHeap. - */ - DSBinaryHeap.prototype.removeAll = function () { - this.heap = []; - }; +/** + * @method DSBinaryHeap.removeAll + * @desc Remove all nodes from this DSBinaryHeap. + */ +DSBinaryHeap.prototype.removeAll = function () { + this.heap = []; +}; - /** - * @method DSBinaryHeap.size - * @desc Return the size of the priority queue. - * @returns {number} The size of the priority queue. - */ - DSBinaryHeap.prototype.size = function () { - return this.heap.length; - }; +/** + * @method DSBinaryHeap.size + * @desc Return the size of the priority queue. + * @returns {number} The size of the priority queue. + */ +DSBinaryHeap.prototype.size = function () { + return this.heap.length; +}; +/** + * @desc Provider for the DSBinaryHeap. + */ +function DSBinaryHeapProvider() { + this.$get = function () { return DSBinaryHeap; }; } -module.exports = DSBinaryHeapProvider; +module.exports = { + DSBinaryHeapProvider: DSBinaryHeapProvider, + DSBinaryHeap: DSBinaryHeap +}; diff --git a/src/DSCache/index.js b/src/DSCache/index.js index b2c9a52..0076c31 100644 --- a/src/DSCache/index.js +++ b/src/DSCache/index.js @@ -1,4 +1,5 @@ -var defaults = require('../defaults'); +var defaults = require('../defaults'), + DSBinaryHeap = require('../DSBinaryHeap').DSBinaryHeap; /*! * Configure the cache to use webStorage. diff --git a/src/index.js b/src/index.js index a063dc4..b5e453c 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ }; angular.module('angular-data.DSBinaryHeap', []) - .provider('DSBinaryHeap', require('./DSBinaryHeap')); + .provider('DSBinaryHeap', require('./DSBinaryHeap').DSBinaryHeapProvider); /** * @doc overview diff --git a/test/unit/DSBinaryHeap/index.peek.test.js b/test/unit/DSBinaryHeap/index.peek.test.js index 3a5822d..df1d887 100644 --- a/test/unit/DSBinaryHeap/index.peek.test.js +++ b/test/unit/DSBinaryHeap/index.peek.test.js @@ -1,7 +1,7 @@ describe('DSBinaryHeap.peek()', function () { it('should show the item at the front of the DSBinaryHeap.', function () { - var heap = new DSBinaryHeap(); - var objHeap = new DSBinaryHeap(function (x) { + var heap = new TestDSBinaryHeap(); + var objHeap = new TestDSBinaryHeap(function (x) { return x.value; }); var items = [20, 4, 33, 1, 0, 34, 22, 31, 32, 5, 6, 7], diff --git a/test/unit/DSBinaryHeap/index.pop.test.js b/test/unit/DSBinaryHeap/index.pop.test.js index a27e690..f55aa7a 100644 --- a/test/unit/DSBinaryHeap/index.pop.test.js +++ b/test/unit/DSBinaryHeap/index.pop.test.js @@ -1,7 +1,7 @@ describe('DSBinaryHeap.pop()', function () { it('should pop the item off of the front of the DSBinaryHeap.', function () { - var heap = new DSBinaryHeap(); - var objHeap = new DSBinaryHeap(function (x) { + var heap = new TestDSBinaryHeap(); + var objHeap = new TestDSBinaryHeap(function (x) { return x.value; }); var items = [20, 4, 33, 1, 0, 34, 22, 31, 32, 5, 6, 7]; diff --git a/test/unit/DSBinaryHeap/index.push.test.js b/test/unit/DSBinaryHeap/index.push.test.js index 8c71571..305e46c 100644 --- a/test/unit/DSBinaryHeap/index.push.test.js +++ b/test/unit/DSBinaryHeap/index.push.test.js @@ -1,7 +1,7 @@ describe('DSBinaryHeap.push(node)', function () { it('should push items to the front of the DSBinaryHeap.', function () { - var heap = new DSBinaryHeap(); - var objHeap = new DSBinaryHeap(function (x) { + var heap = new TestDSBinaryHeap(); + var objHeap = new TestDSBinaryHeap(function (x) { return x.value; }); var items = [20, 4, 33, 1, 0, 34, 22, 31, 32, 5, 6, 7], diff --git a/test/unit/DSBinaryHeap/index.remove.test.js b/test/unit/DSBinaryHeap/index.remove.test.js index 0290f31..8e7a1d7 100644 --- a/test/unit/DSBinaryHeap/index.remove.test.js +++ b/test/unit/DSBinaryHeap/index.remove.test.js @@ -1,7 +1,7 @@ describe('DSBinaryHeap.remove(node)', function () { it('should remove the item from the heap.', function () { - var heap = new DSBinaryHeap(); - var objHeap = new DSBinaryHeap(function (x) { + var heap = new TestDSBinaryHeap(); + var objHeap = new TestDSBinaryHeap(function (x) { return x.value; }); var items = [20, 4, 33, 1, 0, 34, 22, 31, 32, 5, 6, 7]; diff --git a/test/unit/DSBinaryHeap/index.removeAll.test.js b/test/unit/DSBinaryHeap/index.removeAll.test.js index 820f27d..2340789 100644 --- a/test/unit/DSBinaryHeap/index.removeAll.test.js +++ b/test/unit/DSBinaryHeap/index.removeAll.test.js @@ -1,7 +1,7 @@ describe('DSBinaryHeap.removeAll()', function () { it('should remove all items from the heap.', function () { - var heap = new DSBinaryHeap(); - var objHeap = new DSBinaryHeap(function (x) { + var heap = new TestDSBinaryHeap(); + var objHeap = new TestDSBinaryHeap(function (x) { return x.value; }); var items = [20, 4, 33, 1, 0, 34, 22, 31, 32, 5, 6, 7]; diff --git a/test/unit/DSBinaryHeap/index.test.js b/test/unit/DSBinaryHeap/index.test.js index 6531696..65b5395 100644 --- a/test/unit/DSBinaryHeap/index.test.js +++ b/test/unit/DSBinaryHeap/index.test.js @@ -1,13 +1,13 @@ describe('DSBinaryHeap(weightFunc)', function () { it('should create an empty heap with size 0.', function () { - var heap = new DSBinaryHeap(); + var heap = new TestDSBinaryHeap(); assert.deepEqual(heap.size(), 0); }); it('should throw an error if "weightFunc" is not a function.', function () { var heap; for (var i = 0; i < TYPES_EXCEPT_FUNCTION.length; i++) { try { - heap = new DSBinaryHeap(TYPES_EXCEPT_FUNCTION[i]); + heap = new TestDSBinaryHeap(TYPES_EXCEPT_FUNCTION[i]); if (TYPES_EXCEPT_FUNCTION[i]) { fail(); } diff --git a/test/unit/DSCache/index.destroy.test.js b/test/unit/DSCache/index.destroy.test.js index 0e2ccad..c27bb7c 100644 --- a/test/unit/DSCache/index.destroy.test.js +++ b/test/unit/DSCache/index.destroy.test.js @@ -1,6 +1,6 @@ describe('DSCache.destroy()', function () { it('should destroy the cache and remove all traces of its existence.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); cache.destroy(); try { assert.equal(cache.info(), { size: 0 }); @@ -8,11 +8,11 @@ describe('DSCache.destroy()', function () { } catch (err) { } - assert.isUndefined(DSCacheFactory.get('cache')); + assert.isUndefined(TestDSCacheFactory.get('cache')); }); it('should remove items from localStorage when storageMode is used.', function () { - var localStorageCache = DSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage, storagePrefix: 'acc.' }), - sessionStorageCache = DSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); + var localStorageCache = TestDSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage, storagePrefix: 'acc.' }), + sessionStorageCache = TestDSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); localStorageCache.put('item1', 'value1'); sessionStorageCache.put('item1', 'value1'); diff --git a/test/unit/DSCache/index.get.test.js b/test/unit/DSCache/index.get.test.js index 902f68b..bbe9b87 100644 --- a/test/unit/DSCache/index.get.test.js +++ b/test/unit/DSCache/index.get.test.js @@ -1,6 +1,6 @@ describe('asCache.get(key)', function () { it('should do nothing if the cache is disabled.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.equal(cache.info().size, 0); cache.put('1', 'item'); @@ -11,7 +11,7 @@ describe('asCache.get(key)', function () { assert.isUndefined(cache.get('1')); }); it('should throw an error if "key" is not a string or array.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); for (var i = 0; i < TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER.length; i++) { try { cache.get(TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER[i]); @@ -24,7 +24,7 @@ describe('asCache.get(key)', function () { } }); it('should throw an error if "options" is not an object.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); for (var i = 0; i < TYPES_EXCEPT_OBJECT.length; i++) { try { cache.get('item', TYPES_EXCEPT_OBJECT[i]); @@ -41,7 +41,7 @@ describe('asCache.get(key)', function () { } }); it('should throw an error if "onExpire" is not a function.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); for (var i = 0; i < TYPES_EXCEPT_FUNCTION.length; i++) { try { if (!TYPES_EXCEPT_FUNCTION[i]) { @@ -61,7 +61,7 @@ describe('asCache.get(key)', function () { } }); it('should return the correct value for the specified key.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); var value1 = 'value1', value2 = 2, value3 = { @@ -75,11 +75,11 @@ describe('asCache.get(key)', function () { assert.equal(cache.get('item3'), value3); }); it('should return undefined if the key isn\'t in the cache.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.isUndefined(cache.get('item')); }); it('should execute globally configured "onExpire" callback if the item is expired in passive mode and global "onExpire" callback is configured.', function (done) { - var cache = DSCacheFactory('cache', { + var cache = TestDSCacheFactory('cache', { maxAge: 10, recycleFreq: 20, deleteOnExpire: 'passive', @@ -106,7 +106,7 @@ describe('asCache.get(key)', function () { } }; sinon.spy(options, 'onExpire'); - var cache = DSCacheFactory('cache', options); + var cache = TestDSCacheFactory('cache', options); cache.put('item', 'value'); setTimeout(function () { assert.isTrue(options.onExpire.called); @@ -115,7 +115,7 @@ describe('asCache.get(key)', function () { }, 100); }); it('should execute local "onExpire" callback if the item is expired in passive mode and global "onExpire" callback is NOT configured.', function (done) { - var cache = DSCacheFactory('cache', { + var cache = TestDSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'passive', recycleFreq: 20 @@ -130,7 +130,7 @@ describe('asCache.get(key)', function () { }, 100); }); it('should return the correct values for multiple keys.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); var value1 = 'value1', value2 = 2, value3 = { @@ -142,7 +142,7 @@ describe('asCache.get(key)', function () { assert.deepEqual(cache.get(['item1', 'item2', 'item3']), [value1, value2, value3]); }); it('should not return undefined values for multiple keys.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); var value1 = 'value1', value2 = 2; cache.put('item1', value1); diff --git a/test/unit/DSCache/index.info.test.js b/test/unit/DSCache/index.info.test.js index 6e163e8..d177788 100644 --- a/test/unit/DSCache/index.info.test.js +++ b/test/unit/DSCache/index.info.test.js @@ -2,13 +2,13 @@ describe('DSCache.info()', function () { it('should return the correct values.', function () { var onExpire = function () { }; - var cache = DSCacheFactory('cache'), - cache2 = DSCacheFactory('cache2', { maxAge: 1000 }), - cache3 = DSCacheFactory('cache3', { cacheFlushInterval: 1000 }), - cache4 = DSCacheFactory('cache4', { capacity: 1000 }), - cache5 = DSCacheFactory('cache5', { storageMode: 'localStorage' }), - cache6 = DSCacheFactory('cache6', { storageMode: 'sessionStorage' }), - cache7 = DSCacheFactory('cache7', { maxAge: 100, onExpire: onExpire }); + var cache = TestDSCacheFactory('cache'), + cache2 = TestDSCacheFactory('cache2', { maxAge: 1000 }), + cache3 = TestDSCacheFactory('cache3', { cacheFlushInterval: 1000 }), + cache4 = TestDSCacheFactory('cache4', { capacity: 1000 }), + cache5 = TestDSCacheFactory('cache5', { storageMode: 'localStorage' }), + cache6 = TestDSCacheFactory('cache6', { storageMode: 'sessionStorage' }), + cache7 = TestDSCacheFactory('cache7', { maxAge: 100, onExpire: onExpire }); var cacheInfo = cache.info(); assert.equal(cacheInfo.id, 'cache'); assert.equal(cacheInfo.capacity, Number.MAX_VALUE); diff --git a/test/unit/DSCache/index.keySet.test.js b/test/unit/DSCache/index.keySet.test.js index 25d0958..48fa51b 100644 --- a/test/unit/DSCache/index.keySet.test.js +++ b/test/unit/DSCache/index.keySet.test.js @@ -2,7 +2,7 @@ describe('DSCache.keySet()', function () { it('should return the set of keys of all items in the cache.', function () { var itemKeys = ['item1', 'item2', 'item3']; - var cache = DSCacheFactory('DSCache.keySet.cache'); + var cache = TestDSCacheFactory('DSCache.keySet.cache'); cache.put(itemKeys[0], itemKeys[0]); cache.put(itemKeys[1], itemKeys[1]); diff --git a/test/unit/DSCache/index.keys.test.js b/test/unit/DSCache/index.keys.test.js index 4818307..6aceda9 100644 --- a/test/unit/DSCache/index.keys.test.js +++ b/test/unit/DSCache/index.keys.test.js @@ -2,7 +2,7 @@ describe('DSCache.keys()', function () { it('should return the array of keys of all items in the cache.', function () { var itemKeys = ['item1', 'item2', 'item3']; - var cache = DSCacheFactory('DSCache.keys.cache'); + var cache = TestDSCacheFactory('DSCache.keys.cache'); cache.put(itemKeys[0], itemKeys[0]); cache.put(itemKeys[1], itemKeys[1]); diff --git a/test/unit/DSCache/index.put.test.js b/test/unit/DSCache/index.put.test.js index 7bef52e..4df455d 100644 --- a/test/unit/DSCache/index.put.test.js +++ b/test/unit/DSCache/index.put.test.js @@ -1,13 +1,13 @@ describe('DSCache.put(key, value, options)', function () { it('should do nothing if the cache is disabled.', function () { - var cache = DSCacheFactory('DSCache.put.cache', { disabled: true }); + var cache = TestDSCacheFactory('DSCache.put.cache', { disabled: true }); assert.equal(cache.info().size, 0); assert.isUndefined(cache.put('1', 'item')); assert.equal(cache.info().size, 0); }); it('should throw an error if "key" is not a string.', function () { - var cache = DSCacheFactory('DSCache.put.cache'); + var cache = TestDSCacheFactory('DSCache.put.cache'); for (var i = 0; i < TYPES_EXCEPT_STRING_OR_NUMBER.length; i++) { try { cache.put(TYPES_EXCEPT_STRING_OR_NUMBER[i], 'value'); @@ -20,14 +20,14 @@ describe('DSCache.put(key, value, options)', function () { } }); it('should not add values that are not defined.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); cache.put('item', null); assert.equal(cache.get('item'), undefined); cache.put('item', undefined); assert.equal(cache.get('item'), undefined); }); it('should increase the size of the cache by one.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.equal(cache.info().size, 0); cache.put('item', 'value1'); assert.equal(cache.info().size, 1); @@ -35,7 +35,7 @@ describe('DSCache.put(key, value, options)', function () { assert.equal(cache.info().size, 2); }); it('should overwrite an item if it is re-added to the cache.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.equal(cache.info().size, 0); cache.put('item', 'value1'); assert.equal(cache.info().size, 1); @@ -44,7 +44,7 @@ describe('DSCache.put(key, value, options)', function () { assert.equal(cache.get('item'), 'value2'); }); it('should remove the least recently used item if the capacity has been reached.', function () { - var cache = DSCacheFactory('cache', { capacity: 2 }); + var cache = TestDSCacheFactory('cache', { capacity: 2 }); assert.equal(cache.info().size, 0); cache.put('item1', 'value1'); assert.equal(cache.info().size, 1); @@ -62,7 +62,7 @@ describe('DSCache.put(key, value, options)', function () { assert.equal(cache.get('item2'), 'value2'); }); it('should not delete items if maxAge is specified and deleteOnExpire is set to "none".', function (done) { - var cache = DSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'none', recycleFreq: 20 }); + var cache = TestDSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'none', recycleFreq: 20 }); cache.put('item1', 'value1'); assert.equal(cache.get('item1'), 'value1'); setTimeout(function () { @@ -72,7 +72,7 @@ describe('DSCache.put(key, value, options)', function () { }, 100); }); it('should remove items if maxAge is specified and deleteOnExpire is set to "aggressive".', function (done) { - var cache = DSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'aggressive', recycleFreq: 20 }); + var cache = TestDSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'aggressive', recycleFreq: 20 }); cache.put('item1', 'value1'); assert.equal(cache.get('item1'), 'value1'); setTimeout(function () { @@ -83,7 +83,7 @@ describe('DSCache.put(key, value, options)', function () { }, 100); }); it('should should lazy delete an item when maxAge is specified and deleteOnExpire is set to "passive".', function (done) { - var cache = DSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'passive' }); + var cache = TestDSCacheFactory('cache', { maxAge: 10, deleteOnExpire: 'passive' }); cache.put('item1', 'value1'); assert.equal(cache.get('item1'), 'value1'); setTimeout(function () { @@ -94,8 +94,8 @@ describe('DSCache.put(key, value, options)', function () { }, 100); }); it('should save data to localStorage when storageMode is used.', function () { - var localStorageCache = DSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), - sessionStorageCache = DSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); + var localStorageCache = TestDSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), + sessionStorageCache = TestDSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); localStorageCache.put('item1', 'value1'); sessionStorageCache.put('item1', 'value1'); diff --git a/test/unit/DSCache/index.remove.test.js b/test/unit/DSCache/index.remove.test.js index 7f870bf..71368da 100644 --- a/test/unit/DSCache/index.remove.test.js +++ b/test/unit/DSCache/index.remove.test.js @@ -1,6 +1,6 @@ describe('DSCache.remove(key)', function () { it('should remove the item with the specified key.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); var value1 = 'value1', value2 = 2, value3 = { @@ -17,7 +17,7 @@ describe('DSCache.remove(key)', function () { assert.isUndefined(cache.get('item3')); }); it('should reduce the size of the cache by one if the size is greater than zero.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); cache.put('item1', 'value1'); assert.equal(cache.info().size, 1); cache.put('item2', 'value2'); @@ -32,8 +32,8 @@ describe('DSCache.remove(key)', function () { assert.equal(cache.info().size, 0); }); it('should remove items from localStorage when storageMode is used.', function () { - var localStorageCache = DSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), - sessionStorageCache = DSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); + var localStorageCache = TestDSCacheFactory('localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), + sessionStorageCache = TestDSCacheFactory('sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage }); localStorageCache.put('item1', 'value1'); sessionStorageCache.put('item1', 'value1'); diff --git a/test/unit/DSCache/index.removeAll.test.js b/test/unit/DSCache/index.removeAll.test.js index 344623f..f291627 100644 --- a/test/unit/DSCache/index.removeAll.test.js +++ b/test/unit/DSCache/index.removeAll.test.js @@ -1,6 +1,6 @@ describe('DSCache.removeAll()', function () { it('should remove all items in the cache.', function () { - var cache = DSCacheFactory('DSCache.removeAll.cache'); + var cache = TestDSCacheFactory('DSCache.removeAll.cache'); var value1 = 'value1', value2 = 2, value3 = { @@ -15,8 +15,8 @@ describe('DSCache.removeAll()', function () { assert.isUndefined(cache.get('item3')); }); it('should remove items from localStorage when storageMode is used.', function () { - var localStorageCache = DSCacheFactory('DSCache.removeAll.localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), - sessionStorageCache = DSCacheFactory('DSCache.removeAll.sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage, storagePrefix: 'affas' }); + var localStorageCache = TestDSCacheFactory('DSCache.removeAll.localStorageCache', { storageMode: 'localStorage', storageImpl: $window.localStorage }), + sessionStorageCache = TestDSCacheFactory('DSCache.removeAll.sessionStorageCache', { storageMode: 'sessionStorage', storageImpl: $window.sessionStorage, storagePrefix: 'affas' }); localStorageCache.put('item1', 'value1'); sessionStorageCache.put('item1', 'value1'); diff --git a/test/unit/DSCache/index.removeExpired.test.js b/test/unit/DSCache/index.removeExpired.test.js index 45861f4..fe97979 100644 --- a/test/unit/DSCache/index.removeExpired.test.js +++ b/test/unit/DSCache/index.removeExpired.test.js @@ -1,6 +1,6 @@ describe('DSCache.removeExpired()', function () { it('should remove all expired items when deleteOnExpire is "none".', function (done) { - var cache = DSCacheFactory('cache', { + var cache = TestDSCacheFactory('cache', { deleteOnExpire: 'none', maxAge: 10, recycleFreq: 20 @@ -27,7 +27,7 @@ describe('DSCache.removeExpired()', function () { }, 100); }); // it('should remove all expired items when deleteOnExpire is "passive".', function (done) { -// var cache = DSCacheFactory('cache', { +// var cache = TestDSCacheFactory('cache', { // deleteOnExpire: 'passive', // maxAge: 10, // recycleFreq: 20 @@ -54,7 +54,7 @@ describe('DSCache.removeExpired()', function () { // }, 100); // }); // it('should remove all expired items when deleteOnExpire is "aggressive".', function (done) { -// var cache = DSCacheFactory('cache', { +// var cache = TestDSCacheFactory('cache', { // deleteOnExpire: 'aggressive', // maxAge: 10, // recycleFreq: 20 diff --git a/test/unit/DSCache/index.setOptions.test.js b/test/unit/DSCache/index.setOptions.test.js index 57efad6..04e612c 100644 --- a/test/unit/DSCache/index.setOptions.test.js +++ b/test/unit/DSCache/index.setOptions.test.js @@ -1,6 +1,6 @@ describe('DSCache.setOptions()', function () { it('should throw an error if "options" is not an object.', function () { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); for (var i = 0; i < TYPES_EXCEPT_OBJECT.length; i++) { try { cache.setOptions(TYPES_EXCEPT_OBJECT[i]); @@ -19,7 +19,7 @@ describe('DSCache.setOptions()', function () { it('should correctly reset to defaults if strict mode is true', function () { var onExpire = function () { }; - var cache = DSCacheFactory('cache', { + var cache = TestDSCacheFactory('cache', { maxAge: 100, cacheFlushInterval: 200, onExpire: onExpire, @@ -39,7 +39,7 @@ describe('DSCache.setOptions()', function () { assert.isFalse(cache.info().disabled); }); it('should correctly modify the capacity of a cache', function (done) { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.equal(cache.info().capacity, Number.MAX_VALUE); cache.setOptions({ capacity: 5 }, false); assert.equal(cache.info().capacity, 5); @@ -64,7 +64,7 @@ describe('DSCache.setOptions()', function () { }, 50); }); it('should correctly modify the maxAge of a cache', function (done) { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.equal(cache.info().maxAge, Number.MAX_VALUE); cache.setOptions({ maxAge: 1000, deleteOnExpire: 'aggressive', recycleFreq: 20 }, false); assert.equal(cache.info().maxAge, 1000); @@ -108,7 +108,7 @@ describe('DSCache.setOptions()', function () { }, 100); }); it('should correctly modify the cacheFlushInterval of a cache', function (done) { - var cache = DSCacheFactory('cache'); + var cache = TestDSCacheFactory('cache'); assert.isNull(cache.info().cacheFlushInterval); cache.setOptions({ cacheFlushInterval: 10 }, false); assert.equal(cache.info().cacheFlushInterval, 10); @@ -141,7 +141,7 @@ describe('DSCache.setOptions()', function () { }, 100); }); it('should correctly modify the deleteOnExpire of a cache', function (done) { - var cache = DSCacheFactory('cache', { maxAge: 10 }); + var cache = TestDSCacheFactory('cache', { maxAge: 10 }); assert.equal(cache.info().deleteOnExpire, 'none'); cache.setOptions({ deleteOnExpire: 'passive' }); assert.equal(cache.info().deleteOnExpire, 'passive'); @@ -165,7 +165,7 @@ describe('DSCache.setOptions()', function () { }, 100); }); it('should correctly set configuration to default when "strict" is true', function () { - var cache = DSCacheFactory('cache', { + var cache = TestDSCacheFactory('cache', { capacity: 10, maxAge: 1000, cacheFlushInterval: 1000, diff --git a/test/unit/DSCacheFactory/DSCacheFactoryProvider.setCacheDefaults.test.js b/test/unit/DSCacheFactory/DSCacheFactoryProvider.setCacheDefaults.test.js index 7f275e0..304a1ae 100644 --- a/test/unit/DSCacheFactory/DSCacheFactoryProvider.setCacheDefaults.test.js +++ b/test/unit/DSCacheFactory/DSCacheFactoryProvider.setCacheDefaults.test.js @@ -1,6 +1,6 @@ describe('DSCacheFactoryProvider.setCacheDefaults(options)', function () { it('should have the correct defaults.', function () { - var cache = DSCacheFactory('DSCacheFactoryProvider.setCacheDefaults.cache'); + var cache = TestDSCacheFactory('DSCacheFactoryProvider.setCacheDefaults.cache'); assert.isDefined(cache); assert.equal(cache.info().id, 'DSCacheFactoryProvider.setCacheDefaults.cache'); assert.equal(cache.info().capacity, CACHE_DEFAULTS.capacity); @@ -34,8 +34,8 @@ describe('DSCacheFactoryProvider.setCacheDefaults(options)', function () { onExpire: function () { } }; - DSCacheFactoryProvider.setCacheDefaults(options); - var cache = DSCacheFactory('cache'); + TestDSCacheFactoryProvider.setCacheDefaults(options); + var cache = TestDSCacheFactory('cache'); assert.isDefined(cache); assert.equal(cache.info().id, 'cache'); assert.equal(cache.info().capacity, options.capacity); @@ -53,7 +53,7 @@ describe('DSCacheFactoryProvider.setCacheDefaults(options)', function () { continue; } try { - DSCacheFactoryProvider.setCacheDefaults(TYPES_EXCEPT_OBJECT[i]); + TestDSCacheFactoryProvider.setCacheDefaults(TYPES_EXCEPT_OBJECT[i]); if (TYPES_EXCEPT_OBJECT[i] !== null && TYPES_EXCEPT_OBJECT[i] !== undefined && TYPES_EXCEPT_OBJECT[i] !== false) { fail(TYPES_EXCEPT_OBJECT[i]); } diff --git a/test/unit/DSCacheFactory/index.clearAll.test.js b/test/unit/DSCacheFactory/index.clearAll.test.js index 1ca16cb..a6f0cc2 100644 --- a/test/unit/DSCacheFactory/index.clearAll.test.js +++ b/test/unit/DSCacheFactory/index.clearAll.test.js @@ -3,13 +3,13 @@ describe('DSCacheFactory.clearAll()', function () { var cacheKeys = ['DSCacheFactory.clearAll.cache', 'DSCacheFactory.clearAll.cache1', 'DSCacheFactory.clearAll.cache2'], caches = []; - caches.push(DSCacheFactory(cacheKeys[0])); + caches.push(TestDSCacheFactory(cacheKeys[0])); caches[0].put('item', 'value'); caches[0].put('item2', 'value2'); - caches.push(DSCacheFactory(cacheKeys[1])); + caches.push(TestDSCacheFactory(cacheKeys[1])); caches[1].put('item', 'value'); caches[1].put('item2', 'value2'); - caches.push(DSCacheFactory(cacheKeys[2])); + caches.push(TestDSCacheFactory(cacheKeys[2])); caches[2].put('item', 'value'); caches[2].put('item2', 'value2'); @@ -17,7 +17,7 @@ describe('DSCacheFactory.clearAll()', function () { sinon.spy(caches[1], 'removeAll'); sinon.spy(caches[2], 'removeAll'); - DSCacheFactory.clearAll(); + TestDSCacheFactory.clearAll(); assert.equal(caches[0].removeAll.callCount, 1); assert.equal(caches[1].removeAll.callCount, 1); @@ -29,13 +29,13 @@ describe('DSCacheFactory.clearAll()', function () { var cacheKeys = ['DSCacheFactory.clearAll.cache', 'DSCacheFactory.clearAll.cache1', 'DSCacheFactory.clearAll.cache2'], caches = []; - caches.push(DSCacheFactory(cacheKeys[0])); + caches.push(TestDSCacheFactory(cacheKeys[0])); caches[0].put('item', 'value'); caches[0].put('item2', 'value2'); - caches.push(DSCacheFactory(cacheKeys[1])); + caches.push(TestDSCacheFactory(cacheKeys[1])); caches[1].put('item', 'value'); caches[1].put('item2', 'value2'); - caches.push(DSCacheFactory(cacheKeys[2])); + caches.push(TestDSCacheFactory(cacheKeys[2])); caches[2].put('item', 'value'); caches[2].put('item2', 'value2'); @@ -46,7 +46,7 @@ describe('DSCacheFactory.clearAll()', function () { assert.isDefined(caches[1].get('item2')); assert.isDefined(caches[2].get('item2')); - DSCacheFactory.clearAll(); + TestDSCacheFactory.clearAll(); assert.isUndefined(caches[0].get('item')); assert.isUndefined(caches[1].get('item')); diff --git a/test/unit/DSCacheFactory/index.destroyAll.test.js b/test/unit/DSCacheFactory/index.destroyAll.test.js index f16d32b..82b2a12 100644 --- a/test/unit/DSCacheFactory/index.destroyAll.test.js +++ b/test/unit/DSCacheFactory/index.destroyAll.test.js @@ -3,14 +3,14 @@ describe('DSCacheFactory.destroyAll()', function () { var cacheKeys = ['DSCacheFactory.destroyAll.cache', 'DSCacheFactory.destroyAll.cache1', 'DSCacheFactory.destroyAll.cache2'], caches = []; - caches.push(DSCacheFactory(cacheKeys[0])); - caches.push(DSCacheFactory(cacheKeys[1])); - caches.push(DSCacheFactory(cacheKeys[2])); + caches.push(TestDSCacheFactory(cacheKeys[0])); + caches.push(TestDSCacheFactory(cacheKeys[1])); + caches.push(TestDSCacheFactory(cacheKeys[2])); sinon.spy(caches[0], 'destroy'); sinon.spy(caches[1], 'destroy'); sinon.spy(caches[2], 'destroy'); - DSCacheFactory.destroyAll(); + TestDSCacheFactory.destroyAll(); assert.equal(caches[0].destroy.callCount, 1); assert.equal(caches[1].destroy.callCount, 1); @@ -22,15 +22,15 @@ describe('DSCacheFactory.destroyAll()', function () { var cacheKeys = ['DSCacheFactory.destroyAll.cache', 'DSCacheFactory.destroyAll.cache1', 'DSCacheFactory.destroyAll.cache2'], caches = []; - caches.push(DSCacheFactory(cacheKeys[0])); - caches.push(DSCacheFactory(cacheKeys[1])); - caches.push(DSCacheFactory(cacheKeys[2])); + caches.push(TestDSCacheFactory(cacheKeys[0])); + caches.push(TestDSCacheFactory(cacheKeys[1])); + caches.push(TestDSCacheFactory(cacheKeys[2])); - DSCacheFactory.destroyAll(); + TestDSCacheFactory.destroyAll(); - assert.isUndefined(DSCacheFactory.get(cacheKeys[0])); - assert.isUndefined(DSCacheFactory.get(cacheKeys[1])); - assert.isUndefined(DSCacheFactory.get(cacheKeys[2])); + assert.isUndefined(TestDSCacheFactory.get(cacheKeys[0])); + assert.isUndefined(TestDSCacheFactory.get(cacheKeys[1])); + assert.isUndefined(TestDSCacheFactory.get(cacheKeys[2])); done(); }); diff --git a/test/unit/DSCacheFactory/index.disableAll.test.js b/test/unit/DSCacheFactory/index.disableAll.test.js index 81fde9d..a0556e1 100644 --- a/test/unit/DSCacheFactory/index.disableAll.test.js +++ b/test/unit/DSCacheFactory/index.disableAll.test.js @@ -2,19 +2,19 @@ describe('DSCacheFactory.disableAll()', function () { it('should disable all caches in DSCacheFactory.', function (done) { var cacheKeys = ['DSCacheFactory.disableAll.cache', 'DSCacheFactory.disableAll.cache1', 'DSCacheFactory.disableAll.cache2']; - DSCacheFactory(cacheKeys[0]); - DSCacheFactory(cacheKeys[1], { disabled: true }); - DSCacheFactory(cacheKeys[2]); + TestDSCacheFactory(cacheKeys[0]); + TestDSCacheFactory(cacheKeys[1], { disabled: true }); + TestDSCacheFactory(cacheKeys[2]); - assert.equal(DSCacheFactory.get(cacheKeys[0]).info().disabled, false); - assert.equal(DSCacheFactory.get(cacheKeys[1]).info().disabled, true); - assert.equal(DSCacheFactory.get(cacheKeys[2]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[0]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[1]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[2]).info().disabled, false); - DSCacheFactory.disableAll(); + TestDSCacheFactory.disableAll(); - assert.equal(DSCacheFactory.get(cacheKeys[0]).info().disabled, true); - assert.equal(DSCacheFactory.get(cacheKeys[1]).info().disabled, true); - assert.equal(DSCacheFactory.get(cacheKeys[2]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[0]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[1]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[2]).info().disabled, true); done(); }); diff --git a/test/unit/DSCacheFactory/index.enableAll.test.js b/test/unit/DSCacheFactory/index.enableAll.test.js index 7777d93..d2d5a6e 100644 --- a/test/unit/DSCacheFactory/index.enableAll.test.js +++ b/test/unit/DSCacheFactory/index.enableAll.test.js @@ -2,19 +2,19 @@ describe('DSCacheFactory.enableAll()', function () { it('should enable all caches in DSCacheFactory.', function (done) { var cacheKeys = ['DSCacheFactory.enableAll.cache', 'DSCacheFactory.enableAll.cache1', 'DSCacheFactory.enableAll.cache2']; - DSCacheFactory(cacheKeys[0], { disabled: true }); - DSCacheFactory(cacheKeys[1]); - DSCacheFactory(cacheKeys[2], { disabled: true }); + TestDSCacheFactory(cacheKeys[0], { disabled: true }); + TestDSCacheFactory(cacheKeys[1]); + TestDSCacheFactory(cacheKeys[2], { disabled: true }); - assert.equal(DSCacheFactory.get(cacheKeys[0]).info().disabled, true); - assert.equal(DSCacheFactory.get(cacheKeys[1]).info().disabled, false); - assert.equal(DSCacheFactory.get(cacheKeys[2]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[0]).info().disabled, true); + assert.equal(TestDSCacheFactory.get(cacheKeys[1]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[2]).info().disabled, true); - DSCacheFactory.enableAll(); + TestDSCacheFactory.enableAll(); - assert.equal(DSCacheFactory.get(cacheKeys[0]).info().disabled, false); - assert.equal(DSCacheFactory.get(cacheKeys[1]).info().disabled, false); - assert.equal(DSCacheFactory.get(cacheKeys[2]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[0]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[1]).info().disabled, false); + assert.equal(TestDSCacheFactory.get(cacheKeys[2]).info().disabled, false); done(); }); diff --git a/test/unit/DSCacheFactory/index.get.test.js b/test/unit/DSCacheFactory/index.get.test.js index f21edba..f9bd64c 100644 --- a/test/unit/DSCacheFactory/index.get.test.js +++ b/test/unit/DSCacheFactory/index.get.test.js @@ -2,7 +2,7 @@ describe('DSCacheFactory.get(cacheId)', function () { it('should throw an exception if "cacheId" is not a string.', function (done) { for (var i = 0; i < TYPES_EXCEPT_STRING.length; i++) { try { - DSCacheFactory.get(TYPES_EXCEPT_STRING[i]); + TestDSCacheFactory.get(TYPES_EXCEPT_STRING[i]); fail(); } catch (err) { assert.equal(err.message, '[ng:areq] Expected cacheId to be a string! Found: ' + typeof TYPES_EXCEPT_STRING[i] + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof TYPES_EXCEPT_STRING[i]); @@ -13,14 +13,14 @@ describe('DSCacheFactory.get(cacheId)', function () { done(); }); it('should return "undefined" if the cache does not exist.', function (done) { - assert.isUndefined(DSCacheFactory.get('someNonExistentCache')); + assert.isUndefined(TestDSCacheFactory.get('someNonExistentCache')); done(); }); it('should return the correct cache with the specified cacheId.', function (done) { - var cache = DSCacheFactory('DSCacheFactory.get.cache'), - cache2 = DSCacheFactory('DSCacheFactory.get.cache2'); - assert.equal(DSCacheFactory.get('DSCacheFactory.get.cache'), cache); - assert.equal(DSCacheFactory.get('DSCacheFactory.get.cache2'), cache2); + var cache = TestDSCacheFactory('DSCacheFactory.get.cache'), + cache2 = TestDSCacheFactory('DSCacheFactory.get.cache2'); + assert.equal(TestDSCacheFactory.get('DSCacheFactory.get.cache'), cache); + assert.equal(TestDSCacheFactory.get('DSCacheFactory.get.cache2'), cache2); assert.notEqual(cache, cache2); done(); diff --git a/test/unit/DSCacheFactory/index.info.test.js b/test/unit/DSCacheFactory/index.info.test.js index 9bbdea9..0e5bedc 100644 --- a/test/unit/DSCacheFactory/index.info.test.js +++ b/test/unit/DSCacheFactory/index.info.test.js @@ -7,15 +7,15 @@ describe('DSCacheFactory.info()', function () { }, caches = []; - caches.push(DSCacheFactory('cache')); - caches.push(DSCacheFactory('cache2', { + caches.push(TestDSCacheFactory('cache')); + caches.push(TestDSCacheFactory('cache2', { maxAge: options.maxAge })); - caches.push(DSCacheFactory('cache3', { + caches.push(TestDSCacheFactory('cache3', { capacity: options.capacity, cacheFlushInterval: options.cacheFlushInterval })); - var info = DSCacheFactory.info(); + var info = TestDSCacheFactory.info(); assert.equal(info.size, 3); assert.equal(info.cacheDefaults.capacity, CACHE_DEFAULTS.capacity); diff --git a/test/unit/DSCacheFactory/index.keySet.test.js b/test/unit/DSCacheFactory/index.keySet.test.js index 078f351..926d97f 100644 --- a/test/unit/DSCacheFactory/index.keySet.test.js +++ b/test/unit/DSCacheFactory/index.keySet.test.js @@ -2,11 +2,11 @@ describe('DSCacheFactory.keySet()', function () { it('should return the set of keys of all caches in DSCacheFactory.', function (done) { var cacheKeys = ['DSCacheFactory.keySet.cache', 'DSCacheFactory.keySet.cache1', 'DSCacheFactory.keySet.cache2']; - DSCacheFactory(cacheKeys[0]); - DSCacheFactory(cacheKeys[1]); - DSCacheFactory(cacheKeys[2]); + TestDSCacheFactory(cacheKeys[0]); + TestDSCacheFactory(cacheKeys[1]); + TestDSCacheFactory(cacheKeys[2]); - var keySet = DSCacheFactory.keySet(); + var keySet = TestDSCacheFactory.keySet(); assert.equal(keySet.hasOwnProperty(cacheKeys[0]), true); assert.equal(keySet.hasOwnProperty(cacheKeys[1]), true); @@ -16,8 +16,8 @@ describe('DSCacheFactory.keySet()', function () { assert.equal(keySet[cacheKeys[1]], cacheKeys[1]); assert.equal(keySet[cacheKeys[2]], cacheKeys[2]); - DSCacheFactory.get(cacheKeys[0]).destroy(); - keySet = DSCacheFactory.keySet(); + TestDSCacheFactory.get(cacheKeys[0]).destroy(); + keySet = TestDSCacheFactory.keySet(); assert.equal(keySet.hasOwnProperty(cacheKeys[0]), false); assert.equal(keySet.hasOwnProperty(cacheKeys[1]), true); assert.equal(keySet.hasOwnProperty(cacheKeys[2]), true); @@ -25,8 +25,8 @@ describe('DSCacheFactory.keySet()', function () { assert.equal(keySet[cacheKeys[1]], cacheKeys[1]); assert.equal(keySet[cacheKeys[2]], cacheKeys[2]); - DSCacheFactory.get(cacheKeys[1]).destroy(); - keySet = DSCacheFactory.keySet(); + TestDSCacheFactory.get(cacheKeys[1]).destroy(); + keySet = TestDSCacheFactory.keySet(); assert.equal(keySet.hasOwnProperty(cacheKeys[0]), false); assert.equal(keySet.hasOwnProperty(cacheKeys[1]), false); assert.equal(keySet.hasOwnProperty(cacheKeys[2]), true); @@ -34,9 +34,9 @@ describe('DSCacheFactory.keySet()', function () { assert.isUndefined(keySet[cacheKeys[1]]); assert.equal(keySet[cacheKeys[2]], cacheKeys[2]); - DSCacheFactory.get(cacheKeys[2]).destroy(); + TestDSCacheFactory.get(cacheKeys[2]).destroy(); - keySet = DSCacheFactory.keySet(); + keySet = TestDSCacheFactory.keySet(); assert.equal(keySet.hasOwnProperty(cacheKeys[0]), false); assert.equal(keySet.hasOwnProperty(cacheKeys[1]), false); diff --git a/test/unit/DSCacheFactory/index.keys.test.js b/test/unit/DSCacheFactory/index.keys.test.js index a0c95ad..15e073f 100644 --- a/test/unit/DSCacheFactory/index.keys.test.js +++ b/test/unit/DSCacheFactory/index.keys.test.js @@ -2,30 +2,30 @@ describe('DSCacheFactory.keys()', function () { it('should return the array of keys of all caches in DSCacheFactory.', function (done) { var cacheKeys = ['cache', 'cache1', 'cache2']; - DSCacheFactory(cacheKeys[0]); - DSCacheFactory(cacheKeys[1]); - DSCacheFactory(cacheKeys[2]); + TestDSCacheFactory(cacheKeys[0]); + TestDSCacheFactory(cacheKeys[1]); + TestDSCacheFactory(cacheKeys[2]); - var keys = DSCacheFactory.keys(); + var keys = TestDSCacheFactory.keys(); assert.equal(keys.length, 3); assert.equal(keys[0], cacheKeys[0]); assert.equal(keys[1], cacheKeys[1]); assert.equal(keys[2], cacheKeys[2]); - DSCacheFactory.get(cacheKeys[0]).destroy(); - keys = DSCacheFactory.keys(); + TestDSCacheFactory.get(cacheKeys[0]).destroy(); + keys = TestDSCacheFactory.keys(); assert.equal(keys.length, 2); assert.notEqual(keys.indexOf(cacheKeys[1]), -1); assert.notEqual(keys.indexOf(cacheKeys[2]), -1); - DSCacheFactory.get(cacheKeys[1]).destroy(); - keys = DSCacheFactory.keys(); + TestDSCacheFactory.get(cacheKeys[1]).destroy(); + keys = TestDSCacheFactory.keys(); assert.equal(keys.length, 1); assert.notEqual(keys.indexOf(cacheKeys[2]), -1); - DSCacheFactory.get(cacheKeys[2]).destroy(); + TestDSCacheFactory.get(cacheKeys[2]).destroy(); - keys = DSCacheFactory.keys(); + keys = TestDSCacheFactory.keys(); assert.equal(keys.length, 0); diff --git a/test/unit/DSCacheFactory/index.test.js b/test/unit/DSCacheFactory/index.test.js index a66d271..2916305 100644 --- a/test/unit/DSCacheFactory/index.test.js +++ b/test/unit/DSCacheFactory/index.test.js @@ -1,6 +1,6 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should be able to create a default cache.', function (done) { - var cache = DSCacheFactory('DSCacheFactory.cache'); + var cache = TestDSCacheFactory('DSCacheFactory.cache'); assert.isDefined(cache); assert.equal(cache.info().id, 'DSCacheFactory.cache'); assert.equal(cache.info().capacity, CACHE_DEFAULTS.capacity); @@ -34,7 +34,7 @@ describe('DSCacheFactory(cacheId, options)', function () { }, readOnGet: false }; - var cache = DSCacheFactory('DSCacheFactory.cache', options); + var cache = TestDSCacheFactory('DSCacheFactory.cache', options); assert.isDefined(cache); assert.equal(cache.info().id, 'DSCacheFactory.cache'); assert.equal(cache.info().capacity, options.capacity); @@ -49,7 +49,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should throw an exception if "capacity" is not a number or is less than zero.', function (done) { var capacity = Math.floor((Math.random() * 100000) + 1) * -1; try { - DSCacheFactory('capacityCache99', { capacity: capacity }); + TestDSCacheFactory('capacityCache99', { capacity: capacity }); fail(); } catch (err) { var msg = err.message; @@ -60,7 +60,7 @@ describe('DSCacheFactory(cacheId, options)', function () { continue; } try { - DSCacheFactory('capacityCache' + i, { capacity: TYPES_EXCEPT_NUMBER[i] }); + TestDSCacheFactory('capacityCache' + i, { capacity: TYPES_EXCEPT_NUMBER[i] }); fail(); } catch (err) { assert.equal(err.message, '[ng:areq] Expected capacity to be a number! Found: ' + typeof TYPES_EXCEPT_NUMBER[i] + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof TYPES_EXCEPT_NUMBER[i]); @@ -73,7 +73,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate maxAge.', function (done) { var maxAge = Math.floor((Math.random() * 100000) + 1) * -1; try { - DSCacheFactory('maxAgeCache99', { maxAge: maxAge }); + TestDSCacheFactory('maxAgeCache99', { maxAge: maxAge }); fail(); } catch (err) { var msg = err.message; @@ -81,7 +81,7 @@ describe('DSCacheFactory(cacheId, options)', function () { assert.equal(msg, '[ng:areq] Expected maxAge to be greater than zero! Found: ' + maxAge + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + maxAge); for (var i = 0; i < TYPES_EXCEPT_NUMBER.length; i++) { try { - DSCacheFactory('maxAgeCache' + i, { maxAge: TYPES_EXCEPT_NUMBER[i] }); + TestDSCacheFactory('maxAgeCache' + i, { maxAge: TYPES_EXCEPT_NUMBER[i] }); if (TYPES_EXCEPT_NUMBER[i] !== null) { fail(TYPES_EXCEPT_NUMBER[i]); } @@ -99,7 +99,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate cacheFlushInterval.', function (done) { var cacheFlushInterval = Math.floor((Math.random() * 100000) + 1) * -1; try { - DSCacheFactory('cacheFlushIntervalCache99', { cacheFlushInterval: cacheFlushInterval }); + TestDSCacheFactory('cacheFlushIntervalCache99', { cacheFlushInterval: cacheFlushInterval }); fail(); } catch (err) { var msg = err.message; @@ -107,7 +107,7 @@ describe('DSCacheFactory(cacheId, options)', function () { assert.equal(msg, '[ng:areq] Expected cacheFlushInterval to be greater than zero! Found: ' + cacheFlushInterval + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + cacheFlushInterval); for (var i = 0; i < TYPES_EXCEPT_NUMBER.length; i++) { try { - DSCacheFactory('cacheFlushIntervalCache' + i, { cacheFlushInterval: TYPES_EXCEPT_NUMBER[i] }); + TestDSCacheFactory('cacheFlushIntervalCache' + i, { cacheFlushInterval: TYPES_EXCEPT_NUMBER[i] }); if (TYPES_EXCEPT_NUMBER[i] !== null) { fail(); } @@ -125,7 +125,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate recycleFreq.', function (done) { var recycleFreq = Math.floor((Math.random() * 100000) + 1) * -1; try { - DSCacheFactory('recycleFreqCache99', { recycleFreq: recycleFreq }); + TestDSCacheFactory('recycleFreqCache99', { recycleFreq: recycleFreq }); fail(); } catch (err) { var msg = err.message; @@ -133,7 +133,7 @@ describe('DSCacheFactory(cacheId, options)', function () { assert.equal(msg, '[ng:areq] Expected recycleFreq to be greater than zero! Found: ' + recycleFreq + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + recycleFreq); for (var i = 0; i < TYPES_EXCEPT_NUMBER.length; i++) { try { - DSCacheFactory('recycleFreqCache' + i, { recycleFreq: TYPES_EXCEPT_NUMBER[i] }); + TestDSCacheFactory('recycleFreqCache' + i, { recycleFreq: TYPES_EXCEPT_NUMBER[i] }); if (TYPES_EXCEPT_NUMBER[i] !== null) { fail(); } @@ -151,7 +151,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate onExpire.', function (done) { var onExpire = 234; try { - DSCacheFactory('onExpireCache99', { onExpire: onExpire }); + TestDSCacheFactory('onExpireCache99', { onExpire: onExpire }); assert.equal('should not reach this!', false); } catch (err) { var msg = err.message; @@ -160,7 +160,7 @@ describe('DSCacheFactory(cacheId, options)', function () { for (var i = 0; i < TYPES_EXCEPT_FUNCTION.length; i++) { try { if (TYPES_EXCEPT_FUNCTION[i]) { - DSCacheFactory('onExpireCache' + i, { onExpire: TYPES_EXCEPT_FUNCTION[i] }); + TestDSCacheFactory('onExpireCache' + i, { onExpire: TYPES_EXCEPT_FUNCTION[i] }); } else { continue; } @@ -178,7 +178,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate deleteOnExpire.', function (done) { var deleteOnExpire = 'fail'; try { - DSCacheFactory('cache', { deleteOnExpire: deleteOnExpire }); + TestDSCacheFactory('cache', { deleteOnExpire: deleteOnExpire }); fail('should not reach this!'); } catch (err) { var msg = err.message; @@ -189,7 +189,7 @@ describe('DSCacheFactory(cacheId, options)', function () { continue; } try { - DSCacheFactory('deleteOnExpireCache' + i, { deleteOnExpire: TYPES_EXCEPT_STRING[i] }); + TestDSCacheFactory('deleteOnExpireCache' + i, { deleteOnExpire: TYPES_EXCEPT_STRING[i] }); fail(TYPES_EXCEPT_STRING[i]); } catch (err) { assert.equal(err.message, '[ng:areq] Expected deleteOnExpire to be a string! Found: ' + typeof TYPES_EXCEPT_STRING[i] + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof TYPES_EXCEPT_STRING[i]); @@ -203,7 +203,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate storageMode.', function (done) { var storageMode = 'fail'; try { - DSCacheFactory('cache', { storageMode: storageMode }); + TestDSCacheFactory('cache', { storageMode: storageMode }); assert.equal('should not reach this!', false); } catch (err) { var msg = err.message; @@ -211,7 +211,7 @@ describe('DSCacheFactory(cacheId, options)', function () { assert.equal(msg, '[ng:areq] Expected storageMode to be "memory", "localStorage" or "sessionStorage"! Found: ' + storageMode + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + storageMode); for (var i = 0; i < TYPES_EXCEPT_STRING.length; i++) { try { - DSCacheFactory('storageModeCache' + i, { storageMode: TYPES_EXCEPT_STRING[i] }); + TestDSCacheFactory('storageModeCache' + i, { storageMode: TYPES_EXCEPT_STRING[i] }); fail(TYPES_EXCEPT_STRING[i]); } catch (err) { assert.equal(err.message, '[ng:areq] Expected storageMode to be a string! Found: ' + typeof TYPES_EXCEPT_STRING[i] + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof TYPES_EXCEPT_STRING[i]); @@ -225,7 +225,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should validate storageImpl.', function (done) { var storageImpl = 'fail'; try { - DSCacheFactory('cache', { storageMode: 'localStorage', storageImpl: storageImpl }); + TestDSCacheFactory('cache', { storageMode: 'localStorage', storageImpl: storageImpl }); assert.equal('should not reach this!', false); } catch (err) { var msg = err.message; @@ -233,7 +233,7 @@ describe('DSCacheFactory(cacheId, options)', function () { assert.equal(msg, '[ng:areq] Expected storageImpl to be an object! Found: ' + typeof storageImpl + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof storageImpl); for (var i = 0; i < TYPES_EXCEPT_OBJECT.length; i++) { try { - DSCacheFactory('storageImplCache' + i, { storageMode: 'localStorage', storageImpl: TYPES_EXCEPT_OBJECT[i] }); + TestDSCacheFactory('storageImplCache' + i, { storageMode: 'localStorage', storageImpl: TYPES_EXCEPT_OBJECT[i] }); if (TYPES_EXCEPT_OBJECT[i] !== null && TYPES_EXCEPT_OBJECT[i] !== undefined && TYPES_EXCEPT_OBJECT[i] !== false) { fail(TYPES_EXCEPT_OBJECT[i]); } @@ -252,7 +252,7 @@ describe('DSCacheFactory(cacheId, options)', function () { removeItem: function () { } }; - DSCacheFactory('storageImplCache-noSetItem', { + TestDSCacheFactory('storageImplCache-noSetItem', { storageMode: 'localStorage', storageImpl: storageImpl }); @@ -267,7 +267,7 @@ describe('DSCacheFactory(cacheId, options)', function () { removeItem: function () { } }; - DSCacheFactory('storageImplCache-noGetItem', { + TestDSCacheFactory('storageImplCache-noGetItem', { storageMode: 'localStorage', storageImpl: storageImpl }); @@ -282,7 +282,7 @@ describe('DSCacheFactory(cacheId, options)', function () { setItem: function () { } }; - DSCacheFactory('storageImplCache-noRemoveItem', { + TestDSCacheFactory('storageImplCache-noRemoveItem', { storageMode: 'localStorage', storageImpl: storageImpl }); @@ -295,8 +295,8 @@ describe('DSCacheFactory(cacheId, options)', function () { }); it('should prevent a cache from being duplicated.', function (done) { try { - DSCacheFactory('cache'); - DSCacheFactory('cache'); + TestDSCacheFactory('cache'); + TestDSCacheFactory('cache'); } catch (err) { var msg = err.message; } @@ -307,7 +307,7 @@ describe('DSCacheFactory(cacheId, options)', function () { it('should require cacheId to be a string.', function (done) { for (var i = 0; i < TYPES_EXCEPT_STRING.length; i++) { try { - DSCacheFactory(TYPES_EXCEPT_STRING[i]); + TestDSCacheFactory(TYPES_EXCEPT_STRING[i]); fail(TYPES_EXCEPT_STRING[i]); } catch (err) { assert.equal(err.message, '[ng:areq] Expected cacheId to be a string! Found: ' + typeof TYPES_EXCEPT_STRING[i] + '.\nhttp://errors.angularjs.org/' + angular.version.full + '/ng/areq?p0=' + typeof TYPES_EXCEPT_STRING[i]);