diff --git a/README.md b/README.md index 4829c7b..b70ffa5 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,19 @@ Memoization is best technique to save on memory or CPU cycles when we deal with ### Features -* Works with any type of function arguments – **no serialization is needed** -* Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic. -* One of the [**fastest**](#benchmarks) available solutions. -* Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions) -* [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings. -* [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration -* Can be configured [**for methods**](#memoizing-methods) (when `this` counts in) -* Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time) -* Cache size can be **[limited on LRU basis](#limiting-cache-size)** -* Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function. -* Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management -* [**Profile tool**](#profiling--statistics) that provides valuable usage statistics -* Covered by [**over 500 unit tests**](#tests) +- Works with any type of function arguments – **no serialization is needed** +- Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic. +- One of the [**fastest**](#benchmarks) available solutions. +- Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions) +- [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings. +- [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration +- Can be configured [**for methods**](#memoizing-methods) (when `this` counts in) +- Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time) +- Cache size can be **[limited on LRU basis](#limiting-cache-size)** +- Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function. +- Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management +- [**Profile tool**](#profiling--statistics) that provides valuable usage statistics +- Covered by [**over 500 unit tests**](#tests) ### Installation @@ -46,9 +46,7 @@ To port it to Browser or any other (non CJS) environment, use your favorite CJS ```javascript var memoize = require("memoizee"); -var fn = function(one, two, three) { - /* ... */ -}; +var fn = function (one, two, three) { /* ... */ }; memoized = memoize(fn); @@ -56,7 +54,7 @@ memoized("foo", 3, "bar"); memoized("foo", 3, "bar"); // Cache hit ``` -__Note__: Invocations that throw exceptions are not cached. +**Note**: Invocations that throw exceptions are not cached. ### Configuration @@ -76,7 +74,7 @@ memoized("foo", 3, {}); // Third argument is ignored (but passed to underlying f memoized("foo", 3, 13); // Cache hit ``` -__Note:__ [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly +**Note:** [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly Dynamic _length_ behavior can be forced by setting _length_ to `false`, that means memoize will work with any number of arguments. @@ -108,8 +106,8 @@ memoized("/path/one"); // Cache hit By default cache id for given call is resolved either by: -* Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values. -* Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays) +- Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values. +- Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays) Still above two methods do not serve all cases, e.g. if we want to memoize function where arguments are hash objects which we do not want to compare by instance but by its content. @@ -117,21 +115,21 @@ Still above two methods do not serve all cases, e.g. if we want to memoize funct There's a `normalizer` option through which we can pass custom cache id normalization function. -###### Memoizing on dictionary (object hash) arguments) +###### Memoizing on dictionary (object hash) arguments) if we want to memoize a function where argument is a hash object which we do not want to compare by instance but by its content, then we can achieve it as following: ```javascript var mfn = memoize( - function(hash) { - // body of memoized function - }, - { - normalizer: function(args) { - // args is arguments object as accessible in memoized function - return JSON.stringify(args[0]); - } - } + function (hash) { + // body of memoized function + }, + { + normalizer: function (args) { + // args is arguments object as accessible in memoized function + return JSON.stringify(args[0]); + }, + } ); mfn({ foo: "bar" }); @@ -142,23 +140,23 @@ If additionally we want to ensure that our logic works well with different order ```javascript const deepSortedEntries = object => - Object.entries(object) - .map(([key, value]) => { - if (value && typeof value === "object") return [key, deepSortedEntries(value)]; - return [key, value]; - }) - .sort(); + Object.entries(object) + .map(([key, value]) => { + if (value && typeof value === "object") return [key, deepSortedEntries(value)]; + return [key, value]; + }) + .sort(); var mfn = memoize( - function(hash) { - // body of memoized function - }, - { - normalizer: function(args) { - // args is arguments object as accessible in memoized function - return JSON.stringify(deepSortedEntries(args[0])); - } - } + function (hash) { + // body of memoized function + }, + { + normalizer: function (args) { + // args is arguments object as accessible in memoized function + return JSON.stringify(deepSortedEntries(args[0])); + }, + } ); mfn({ foo: "bar", bar: "foo" }); @@ -174,14 +172,7 @@ memoized = memoize(fn, { length: 2, resolvers: [String, Boolean] }); memoized(12, [1, 2, 3].length); memoized("12", true); // Cache hit -memoized( - { - toString: function() { - return "12"; - } - }, - {} -); // Cache hit +memoized({ toString: function () { return "12"; } }, {}); // Cache hit ``` **Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings**, for it's best to just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions, or rely on `JSON.stringify`. @@ -198,10 +189,8 @@ The difference from natural behavior is that in case when promise was rejected w the result is immediately removed from memoize cache, and not kept as further reusable result. ```javascript -var afn = function(a, b) { - return new Promise(function(res) { - res(a + b); - }); +var afn = function (a, b) { + return new Promise(function (res) { res(a + b); }); }; memoized = memoize(afn, { promise: true }); @@ -220,13 +209,13 @@ memoized = memoize(afn, { promise: "done:finally" }); Supported modes -* `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise - come with no logged warning!**, and that to avoid implied error swallowing both states are resolved tick after callbacks were invoked +- `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise + come with no logged warning!**, and that to avoid implied error swallowing both states are resolved tick after callbacks were invoked -* `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**. +- `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**. -* `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally - if no _onFailure_ callback was passed to `done`, and promise error was handled by other consumer (this is not commonly implemented _done_ behavior). Otherwise side-effect is that exception is thrown on promise rejection (highly not recommended) +- `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally + if no _onFailure_ callback was passed to `done`, and promise error was handled by other consumer (this is not commonly implemented _done_ behavior). Otherwise side-effect is that exception is thrown on promise rejection (highly not recommended) ##### Node.js callback style functions @@ -234,21 +223,19 @@ With _async_ option we indicate that we memoize asynchronous (Node.js style) fun Operations that result with an error are not cached. ```javascript -afn = function(a, b, cb) { - setTimeout(function() { - cb(null, a + b); - }, 200); +afn = function (a, b, cb) { + setTimeout(function () { cb(null, a + b); }, 200); }; memoized = memoize(afn, { async: true }); -memoized(3, 7, function(err, res) { - memoized(3, 7, function(err, res) { - // Cache hit - }); +memoized(3, 7, function (err, res) { + memoized(3, 7, function (err, res) { + // Cache hit + }); }); -memoized(3, 7, function(err, res) { - // Cache hit +memoized(3, 7, function (err, res) { + // Cache hit }); ``` @@ -257,12 +244,12 @@ memoized(3, 7, function(err, res) { When we are defining a prototype, we may want to define a method that will memoize it's results in relation to each instance. A basic way to obtain that would be: ```javascript -var Foo = function() { - this.bar = memoize(this.bar.bind(this), { someOption: true }); - // ... constructor logic +var Foo = function () { + this.bar = memoize(this.bar.bind(this), { someOption: true }); + // ... constructor logic }; -Foo.prototype.bar = function() { - // ... method logic +Foo.prototype.bar = function () { + // ... method logic }; ``` @@ -272,19 +259,19 @@ There's a lazy methods descriptor generator provided: var d = require("d"); var memoizeMethods = require("memoizee/methods"); -var Foo = function() { - // ... constructor logic +var Foo = function () { + // ... constructor logic }; Object.defineProperties( - Foo.prototype, - memoizeMethods({ - bar: d( - function() { - // ... method logic - }, - { someOption: true } - ) - }) + Foo.prototype, + memoizeMethods({ + bar: d( + function () { + // ... method logic + }, + { someOption: true } + ), + }) ); ``` @@ -298,9 +285,7 @@ It can be combined with other options mentioned across documentation. However du ```javascript var memoize = require("memoizee/weak"); -var memoized = memoize(function(obj) { - return Object.keys(obj); -}); +var memoized = memoize(function (obj) { return Object.keys(obj); }); var obj = { foo: true, bar: false }; memoized(obj); @@ -334,9 +319,9 @@ memoized = memoize(fn, { maxAge: 1000 }); // 1 second memoized("foo", 3); memoized("foo", 3); // Cache hit -setTimeout(function() { - memoized("foo", 3); // No longer in cache, re-executed - memoized("foo", 3); // Cache hit +setTimeout(function () { + memoized("foo", 3); // No longer in cache, re-executed + memoized("foo", 3); // Cache hit }, 2000); ``` @@ -348,16 +333,16 @@ memoized = memoize(fn, { maxAge: 1000, preFetch: true }); // Defaults to 0.33 memoized("foo", 3); memoized("foo", 3); // Cache hit -setTimeout(function() { - memoized("foo", 3); // Cache hit +setTimeout(function () { + memoized("foo", 3); // Cache hit }, 500); -setTimeout(function() { - memoized("foo", 3); // Cache hit, silently pre-fetched in next tick +setTimeout(function () { + memoized("foo", 3); // Cache hit, silently pre-fetched in next tick }, 800); -setTimeout(function() { - memoized("foo", 3); // Cache hit +setTimeout(function () { + memoized("foo", 3); // Cache hit }, 1300); ``` @@ -369,12 +354,12 @@ memoized = memoize(fn, { maxAge: 1000, preFetch: 0.6 }); memoized("foo", 3); memoized("foo", 3); // Cache hit -setTimeout(function() { - memoized("foo", 3); // Cache hit, silently pre-fetched in next tick +setTimeout(function () { + memoized("foo", 3); // Cache hit, silently pre-fetched in next tick }, 500); -setTimeout(function() { - memoized("foo", 3); // Cache hit +setTimeout(function () { + memoized("foo", 3); // Cache hit }, 1300); ``` @@ -422,11 +407,7 @@ memoized("bar", 7); // Re-executed, Cache cleared for 'lorem', 11 You can register a callback to be called on each value removed from the cache: ```javascript -memoized = memoize(fn, { - dispose: function(value) { - /*…*/ - } -}); +memoized = memoize(fn, { dispose: function (value) { /*…*/ } }); var foo3 = memoized("foo", 3); var bar7 = memoized("bar", 7); @@ -494,10 +475,10 @@ Memoize statistics: ------------------------------------------------------------ ``` -* _Init_ – Initial hits -* _Cache_ – Cache hits -* _%Cache_ – What's the percentage of cache hits (of all function calls) -* _Source location_ – Where in the source code given memoization was initialized +- _Init_ – Initial hits +- _Cache_ – Cache hits +- _%Cache_ – What's the percentage of cache hits (of all function calls) +- _Source location_ – Where in the source code given memoization was initialized ### Tests @@ -525,8 +506,8 @@ To report a security vulnerability, please use the [Tidelift security contact](h ### Contributors -* [@puzrin](https://github.com/puzrin) (Vitaly Puzrin) - * Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant +- [@puzrin](https://github.com/puzrin) (Vitaly Puzrin) + - Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant [nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/memoizee/branches/master/shields_badge.svg [nix-build-url]: https://semaphoreci.com/medikoo-org/memoizee diff --git a/benchmark/fibonacci.js b/benchmark/fibonacci.js index 3a704e7..655810f 100644 --- a/benchmark/fibonacci.js +++ b/benchmark/fibonacci.js @@ -31,9 +31,7 @@ var now = Date.now , lruObj; getFib = function (memoize, opts) { - var fib = memoize(function (x) { - return x < 2 ? 1 : fib(x - 1) + fib(x - 2); - }, opts); + var fib = memoize(function (x) { return x < 2 ? 1 : fib(x - 1) + fib(x - 2); }, opts); return fib; }; @@ -134,7 +132,5 @@ forEach( console.log(currentIndex + 1 + ":", pad.call(value, " ", 5) + "ms ", name); }, null, - function (a, b) { - return this[a] - this[b]; - } + function (a, b) { return this[a] - this[b]; } ); diff --git a/commitlint.config.js b/commitlint.config.js index a238900..b4e758b 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -16,7 +16,7 @@ module.exports = { "type-empty": [2, "never"], "type-enum": [ 2, "always", - ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"] - ] - } + ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"], + ], + }, }; diff --git a/ext/async.js b/ext/async.js index a4cbd8d..94b2dbf 100644 --- a/ext/async.js +++ b/ext/async.js @@ -28,7 +28,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) { currentCallback = last; args = slice.call(args, 0, -1); } - return base.apply(currentContext = this, currentArgs = args); + return base.apply((currentContext = this), (currentArgs = args)); }, base); try { mixin(conf.memoized, base); } catch (ignore) {} diff --git a/ext/dispose.js b/ext/dispose.js index 2eb9a23..4f79646 100644 --- a/ext/dispose.js +++ b/ext/dispose.js @@ -5,29 +5,23 @@ var callable = require("es5-ext/object/valid-callable") , forEach = require("es5-ext/object/for-each") , extensions = require("../lib/registered-extensions") - - , apply = Function.prototype.apply; + , apply = Function.prototype.apply; extensions.dispose = function (dispose, conf, options) { var del; callable(dispose); if ((options.async && extensions.async) || (options.promise && extensions.promise)) { - conf.on("deleteasync", del = function (id, resultArray) { - apply.call(dispose, null, resultArray); - }); + conf.on( + "deleteasync", + (del = function (id, resultArray) { apply.call(dispose, null, resultArray); }) + ); conf.on("clearasync", function (cache) { - forEach(cache, function (result, id) { - del(id, result); -}); + forEach(cache, function (result, id) { del(id, result); }); }); return; } - conf.on("delete", del = function (id, result) { - dispose(result); -}); + conf.on("delete", (del = function (id, result) { dispose(result); })); conf.on("clear", function (cache) { - forEach(cache, function (result, id) { - del(id, result); -}); + forEach(cache, function (result, id) { del(id, result); }); }); }; diff --git a/ext/max.js b/ext/max.js index 13d120e..8f48adf 100644 --- a/ext/max.js +++ b/ext/max.js @@ -13,14 +13,19 @@ extensions.max = function (max, conf, options) { if (!max) return; queue = lruQueue(max); - postfix = (options.async && extensions.async) || (options.promise && extensions.promise) - ? "async" : ""; + postfix = + (options.async && extensions.async) || (options.promise && extensions.promise) + ? "async" + : ""; - conf.on("set" + postfix, hit = function (id) { - id = queue.hit(id); - if (id === undefined) return; - conf.delete(id); - }); + conf.on( + "set" + postfix, + (hit = function (id) { + id = queue.hit(id); + if (id === undefined) return; + conf.delete(id); + }) + ); conf.on("get" + postfix, hit); conf.on("delete" + postfix, queue.delete); conf.on("clear" + postfix, queue.clear); diff --git a/ext/ref-counter.js b/ext/ref-counter.js index 5fd8c28..396dae5 100644 --- a/ext/ref-counter.js +++ b/ext/ref-counter.js @@ -2,30 +2,24 @@ "use strict"; -var d = require("d") - , extensions = require("../lib/registered-extensions") - - , create = Object.create, defineProperties = Object.defineProperties; +var d = require("d") + , extensions = require("../lib/registered-extensions") + , create = Object.create + , defineProperties = Object.defineProperties; extensions.refCounter = function (ignore, conf, options) { var cache, postfix; cache = create(null); - postfix = (options.async && extensions.async) || (options.promise && extensions.promise) - ? "async" : ""; + postfix = + (options.async && extensions.async) || (options.promise && extensions.promise) + ? "async" + : ""; - conf.on("set" + postfix, function (id, length) { - cache[id] = length || 1; -}); - conf.on("get" + postfix, function (id) { - ++cache[id]; -}); - conf.on("delete" + postfix, function (id) { - delete cache[id]; -}); - conf.on("clear" + postfix, function () { - cache = {}; -}); + conf.on("set" + postfix, function (id, length) { cache[id] = length || 1; }); + conf.on("get" + postfix, function (id) { ++cache[id]; }); + conf.on("delete" + postfix, function (id) { delete cache[id]; }); + conf.on("clear" + postfix, function () { cache = {}; }); defineProperties(conf.memoized, { deleteRef: d(function () { @@ -43,6 +37,6 @@ extensions.refCounter = function (ignore, conf, options) { if (id === null) return 0; if (!cache[id]) return 0; return cache[id]; - }) + }), }); }; diff --git a/index.js b/index.js index 6731a0d..7639ee3 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,8 @@ module.exports = function (fn/*, options*/) { options.normalizer = require("./normalizers/get-primitive-fixed")(length); } } else if (length === false) options.normalizer = require("./normalizers/get")(); - else if (length === 1) options.normalizer = require("./normalizers/get-1")(); - else options.normalizer = require("./normalizers/get-fixed")(length); + else if (length === 1) options.normalizer = require("./normalizers/get-1")(); + else options.normalizer = require("./normalizers/get-fixed")(length); } } diff --git a/lib/configure-map.js b/lib/configure-map.js index 139398b..e11aa34 100644 --- a/lib/configure-map.js +++ b/lib/configure-map.js @@ -136,7 +136,7 @@ module.exports = function (original, length, options) { return on.call(this, type, listener); }, emit: emit, - updateEnv: function () { original = conf.original; } + updateEnv: function () { original = conf.original; }, }; if (get) { extDel = defineLength(function (arg) { @@ -176,7 +176,7 @@ module.exports = function (original, length, options) { delete: d(extDel), clear: d(conf.clear), _get: d(extGet), - _has: d(extHas) + _has: d(extHas), }); return conf; }; diff --git a/lib/methods.js b/lib/methods.js index 779b699..d8cd8a7 100644 --- a/lib/methods.js +++ b/lib/methods.js @@ -16,9 +16,7 @@ module.exports = function (memoize) { options = normalizeOpts(options); if (length === undefined) { length = resolveLength( - options.length, - fn.length, - options.async && extensions.async + options.length, fn.length, options.async && extensions.async ); } options.normalizer = options.getNormalizer(length); diff --git a/lib/resolve-resolve.js b/lib/resolve-resolve.js index 578eb37..577d51d 100644 --- a/lib/resolve-resolve.js +++ b/lib/resolve-resolve.js @@ -7,15 +7,13 @@ var toArray = require("es5-ext/array/to-array") var slice = Array.prototype.slice, resolveArgs; resolveArgs = function (args) { - return this.map(function (resolve, i) { - return resolve ? resolve(args[i]) : args[i]; - }).concat(slice.call(args, this.length)); + return this.map(function (resolve, i) { return resolve ? resolve(args[i]) : args[i]; }).concat( + slice.call(args, this.length) + ); }; module.exports = function (resolvers) { resolvers = toArray(resolvers); - resolvers.forEach(function (resolve) { - if (isValue(resolve)) callable(resolve); - }); + resolvers.forEach(function (resolve) { if (isValue(resolve)) callable(resolve); }); return resolveArgs.bind(resolvers); }; diff --git a/lib/weak.js b/lib/weak.js index c48c910..a36e43d 100644 --- a/lib/weak.js +++ b/lib/weak.js @@ -58,7 +58,7 @@ module.exports = function (memoize) { delete: d(function (obj) { if (resolve) obj = resolve(arguments)[0]; return map.delete(obj); - }) + }), } ); } @@ -82,7 +82,7 @@ module.exports = function (memoize) { ); } } - map.set(obj, memoizer = memoize(partial.call(fn, obj), options)); + map.set(obj, (memoizer = memoize(partial.call(fn, obj), options))); } return memoizer.apply(this, slice.call(args, 1)); }, length), @@ -99,7 +99,7 @@ module.exports = function (memoize) { if (!memoizer) return; memoizer.delete.apply(this, slice.call(args, 1)); }, length) - ) + ), } ); if (!options.refCounter) return memoized; @@ -127,7 +127,7 @@ module.exports = function (memoize) { if (!memoizer) return 0; return memoizer.getRefCount.apply(this, slice.call(args, 1)); }, length) - ) + ), }); return memoized; }; diff --git a/normalizers/get-1.js b/normalizers/get-1.js index 292463b..007c01a 100644 --- a/normalizers/get-1.js +++ b/normalizers/get-1.js @@ -24,6 +24,6 @@ module.exports = function () { clear: function () { argsMap = []; cache = []; - } + }, }; }; diff --git a/normalizers/get-fixed.js b/normalizers/get-fixed.js index 86f6aff..ee64f88 100644 --- a/normalizers/get-fixed.js +++ b/normalizers/get-fixed.js @@ -66,6 +66,6 @@ module.exports = function (length) { clear: function () { map = [[], []]; cache = create(null); - } + }, }; }; diff --git a/normalizers/get-primitive-fixed.js b/normalizers/get-primitive-fixed.js index baedcc8..c12d5be 100644 --- a/normalizers/get-primitive-fixed.js +++ b/normalizers/get-primitive-fixed.js @@ -2,9 +2,7 @@ module.exports = function (length) { if (!length) { - return function () { - return ""; - }; + return function () { return ""; }; } return function (args) { var id = String(args[0]), i = 0, currentLength = length; diff --git a/normalizers/get.js b/normalizers/get.js index c5bb317..8401d0f 100644 --- a/normalizers/get.js +++ b/normalizers/get.js @@ -85,6 +85,6 @@ module.exports = function () { clear: function () { map = []; cache = create(null); - } + }, }; }; diff --git a/normalizers/primitive.js b/normalizers/primitive.js index b1cf0e3..9a520c2 100644 --- a/normalizers/primitive.js +++ b/normalizers/primitive.js @@ -3,7 +3,7 @@ module.exports = function (args) { var id, i, length = args.length; if (!length) return "\u0002"; - id = String(args[i = 0]); + id = String(args[(i = 0)]); while (--length) id += "\u0001" + args[++i]; return id; }; diff --git a/package.json b/package.json index 5b1fc84..dc1ef57 100644 --- a/package.json +++ b/package.json @@ -1,80 +1,80 @@ { - "name": "memoizee", - "version": "0.4.15", - "description": "Memoize/cache function results", - "author": "Mariusz Nowak (http://www.medikoo.com/)", - "keywords": [ - "memoize", - "memoizer", - "cache", - "memoization", - "memo", - "memcached", - "hashing.", - "storage", - "caching", - "memory", - "gc", - "weak", - "garbage", - "collector", - "async" - ], - "repository": "medikoo/memoizee", - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.53", - "es6-weak-map": "^2.0.3", - "event-emitter": "^0.3.5", - "is-promise": "^2.2.2", - "lru-queue": "^0.1.0", - "next-tick": "^1.1.0", - "timers-ext": "^0.1.7" - }, - "devDependencies": { - "bluebird": "^3.7.2", - "eslint": "^8.57.0", - "eslint-config-medikoo": "^4.2.0", - "plain-promise": "^0.1.1", - "prettier-elastic": "^3.2.5", - "tad": "^3.1.1" - }, - "eslintConfig": { - "extends": "medikoo/es5", - "root": true, - "globals": { - "setTimeout": true, - "clearTimeout": true - }, - "rules": { - "max-lines-per-function": "off" - } - }, - "prettier": { - "printWidth": 100, - "tabWidth": 4, - "overrides": [ - { - "files": [ - "*.md", - "*.yml" - ], - "options": { - "tabWidth": 2 - } - } - ] - }, - "scripts": { - "lint": "eslint --ignore-path=.gitignore .", - "prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"", + "name": "memoizee", + "version": "0.4.15", + "description": "Memoize/cache function results", + "author": "Mariusz Nowak (http://www.medikoo.com/)", + "keywords": [ + "memoize", + "memoizer", + "cache", + "memoization", + "memo", + "memcached", + "hashing.", + "storage", + "caching", + "memory", + "gc", + "weak", + "garbage", + "collector", + "async" + ], + "repository": "medikoo/memoizee", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.53", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + }, + "devDependencies": { + "bluebird": "^3.7.2", + "eslint": "^8.57.0", + "eslint-config-medikoo": "^4.2.0", + "plain-promise": "^0.1.1", + "prettier-elastic": "^3.2.5", + "tad": "^3.1.1" + }, + "eslintConfig": { + "extends": "medikoo/es5", + "root": true, + "globals": { + "setTimeout": true, + "clearTimeout": true + }, + "rules": { + "max-lines-per-function": "off" + } + }, + "prettier": { + "printWidth": 100, + "tabWidth": 4, + "overrides": [ + { + "files": [ + "*.md", + "*.yml" + ], + "options": { + "tabWidth": 2 + } + } + ] + }, + "scripts": { + "lint": "eslint --ignore-path=.gitignore .", + "prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"", "prettier-check:updated": "pipe-git-updated --base=main --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c", "prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"", "prettify:updated": "pipe-git-updated ---base=main -ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write", "test": "tad" - }, - "engines": { - "node": ">=.0.12" - }, - "license": "ISC" + }, + "engines": { + "node": ">=.0.12" + }, + "license": "ISC" } diff --git a/plain.js b/plain.js index d73111b..4c770a8 100644 --- a/plain.js +++ b/plain.js @@ -6,7 +6,7 @@ var callable = require("es5-ext/object/valid-callable") , configure = require("./lib/configure-map") , resolveLength = require("./lib/resolve-length"); -module.exports = function self(fn /*, options */) { +module.exports = function self(fn/*, options */) { var options, length, conf; callable(fn); diff --git a/profile.js b/profile.js index a3f85ef..1c2ccb1 100644 --- a/profile.js +++ b/profile.js @@ -9,23 +9,25 @@ var partial = require("es5-ext/function/#/partial") , d = require("d") , memoize = require("./plain"); -var max = Math.max, stats = exports.statistics = {}; +var max = Math.max, stats = (exports.statistics = {}); Object.defineProperty( - memoize, - "__profiler__", + memoize, "__profiler__", d(function (conf) { var id, source, data, stack; stack = new Error().stack; if ( !stack || - !stack.split("\n").slice(3).some(function (line) { - if (line.indexOf("/memoizee/") === -1 && line.indexOf(" (native)") === -1) { - source = line.replace(/\n/g, "\\n").trim(); - return true; - } - return false; - }) + !stack + .split("\n") + .slice(3) + .some(function (line) { + if (line.indexOf("/memoizee/") === -1 && line.indexOf(" (native)") === -1) { + source = line.replace(/\n/g, "\\n").trim(); + return true; + } + return false; + }) ) { source = "unknown"; } diff --git a/tea.yaml b/tea.yaml index 5dd80d1..9c94c6f 100644 --- a/tea.yaml +++ b/tea.yaml @@ -2,5 +2,5 @@ --- version: 1.0.0 codeOwners: - - '0x641A74E8f6b1f59ffadc28b220A316c79a65D87e' + - "0x641A74E8f6b1f59ffadc28b220A316c79a65D87e" quorum: 1 diff --git a/test/ext/async.js b/test/ext/async.js index 17b5022..d16f03e 100644 --- a/test/ext/async.js +++ b/test/ext/async.js @@ -25,40 +25,35 @@ module.exports = function () { ++invoked; a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { ++invoked; a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { ++invoked; a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -70,16 +65,14 @@ module.exports = function () { ++invoked; a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -93,16 +86,14 @@ module.exports = function () { ++invoked; a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -129,36 +120,31 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -168,15 +154,13 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -184,7 +168,7 @@ module.exports = function () { d(); }); }); - } + }, }, "Primitive": { "Success": function (a, d) { @@ -200,39 +184,28 @@ module.exports = function () { mfn = memoize(fn, { async: true, primitive: true }); a( - mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), - u, - "Initial" + mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), + u, "Initial" ); a( - mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), - u, - "Initial #2" + mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( - mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), - u, - "Initial #2" + mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -242,15 +215,13 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -262,15 +233,13 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -296,36 +265,31 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -335,15 +299,13 @@ module.exports = function () { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -354,34 +316,25 @@ module.exports = function () { }, "Primitive null arg case": function (a, d) { var x = {} - , mfn = memoize( - function f(id, cb) { - cb(null, x); - }, - { + , mfn = memoize(function f(id, cb) { cb(null, x); }, { async: true, - primitive: true - } - ); + primitive: true, + }); mfn(null, function (err, res) { a.deep([err, res], [null, x], "Args"); d(); }); - } + }, }, "Sync Clear": function (a, d) { var mfn, fn; fn = function (x, cb) { - nextTick(function () { - cb(null, x); - }); + nextTick(function () { cb(null, x); }); }; mfn = memoize(fn, { async: true }); - mfn(1, function (err, i) { - a(i, 1, "First"); - }); + mfn(1, function (err, i) { a(i, 1, "First"); }); mfn.clear(); mfn(2, function (err, i) { a(i, 2, "Second"); @@ -391,23 +344,17 @@ module.exports = function () { "Sync Clear: Primitive": function (a, d) { var mfn, fn; fn = function (x, cb) { - nextTick(function () { - cb(null, x); - }); + nextTick(function () { cb(null, x); }); }; mfn = memoize(fn, { async: true, primitive: true }); - mfn(2, function (err, i) { - a(i, 2, "First"); - }); + mfn(2, function (err, i) { a(i, 2, "First"); }); mfn(1, function (err, i) { a(i, 1, "Second"); nextTick(d); }); mfn.clear(); - mfn(2, function (err, i) { - a(i, 2, "Third"); - }); - } + mfn(2, function (err, i) { a(i, 2, "Third"); }); + }, }; }; diff --git a/test/ext/dispose.js b/test/ext/dispose.js index d92cd02..064b92e 100644 --- a/test/ext/dispose.js +++ b/test/ext/dispose.js @@ -32,7 +32,7 @@ module.exports = function () { x = {}; invoked = false; mfn = memoize(function () { return x; }, { - dispose: function (val) { invoked = val; } + dispose: function (val) { invoked = val; }, }); mfn.delete(); @@ -47,7 +47,7 @@ module.exports = function () { fn = function (x, y) { return x + y; }; mfn = memoize(fn, { refCounter: true, - dispose: function (val) { value.push(val); } + dispose: function (val) { value.push(val); }, }); mfn(3, 7); @@ -128,7 +128,7 @@ module.exports = function () { ); }); }); - } + }, }, Primitive: { "Sync": function (a) { @@ -156,7 +156,7 @@ module.exports = function () { fn = function (x, y) { return x + y; }; mfn = memoize(fn, { refCounter: true, - dispose: function (val) { value.push(val); } + dispose: function (val) { value.push(val); }, }); mfn(3, 7); @@ -237,7 +237,7 @@ module.exports = function () { ); }); }); - } - } + }, + }, }; }; diff --git a/test/ext/max-age.js b/test/ext/max-age.js index a26b807..9ca3de1 100644 --- a/test/ext/max-age.js +++ b/test/ext/max-age.js @@ -169,7 +169,7 @@ module.exports = function () { }); }, 100); }, 20); - } + }, }, Primitive: { Sync: function (a, d) { @@ -324,7 +324,7 @@ module.exports = function () { }); }, 500); }, 100); - } + }, }, Refetch: { Default: function (a, d) { @@ -450,116 +450,122 @@ module.exports = function () { i, 4, "Called: After Refetch: Before" ); - mfn(3, 7, function ( - err, - result - ) { - a( - result, 10, - "Result: After Refetch" - ); - a( - i, 4, - "Called: After Refetch: After" - ); - mfn(5, 8, function ( - err, - result - ) { + mfn( + 3, + 7, + function (err, result) { a( - result, 13, - "Result: After Refetch B" + result, 10, + "Result: After Refetch" ); a( i, 4, - "Called: After Refetch B: After" + "Called: After Refetch: After" ); - // Wait 250ms - setTimeout( - function () { - // From cache, prefetch triggered - mfn( - 3, - 7, - function ( - err, - result - ) { - a( - result, - 10, - "Result: After Refetch #2" - ); - a( - i, - 4, - "Called: After Refetch #2" - ); + mfn( + 5, + 8, + function ( + err, + result + ) { + a( + result, + 13, + "Result: After Refetch B" + ); + a( + i, 4, + "Called: After Refetch B: After" + ); + // Wait 250ms + setTimeout( + function () { + // From cache, prefetch triggered mfn( - 5, - 8, + 3, + 7, function ( err, result ) { a( result, - 13, - "Result: After Refetch #2 B" + 10, + "Result: After Refetch #2" ); a( i, - 5, - "Called: After Refetch #2 B" + 4, + "Called: After Refetch #2" ); mfn( - 3, - 7, + 5, + 8, function ( err, result ) { a( result, - 10, - "Result: After Refetch #3" + 13, + "Result: After Refetch #2 B" ); a( i, - 6, - "Called: After Refetch #3" + 5, + "Called: After Refetch #2 B" ); mfn( - 5, - 8, + 3, + 7, function ( err, result ) { a( result, - 13, - "Result: After Refetch #3 B" + 10, + "Result: After Refetch #3" ); a( i, 6, - "Called: After Refetch #3 B" + "Called: After Refetch #3" + ); + mfn( + 5, + 8, + function ( + err, + result + ) { + a( + result, + 13, + "Result: After Refetch #3 B" + ); + a( + i, + 6, + "Called: After Refetch #3 B" + ); + d(); + } ); - d(); } ); } ); } ); - } + }, + 250 ); - }, - 250 + } ); - }); - }); + } + ); }, 200); }); }); @@ -856,7 +862,7 @@ module.exports = function () { }, 3000); }, 1000); }, 4500); - } - } + }, + }, }; }; diff --git a/test/ext/max.js b/test/ext/max.js index c9d9cd1..33cbea7 100644 --- a/test/ext/max.js +++ b/test/ext/max.js @@ -11,9 +11,7 @@ module.exports = function () { return { Regular: { Sync: function (a) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -68,10 +66,7 @@ module.exports = function () { a(i, 11, "Called D #5"); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -105,17 +100,14 @@ module.exports = function () { a( mfn(5, 8, function (err, res) { a.deep( - [err, res], - [null, 13], - "Result B #2" + [err, res], [null, 13], "Result B #2" ); a(i, 2, "Called B #2"); a( mfn(12, 4, function (err, res) { a.deep( - [err, res], - [null, 16], + [err, res], [null, 16], "Result C #1" ); a(i, 3, "Called C #1"); @@ -123,406 +115,396 @@ module.exports = function () { a( mfn(3, 7, function (err, res) { a.deep( - [err, res], - [null, 10], + [err, res], [null, 10], "Result #4" ); a(i, 3, "Called #4"); a( - mfn(5, 8, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 13], - "Result B #3" - ); - a( - i, - 3, - "Called B #3" - ); + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, 3, + "Called B #3" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); - - a( - mfn( - 5, - 8, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + res, + ], + [ + null, + 88, + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a( - mfn( - 12, - 4, - function ( + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 16 - ], - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + res, + ], + [ + null, + 13, + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a( - mfn( - 3, - 7, - function ( + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 10 - ], - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + res, + ], + [ + null, + 16, + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + res, + ], + [ + null, + 10, + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a( - mfn( - 12, - 4, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 16 - ], - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + res, + ], + [ + null, + 88, + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a( - mfn( - 5, - 8, - function ( + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + res, + ], + [ + null, + 16, + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + res, + ], + [ + null, + 13, + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn.delete( - 77, - 11 - ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + res, + ], + [ + null, + 88, + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.clear(); - a( - mfn( - 5, - 8, - function ( + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + res, + ], + [ + null, + 88, + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - a( - mfn( - 77, - 11, - function ( + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + res, + ], + [ + null, + 13, + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - d(); - } - ), - u, - "Initial D #5" - ); - } - ), - u, - "Initial B #6" - ); - } - ), - u, - "Initial D #4" - ); - } - ), - u, - "Initial D #3" - ); - } - ), - u, - "Initial B #5" - ); - } - ), - u, - "Initial C #3" - ); - } - ), - u, - "Initial D #2" - ); - } - ), - u, - "Initial #5" - ); - } - ), - u, - "Initial C #2" - ); - } - ), - u, - "Initial B #4" - ); - } - ), - u, - "Initial D #1" - ); - }), - u, - "Initial B #3" + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); + + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + } + ), + u, "Initial B #3" ); }), - u, - "Initial #4" + u, "Initial #4" ); }), - u, - "Initial C #1" + u, "Initial C #1" ); }), - u, - "Initial B #2" + u, "Initial B #2" ); }), - u, - "Initial #3" + u, "Initial #3" ); }), - u, - "Initial B #1" + u, "Initial B #1" ); }), - u, - "Initial #2" + u, "Initial #2" ); }), - u, - "Initial #1" + u, "Initial #1" ); }, Promise: function (a, d) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; - return new Promise(function (res) { - res(x + y); - }); + return new Promise(function (res) { res(x + y); }); }; mfn = memoize(fn, { promise: true, max: 3 }); @@ -572,261 +554,260 @@ module.exports = function () { delay(function (res) { // [12, 4], [3, 7], [5, 8] a( - res, - 13, + res, 13, "Result B #3" ); a( - i, - 3, + i, 3, "Called B #3" ); mfn(77, 11).done( - delay(function ( - res - ) { - // [3, 7], [5, 8], [77, 11] - a( - res, - 88, - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); + delay( + function ( + res + ) { + // [3, 7], [5, 8], [77, 11] + a( + res, + 88, + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - // [3, 7], [77, 11], [5, 8] - a( - res, - 13, - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + mfn( + 5, 8 + ).done( + delay( + function ( + res + ) { + // [3, 7], [77, 11], [5, 8] + a( + res, + 13, + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - mfn( - 12, - 4 - ).done( - delay( - function ( - res - ) { - // [77, 11], [5, 8], [12, 4] - a( - res, - 16, - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + // [77, 11], [5, 8], [12, 4] + a( + res, + 16, + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - mfn( - 3, - 7 - ).done( - delay( - function ( - res - ) { - a( - res, - 10, - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + mfn( + 3, + 7 + ).done( + delay( + function ( + res + ) { + a( + res, + 10, + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - mfn( - 12, - 4 - ).done( - delay( - function ( - res - ) { - a( - res, - 16, - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - a( - res, - 13, - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete( - 77, - 11 - ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + mfn.delete( + 77, + 11 + ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - a( - res, - 13, - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + mfn.clear(); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - }) + d(); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) ); }) ); @@ -844,13 +825,11 @@ module.exports = function () { ); }) ); - } + }, }, Primitive: { Sync: function (a) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -905,10 +884,7 @@ module.exports = function () { a(i, 11, "Called D #5"); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -942,17 +918,14 @@ module.exports = function () { a( mfn(5, 8, function (err, res) { a.deep( - [err, res], - [null, 13], - "Result B #2" + [err, res], [null, 13], "Result B #2" ); a(i, 2, "Called B #2"); a( mfn(12, 4, function (err, res) { a.deep( - [err, res], - [null, 16], + [err, res], [null, 16], "Result C #1" ); a(i, 3, "Called C #1"); @@ -960,406 +933,396 @@ module.exports = function () { a( mfn(3, 7, function (err, res) { a.deep( - [err, res], - [null, 10], + [err, res], [null, 10], "Result #4" ); a(i, 3, "Called #4"); a( - mfn(5, 8, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 13], - "Result B #3" - ); - a( - i, - 3, - "Called B #3" - ); + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, 3, + "Called B #3" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); - - a( - mfn( - 5, - 8, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + res, + ], + [ + null, + 88, + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a( - mfn( - 12, - 4, - function ( + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 16 - ], - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + res, + ], + [ + null, + 13, + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a( - mfn( - 3, - 7, - function ( + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 10 - ], - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + res, + ], + [ + null, + 16, + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + res, + ], + [ + null, + 10, + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a( - mfn( - 12, - 4, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 16 - ], - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + res, + ], + [ + null, + 88, + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a( - mfn( - 5, - 8, - function ( + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + res, + ], + [ + null, + 16, + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + res, + ], + [ + null, + 13, + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn.delete( - 77, - 11 - ); - a( - mfn( - 77, - 11, - function ( + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + res, + ], + [ + null, + 88, + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.clear(); - a( - mfn( - 5, - 8, - function ( + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 13 - ], - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + res, + ], + [ + null, + 88, + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - a( - mfn( - 77, - 11, - function ( + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ err, - res - ) { - a.deep( - [ - err, - res - ], - [ - null, - 88 - ], - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + res, + ], + [ + null, + 13, + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - d(); - } - ), - u, - "Initial D #5" - ); - } - ), - u, - "Initial B #6" - ); - } - ), - u, - "Initial D #4" - ); - } - ), - u, - "Initial D #3" - ); - } - ), - u, - "Initial B #5" - ); - } - ), - u, - "Initial C #3" - ); - } - ), - u, - "Initial D #2" - ); - } - ), - u, - "Initial #5" - ); - } - ), - u, - "Initial C #2" - ); - } - ), - u, - "Initial B #4" - ); - } - ), - u, - "Initial D #1" - ); - }), - u, - "Initial B #3" + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); + + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + } + ), + u, "Initial B #3" ); }), - u, - "Initial #4" + u, "Initial #4" ); }), - u, - "Initial C #1" + u, "Initial C #1" ); }), - u, - "Initial B #2" + u, "Initial B #2" ); }), - u, - "Initial #3" + u, "Initial #3" ); }), - u, - "Initial B #1" + u, "Initial B #1" ); }), - u, - "Initial #2" + u, "Initial #2" ); }), - u, - "Initial #1" + u, "Initial #1" ); }, Promise: function (a, d) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; - return new Promise(function (res) { - res(x + y); - }); + return new Promise(function (res) { res(x + y); }); }; mfn = memoize(fn, { promise: true, primitive: true, max: 3 }); @@ -1402,258 +1365,257 @@ module.exports = function () { mfn(5, 8).done( delay(function (res) { a( - res, - 13, + res, 13, "Result B #3" ); a( - i, - 3, + i, 3, "Called B #3" ); mfn(77, 11).done( - delay(function ( - res - ) { - a( - res, - 88, - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - a( - res, - 13, - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + mfn( + 5, 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - mfn( - 12, - 4 - ).done( - delay( - function ( - res - ) { - a( - res, - 16, - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - mfn( - 3, - 7 - ).done( - delay( - function ( - res - ) { - a( - res, - 10, - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + mfn( + 3, + 7 + ).done( + delay( + function ( + res + ) { + a( + res, + 10, + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - mfn( - 12, - 4 - ).done( - delay( - function ( - res - ) { - a( - res, - 16, - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - a( - res, - 13, - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete( - 77, - 11 - ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + mfn.delete( + 77, + 11 + ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - mfn( - 5, - 8 - ).done( - delay( - function ( - res - ) { - a( - res, - 13, - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + mfn.clear(); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - mfn( - 77, - 11 - ).done( - delay( - function ( - res - ) { - a( - res, - 88, - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - } - ) - ); - }) + d(); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) ); }) ); @@ -1671,7 +1633,7 @@ module.exports = function () { ); }) ); - } - } + }, + }, }; }; diff --git a/test/ext/promise.js b/test/ext/promise.js index c3d6a3a..16ad189 100644 --- a/test/ext/promise.js +++ b/test/ext/promise.js @@ -8,9 +8,7 @@ var memoize = require("../..") , Promise = require("plain-promise") , Bluebird = require("bluebird"); -Bluebird.config({ - cancellation: true -}); +Bluebird.config({ cancellation: true }); module.exports = function () { return { @@ -114,7 +112,7 @@ module.exports = function () { d(); }, 10); }, 10); - } + }, }, "Cancellation": { Immediate: function (a, d) { @@ -122,9 +120,7 @@ module.exports = function () { fn = function (x, y) { ++i; var p = new Bluebird(function (res) { - setTimeout(function () { - res(x + y); - }, 100); + setTimeout(function () { res(x + y); }, 100); }); p.cancel(); return p; @@ -133,30 +129,27 @@ module.exports = function () { mfn = memoize(fn, { promise: true }); mfn(3, 7).done(a.never, function (err) { - a.throws(function () { - throw err; - }, Bluebird.CancellationError, "Result #1"); + a.throws(function () { throw err; }, Bluebird.CancellationError, "Result #1"); }); mfn(5, 8).done(a.never, function (err) { - a.throws(function () { - throw err; - }, Bluebird.CancellationError, "Result B #2"); + a.throws(function () { throw err; }, Bluebird.CancellationError, "Result B #2"); }); setTimeout(function () { a(i, 2, "Called #2"); mfn(3, 7).done(a.never, function (err) { - a.throws(function () { - throw err; - }, Bluebird.CancellationError, "Again: Result"); + a.throws( + function () { throw err; }, Bluebird.CancellationError, "Again: Result" + ); }); mfn(5, 8).done(a.never, function (err) { - a.throws(function () { - throw err; - }, Bluebird.CancellationError, "Again B: Result"); + a.throws( + function () { throw err; }, Bluebird.CancellationError, + "Again B: Result" + ); }); setTimeout(function (err) { @@ -170,13 +163,9 @@ module.exports = function () { fn = function (x, y) { ++i; var p = new Bluebird(function (res) { - setTimeout(function () { - res(x + y); - }, 100); + setTimeout(function () { res(x + y); }, 100); }); - nextTick(function () { - p.cancel(); - }, 1); + nextTick(function () { p.cancel(); }, 1); return p; }; @@ -198,7 +187,7 @@ module.exports = function () { d(); }, 500); }, 500); - } + }, }, "Primitive": { "Success": function (a, d) { @@ -286,7 +275,7 @@ module.exports = function () { a.deep(res, x, "Args"); d(); }, a.never); - } + }, }, "Sync Clear": function (a, d) { var mfn, fn; @@ -321,6 +310,6 @@ module.exports = function () { a(res, 2, "Second"); d(); }, a.never); - } + }, }; }; diff --git a/test/ext/ref-counter.js b/test/ext/ref-counter.js index d5fb19a..1f5a618 100644 --- a/test/ext/ref-counter.js +++ b/test/ext/ref-counter.js @@ -297,6 +297,6 @@ module.exports = function () { }, 10); }, 10); }, 10); - } + }, }; }; diff --git a/test/index.js b/test/index.js index aa1bee9..ab644cf 100644 --- a/test/index.js +++ b/test/index.js @@ -10,8 +10,8 @@ var join = Array.prototype.join; module.exports = function (t, a) { return { "0": function () { - var i = 0, - fn = function () { + var i = 0 + , fn = function () { ++i; return 3; }; @@ -23,8 +23,8 @@ module.exports = function (t, a) { a(i, 1, "Called once"); }, "1": function () { - var i = 0, - fn = function (x) { + var i = 0 + , fn = function (x) { ++i; return x; }; @@ -53,22 +53,22 @@ module.exports = function (t, a) { a(fn(x, 9), x, "Second"); a(fn(x, 3), x, "Third"); a(i, 1, "Called once"); - } + }, }; }, "3": function () { - var i = 0, - fn = function (x, y, z) { + var i = 0 + , fn = function (x, y, z) { ++i; return [x, y, z]; - }, - r; + } + , r; fn = t(fn); return { "No args": function () { i = 0; - a.deep(r = fn(), [undefined, undefined, undefined], "First"); + a.deep((r = fn()), [undefined, undefined, undefined], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -76,39 +76,39 @@ module.exports = function (t, a) { "Some Args": function () { var x = {}; i = 0; - a.deep(r = fn(x, 8), [x, 8, undefined], "First"); + a.deep((r = fn(x, 8)), [x, 8, undefined], "First"); a(fn(x, 8), r, "Second"); a(fn(x, 8), r, "Third"); a(i, 1, "Called once"); return { Other: function () { - a.deep(r = fn(x, 5), [x, 5, undefined], "Second"); + a.deep((r = fn(x, 5)), [x, 5, undefined], "Second"); a(fn(x, 5), r, "Third"); a(i, 2, "Called once"); - } + }, }; }, "Full stuff": function () { var x = {}; i = 0; - a.deep(r = fn(x, 8, 23, 98), [x, 8, 23], "First"); + a.deep((r = fn(x, 8, 23, 98)), [x, 8, 23], "First"); a(fn(x, 8, 23, 43), r, "Second"); a(fn(x, 8, 23, 9), r, "Third"); a(i, 1, "Called once"); return { Other: function () { - a.deep(r = fn(x, 23, 8, 13), [x, 23, 8], "Second"); + a.deep((r = fn(x, 23, 8, 13)), [x, 23, 8], "Second"); a(fn(x, 23, 8, 22), r, "Third"); a(i, 2, "Called once"); - } + }, }; - } + }, }; }, "Error": function () { - var i = 0, - e = new Error("Test"), - fn = function () { + var i = 0 + , e = new Error("Test") + , fn = function () { ++i; if (i < 3) throw e; return 3; @@ -116,13 +116,9 @@ module.exports = function (t, a) { fn = t(fn); - a.throws(function () { - fn(); - }, "Test"); + a.throws(function () { fn(); }, "Test"); a(i, 1, "Called once"); - a.throws(function () { - fn(); - }, "Test"); + a.throws(function () { fn(); }, "Test"); a(i, 2, "Called twice"); a(fn(), 3, "First"); a(fn(), 3, "Second"); @@ -130,17 +126,13 @@ module.exports = function (t, a) { a(i, 3, "Called three times"); }, "Normalizer function": function () { - var i = 0, - fn = function () { + var i = 0 + , fn = function () { ++i; return join.call(arguments, "|"); - }, - mfn; - mfn = t(fn, { - normalizer: function (args) { - return Boolean(args[0]); } - }); + , mfn; + mfn = t(fn, { normalizer: function (args) { return Boolean(args[0]); } }); a(mfn(false, "raz"), "false|raz", "#1"); a(mfn(0, "dwa"), "false|raz", "#2"); a(i, 1, "Called once"); @@ -150,18 +142,18 @@ module.exports = function (t, a) { a(i, 2, "Called twice #2"); }, "Dynamic": function () { - var i = 0, - fn = function () { + var i = 0 + , fn = function () { ++i; return arguments; - }, - r; + } + , r; fn = t(fn, { length: false }); return { "No args": function () { i = 0; - a.deep(aFrom(r = fn()), [], "First"); + a.deep(aFrom((r = fn())), [], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -169,7 +161,7 @@ module.exports = function (t, a) { "Some Args": function () { var x = {}; i = 0; - a.deep(aFrom(r = fn(x, 8)), [x, 8], "First"); + a.deep(aFrom((r = fn(x, 8))), [x, 8], "First"); a(fn(x, 8), r, "Second"); a(fn(x, 8), r, "Third"); a(i, 1, "Called once"); @@ -177,17 +169,15 @@ module.exports = function (t, a) { "Many args": function () { var x = {}; i = 0; - a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First"); + a.deep(aFrom((r = fn(x, 8, 23, 98))), [x, 8, 23, 98], "First"); a(fn(x, 8, 23, 98), r, "Second"); a(fn(x, 8, 23, 98), r, "Third"); a(i, 1, "Called once"); - } + }, }; }, "Resolvers": function () { - var i = 0, - fn, - r; + var i = 0, fn, r; fn = t( function () { ++i; @@ -198,7 +188,7 @@ module.exports = function (t, a) { return { "No args": function () { i = 0; - a.deep(aFrom(r = fn()), [false, "undefined"], "First"); + a.deep(aFrom((r = fn())), [false, "undefined"], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -206,26 +196,23 @@ module.exports = function (t, a) { "Some Args": function () { var x = {}; i = 0; - a.deep(aFrom(r = fn(0, 34, x, 45)), [false, "34", x, 45], "First"); + a.deep(aFrom((r = fn(0, 34, x, 45))), [false, "34", x, 45], "First"); a(fn(0, 34, x, 22), r, "Second"); a(fn(0, 34, x, false), r, "Third"); a(i, 1, "Called once"); return { Other: function () { - a.deep(aFrom(r = fn(1, 34, x, 34)), [true, "34", x, 34], "Second"); + a.deep(aFrom((r = fn(1, 34, x, 34))), [true, "34", x, 34], "Second"); a(fn(1, 34, x, 89), r, "Third"); a(i, 2, "Called once"); - } + }, }; - } + }, }; }, "Clear Cache": { Specific: function () { - var i = 0, - fn, - mfn, - x = {}; + var i = 0, fn, mfn, x = {}; fn = function (a, b, c) { if (c === 3) { @@ -256,9 +243,7 @@ module.exports = function (t, a) { a(i, 1, "Proper no arguments clear"); }, All: function () { - var i = 0, - fn, - x = {}; + var i = 0, fn, x = {}; fn = function () { ++i; @@ -277,92 +262,72 @@ module.exports = function (t, a) { fn(1, x, 3); fn(1, x, 4); a(i, 4, "After clear"); - } + }, }, "Primitive": { "No args": function (a) { - var i = 0, - fn = function () { + var i = 0 + , fn = function () { ++i; return arguments[0]; - }, - mfn; + } + , mfn; mfn = t(fn, { primitive: true }); a(mfn("ble"), "ble", "#1"); a(mfn({}), "ble", "#2"); a(i, 1, "Called once"); }, "One arg": function (a) { - var i = 0, - fn = function (x) { + var i = 0 + , fn = function (x) { ++i; return x; - }, - mfn, - y = { - toString: function () { - return "foo"; - } - }; + } + , mfn + , y = { toString: function () { return "foo"; } }; mfn = t(fn, { primitive: true }); a(mfn(y), y, "#1"); a(mfn("foo"), y, "#2"); a(i, 1, "Called once"); }, "Many args": function (a) { - var i = 0, - fn = function (x, y, z) { + var i = 0 + , fn = function (x, y, z) { ++i; return x + y + z; - }, - mfn, - y = { - toString: function () { - return "foo"; - } - }; + } + , mfn + , y = { toString: function () { return "foo"; } }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); }, "Clear cache": function (a) { - var i = 0, - fn = function (x, y, z) { + var i = 0 + , fn = function (x, y, z) { ++i; return x + y + z; - }, - mfn, - y = { - toString: function () { - return "foo"; - } - }; + } + , mfn + , y = { toString: function () { return "foo"; } }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete( - "foo", - { - toString: function () { - return "bar"; - } - }, - "zeta" - ); + mfn.delete("foo", { toString: function () { return "bar"; } }, "zeta"); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); - } + }, }, "Reference counter": { Regular: function (a) { - var i = 0, - fn = function (x, y, z) { + var i = 0 + , fn = function (x, y, z) { ++i; return x + y + z; - }, - mfn; + } + , mfn; mfn = t(fn, { refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Clear before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -382,12 +347,12 @@ module.exports = function (t, a) { a(i, 2, "Cached again"); }, Primitive: function (a) { - var i = 0, - fn = function (x, y, z) { + var i = 0 + , fn = function (x, y, z) { ++i; return x + y + z; - }, - mfn; + } + , mfn; mfn = t(fn, { primitive: true, refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Clear before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -405,16 +370,12 @@ module.exports = function (t, a) { a(i, 2, "Restarted"); mfn(3, 5, 7); a(i, 2, "Cached again"); - } + }, }, "Async": { Regular: { "Success": function (a, d) { - var mfn, - fn, - u = {}, - i = 0, - invoked = 0; + var mfn, fn, u = {}, i = 0, invoked = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -430,40 +391,35 @@ module.exports = function (t, a) { ++invoked; a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { ++invoked; a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { ++invoked; a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -475,16 +431,14 @@ module.exports = function (t, a) { ++invoked; a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -498,16 +452,14 @@ module.exports = function (t, a) { ++invoked; a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { ++invoked; a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -519,10 +471,7 @@ module.exports = function (t, a) { }); }, "Reference counter": function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -539,36 +488,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -578,15 +522,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -601,15 +543,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -620,11 +560,7 @@ module.exports = function (t, a) { }); }, "Error": function (a, d) { - var mfn, - fn, - u = {}, - i = 0, - e = new Error("Test"); + var mfn, fn, u = {}, i = 0, e = new Error("Test"); fn = function (x, y, cb) { nextTick(function () { ++i; @@ -639,36 +575,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -678,15 +609,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -694,14 +623,11 @@ module.exports = function (t, a) { d(); }); }); - } + }, }, Primitive: { "Success": function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -716,36 +642,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -755,15 +676,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -775,15 +694,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -794,10 +711,7 @@ module.exports = function (t, a) { }); }, "Reference counter": function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -814,36 +728,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -853,15 +762,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -876,15 +783,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -895,11 +800,7 @@ module.exports = function (t, a) { }); }, "Error": function (a, d) { - var mfn, - fn, - u = {}, - i = 0, - e = new Error("Test"); + var mfn, fn, u = {}, i = 0, e = new Error("Test"); fn = function (x, y, cb) { nextTick(function () { ++i; @@ -914,36 +815,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); nextTick(function () { @@ -953,15 +849,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [e, undefined], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -969,15 +863,13 @@ module.exports = function (t, a) { d(); }); }); - } - } + }, + }, }, "MaxAge": { Regular: { Sync: function (a, d) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -1016,10 +908,7 @@ module.exports = function (t, a) { }, 20); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -1034,36 +923,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); setTimeout(function () { @@ -1073,15 +957,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); setTimeout(function () { @@ -1091,15 +973,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -1108,13 +988,11 @@ module.exports = function (t, a) { }); }, 100); }, 20); - } + }, }, Primitive: { Sync: function (a, d) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -1153,10 +1031,7 @@ module.exports = function (t, a) { }, 20); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -1171,36 +1046,31 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #1"); }), - u, - "Initial" + u, "Initial" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #2"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #1"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Result #3"); }), - u, - "Initial #2" + u, "Initial #2" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Result B #2"); }), - u, - "Initial #3" + u, "Initial #3" ); setTimeout(function () { @@ -1210,15 +1080,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); setTimeout(function () { @@ -1228,15 +1096,13 @@ module.exports = function (t, a) { mfn(3, 7, function (err, res) { a.deep([err, res], [null, 10], "Again: Result"); }), - u, - "Again: Initial" + u, "Again: Initial" ); a( mfn(5, 8, function (err, res) { a.deep([err, res], [null, 13], "Again B: Result"); }), - u, - "Again B: Initial" + u, "Again B: Initial" ); nextTick(function () { @@ -1245,15 +1111,13 @@ module.exports = function (t, a) { }); }, 100); }, 20); - } - } + }, + }, }, "Max": { Regular: { Sync: function (a) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -1308,10 +1172,7 @@ module.exports = function (t, a) { a(i, 11, "Called D #5"); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -1345,8 +1206,7 @@ module.exports = function (t, a) { a( mfn(5, 8, function (err, res) { a.deep( - [err, res], - [null, 13], + [err, res], [null, 13], "Result B #2" ); a(i, 2, "Called B #2"); @@ -1354,415 +1214,419 @@ module.exports = function (t, a) { a( mfn(12, 4, function (err, res) { a.deep( - [err, res], - [null, 16], + [err, res], [null, 16], "Result C #1" ); a(i, 3, "Called C #1"); a( - mfn(3, 7, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 10], - "Result #4" - ); - a(i, 3, "Called #4"); + mfn( + 3, + 7, + function (err, res) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a( + i, 3, + "Called #4" + ); - a( - mfn(5, 8, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 13], - "Result B #3" - ); - a( - i, - 3, - "Called B #3" - ); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a( - mfn( - 12, - 4, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 12, + 4, + function ( err, res - ], - [ - null, - 16 - ], - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 16, + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a( - mfn( - 3, - 7, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 3, + 7, + function ( err, res - ], - [ - null, - 10 - ], - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 10, + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a( - mfn( - 12, - 4, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 12, + 4, + function ( err, res - ], - [ - null, - 16 - ], - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 16, + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete( - 77, - 11 - ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + mfn.clear(); + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - } - ), - u, - "Initial D #5" - ); - } - ), - u, - "Initial B #6" - ); - } - ), - u, - "Initial D #4" - ); - } - ), - u, - "Initial D #3" - ); - } - ), - u, - "Initial B #5" - ); - } - ), - u, - "Initial C #3" - ); - } - ), - u, - "Initial D #2" - ); - } - ), - u, - "Initial #5" - ); - } - ), - u, - "Initial C #2" - ); - } - ), - u, - "Initial B #4" - ); - } - ), - u, - "Initial D #1" - ); - }), - u, - "Initial B #3" - ); - }), - u, - "Initial #4" + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + } + ), + u, + "Initial B #3" + ); + } + ), + u, "Initial #4" ); }), - u, - "Initial C #1" + u, "Initial C #1" ); }), - u, - "Initial B #2" + u, "Initial B #2" ); }), - u, - "Initial #3" + u, "Initial #3" ); }), - u, - "Initial B #1" + u, "Initial B #1" ); }), - u, - "Initial #2" + u, "Initial #2" ); }), - u, - "Initial #1" + u, "Initial #1" ); - } + }, }, Primitive: { Sync: function (a) { - var mfn, - fn, - i = 0; + var mfn, fn, i = 0; fn = function (x, y) { ++i; return x + y; @@ -1817,10 +1681,7 @@ module.exports = function (t, a) { a(i, 11, "Called D #5"); }, Async: function (a, d) { - var mfn, - fn, - u = {}, - i = 0; + var mfn, fn, u = {}, i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -1854,8 +1715,7 @@ module.exports = function (t, a) { a( mfn(5, 8, function (err, res) { a.deep( - [err, res], - [null, 13], + [err, res], [null, 13], "Result B #2" ); a(i, 2, "Called B #2"); @@ -1863,427 +1723,423 @@ module.exports = function (t, a) { a( mfn(12, 4, function (err, res) { a.deep( - [err, res], - [null, 16], + [err, res], [null, 16], "Result C #1" ); a(i, 3, "Called C #1"); a( - mfn(3, 7, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 10], - "Result #4" - ); - a(i, 3, "Called #4"); + mfn( + 3, + 7, + function (err, res) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a( + i, 3, + "Called #4" + ); - a( - mfn(5, 8, function ( - err, - res - ) { - a.deep( - [err, res], - [null, 13], - "Result B #3" - ); - a( - i, - 3, - "Called B #3" - ); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #1" - ); - a( - i, - 4, - "Called D #1" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #4" - ); - a( - i, - 4, - "Called B #4" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a( - mfn( - 12, - 4, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 12, + 4, + function ( err, res - ], - [ - null, - 16 - ], - "Result C #2" - ); - a( - i, - 5, - "Called C #2" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 16, + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a( - mfn( - 3, - 7, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 3, + 7, + function ( err, res - ], - [ - null, - 10 - ], - "Result #5" - ); - a( - i, - 6, - "Called #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 10, + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #2" - ); - a( - i, - 7, - "Called D #2" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a( - mfn( - 12, - 4, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 12, + 4, + function ( err, res - ], - [ - null, - 16 - ], - "Result C #3" - ); - a( - i, - 7, - "Called C #3" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 16, + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #5" - ); - a( - i, - 8, - "Called B #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #3" - ); - a( - i, - 8, - "Called D #3" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete( - 77, - 11 - ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #4" - ); - a( - i, - 9, - "Called D #4" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a( - mfn( - 5, - 8, - function ( - err, - res - ) { - a.deep( - [ + mfn.clear(); + a( + mfn( + 5, + 8, + function ( err, res - ], - [ - null, - 13 - ], - "Result B #6" - ); - a( - i, - 10, - "Called B #6" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 13, + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a( - mfn( - 77, - 11, - function ( - err, - res - ) { - a.deep( - [ + a( + mfn( + 77, + 11, + function ( err, res - ], - [ - null, - 88 - ], - "Result D #5" - ); - a( - i, - 11, - "Called D #5" - ); + ) { + a.deep( + [ + err, + res, + ], + [ + null, + 88, + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - } - ), - u, - "Initial D #5" - ); - } - ), - u, - "Initial B #6" - ); - } - ), - u, - "Initial D #4" - ); - } - ), - u, - "Initial D #3" - ); - } - ), - u, - "Initial B #5" - ); - } - ), - u, - "Initial C #3" - ); - } - ), - u, - "Initial D #2" - ); - } - ), - u, - "Initial #5" - ); - } - ), - u, - "Initial C #2" - ); - } - ), - u, - "Initial B #4" - ); - } - ), - u, - "Initial D #1" - ); - }), - u, - "Initial B #3" - ); - }), - u, - "Initial #4" + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + } + ), + u, + "Initial B #3" + ); + } + ), + u, "Initial #4" ); }), - u, - "Initial C #1" + u, "Initial C #1" ); }), - u, - "Initial B #2" + u, "Initial B #2" ); }), - u, - "Initial #3" + u, "Initial #3" ); }), - u, - "Initial B #1" + u, "Initial B #1" ); }), - u, - "Initial #2" + u, "Initial #2" ); }), - u, - "Initial #1" + u, "Initial #1" ); - } - } + }, + }, }, "Dispose": { Regular: { "Sync": function (a) { - var mfn, - fn, - value = [], - x, - invoked; - fn = function (x, y) { - return x + y; - }; - mfn = t(fn, { - dispose: function (val) { - value.push(val); - } - }); + var mfn, fn, value = [], x, invoked; + fn = function (x, y) { return x + y; }; + mfn = t(fn, { dispose: function (val) { value.push(val); } }); mfn(3, 7); mfn(5, 8); @@ -2302,16 +2158,9 @@ module.exports = function (t, a) { x = {}; invoked = false; - mfn = t( - function () { - return x; - }, - { - dispose: function (val) { - invoked = val; - } - } - ); + mfn = t(function () { return x; }, { + dispose: function (val) { invoked = val; }, + }); mfn.delete(); a(invoked, false, "No args: Post invalid clear"); @@ -2321,18 +2170,9 @@ module.exports = function (t, a) { a(invoked, x, "No args: Pre clear"); }, "Ref counter": function (a) { - var mfn, - fn, - value = []; - fn = function (x, y) { - return x + y; - }; - mfn = t(fn, { - refCounter: true, - dispose: function (val) { - value.push(val); - } - }); + var mfn, fn, value = []; + fn = function (x, y) { return x + y; }; + mfn = t(fn, { refCounter: true, dispose: function (val) { value.push(val); } }); mfn(3, 7); mfn(5, 8); @@ -2353,23 +2193,13 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Async": function (a, d) { - var mfn, - fn, - u = {}, - value = []; + var mfn, fn, u = {}, value = []; fn = function (x, y, cb) { - nextTick(function () { - cb(null, x + y); - }); + nextTick(function () { cb(null, x + y); }); return u; }; - mfn = t(fn, { - async: true, - dispose: function (val) { - value.push(val); - } - }); + mfn = t(fn, { async: true, dispose: function (val) { value.push(val); } }); mfn(3, 7, function () { mfn(5, 8, function () { @@ -2390,21 +2220,13 @@ module.exports = function (t, a) { }); }); }); - } + }, }, Primitive: { "Sync": function (a) { - var mfn, - fn, - value = []; - fn = function (x, y) { - return x + y; - }; - mfn = t(fn, { - dispose: function (val) { - value.push(val); - } - }); + var mfn, fn, value = []; + fn = function (x, y) { return x + y; }; + mfn = t(fn, { dispose: function (val) { value.push(val); } }); mfn(3, 7); mfn(5, 8); @@ -2422,18 +2244,9 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Ref counter": function (a) { - var mfn, - fn, - value = []; - fn = function (x, y) { - return x + y; - }; - mfn = t(fn, { - refCounter: true, - dispose: function (val) { - value.push(val); - } - }); + var mfn, fn, value = []; + fn = function (x, y) { return x + y; }; + mfn = t(fn, { refCounter: true, dispose: function (val) { value.push(val); } }); mfn(3, 7); mfn(5, 8); @@ -2454,23 +2267,13 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Async": function (a, d) { - var mfn, - fn, - u = {}, - value = []; + var mfn, fn, u = {}, value = []; fn = function (x, y, cb) { - nextTick(function () { - cb(null, x + y); - }); + nextTick(function () { cb(null, x + y); }); return u; }; - mfn = t(fn, { - async: true, - dispose: function (val) { - value.push(val); - } - }); + mfn = t(fn, { async: true, dispose: function (val) { value.push(val); } }); mfn(3, 7, function () { mfn(5, 8, function () { @@ -2491,8 +2294,8 @@ module.exports = function (t, a) { }); }); }); - } - } - } + }, + }, + }, }; }; diff --git a/test/lib/configure-map.js b/test/lib/configure-map.js index cb4d1db..4a647e8 100644 --- a/test/lib/configure-map.js +++ b/test/lib/configure-map.js @@ -10,15 +10,11 @@ module.exports = function () { "One arg": function (a) { var i = 0 , fn = function (x) { - ++i; - return x; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = memoize(fn, { primitive: true }); a(mfn(y), y, "#1"); a(mfn("foo"), y, "#2"); @@ -27,15 +23,11 @@ module.exports = function () { "No args": function (a) { var i = 0 , fn = function () { - ++i; - return "foo"; - } - , mfn - , y = { - toString: function () { + ++i; return "foo"; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = memoize(fn); a(mfn._has(), false); a(mfn(), "foo", "#1"); @@ -46,46 +38,28 @@ module.exports = function () { "Clear cache": function (a) { var i = 0 , fn = function (x, y, z) { - ++i; - return x + y + z; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x + y + z; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete( - "foo", - { - toString: function () { - return "bar"; - } - }, - "zeta" - ); + mfn.delete("foo", { toString: function () { return "bar"; } }, "zeta"); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); }, "_get": function (a) { - var fn = function (x) { - return x; - } - , mfn; + var fn = function (x) { return x; }, mfn; mfn = memoize(fn); a(mfn._get("foo"), undefined); mfn("foo"); a(mfn._get("foo"), "foo"); }, "_has": function (a) { - var fn = function (x) { - return x; - } - , mfn; + var fn = function (x) { return x; }, mfn; mfn = memoize(fn); a(mfn._has("foo"), false); mfn("foo"); @@ -93,20 +67,12 @@ module.exports = function () { }, "Circular": function (a) { var i = 0, fn; - fn = memoize(function (x) { - if (++i < 2) fn(x); - }); - a.throws(function () { - fn("foo"); - }, "CIRCULAR_INVOCATION"); + fn = memoize(function (x) { if (++i < 2) fn(x); }); + a.throws(function () { fn("foo"); }, "CIRCULAR_INVOCATION"); i = 0; - fn = memoize(function (x, y) { - if (++i < 2) fn(x, y); - }); - a.throws(function () { - fn("foo", "bar"); - }, "CIRCULAR_INVOCATION"); + fn = memoize(function (x, y) { if (++i < 2) fn(x, y); }); + a.throws(function () { fn("foo", "bar"); }, "CIRCULAR_INVOCATION"); }, "Resolvers": function () { var i = 0, fn, r; @@ -120,7 +86,7 @@ module.exports = function () { return { "No args": function (a) { i = 0; - a.deep(aFrom(r = fn()), [false, "undefined"], "First"); + a.deep(aFrom((r = fn())), [false, "undefined"], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -133,24 +99,24 @@ module.exports = function () { }, { resolvers: [Boolean] } ); - a.deep(aFrom(r = fn("elo")), [true], "First"); + a.deep(aFrom((r = fn("elo"))), [true], "First"); }, "Some Args": function (a) { var x = {}; i = 0; - a.deep(aFrom(r = fn(0, 34, x, 45)), [false, "34", x, 45], "First"); + a.deep(aFrom((r = fn(0, 34, x, 45))), [false, "34", x, 45], "First"); a(fn(0, 34, x, 22), r, "Second"); a(fn(0, 34, x, false), r, "Third"); a(i, 1, "Called once"); return { Other: function (a) { - a.deep(aFrom(r = fn(1, 34, x, 34)), [true, "34", x, 34], "Second"); + a.deep(aFrom((r = fn(1, 34, x, 34))), [true, "34", x, 34], "Second"); a(fn(1, 34, x, 89), r, "Third"); a(i, 2, "Called once"); - } + }, }; - } + }, }; - } + }, }; }; diff --git a/test/lib/methods.js b/test/lib/methods.js index 11d9ae5..1824bd6 100644 --- a/test/lib/methods.js +++ b/test/lib/methods.js @@ -19,13 +19,8 @@ module.exports = function (t, a) { a(this, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } - ) + { refCounter: true, dispose: function (val) { value.push(val); } } + ), }) ); diff --git a/test/lib/weak.js b/test/lib/weak.js index a84acad..7cc09d6 100644 --- a/test/lib/weak.js +++ b/test/lib/weak.js @@ -15,12 +15,7 @@ module.exports = function (t, a) { a(arg, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } + { refCounter: true, dispose: function (val) { value.push(val); } } ); a(memoized(obj, 3, 7), 10); @@ -42,9 +37,7 @@ module.exports = function (t, a) { x = {}; y = {}; z = {}; - memoized = t(function (arg) { - return ++count; - }); + memoized = t(function (arg) { return ++count; }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); diff --git a/test/methods-plain.js b/test/methods-plain.js index a7f375c..b821662 100644 --- a/test/methods-plain.js +++ b/test/methods-plain.js @@ -17,13 +17,8 @@ module.exports = function (t, a) { a(this, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } - ) + { refCounter: true, dispose: function (val) { value.push(val); } } + ), }) ); diff --git a/test/methods.js b/test/methods.js index acfd941..ca17d79 100644 --- a/test/methods.js +++ b/test/methods.js @@ -14,13 +14,8 @@ module.exports = function (t, a) { a(this, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } - ) + { refCounter: true, dispose: function (val) { value.push(val); } } + ), }) ); diff --git a/test/normalizers/get-1.js b/test/normalizers/get-1.js index e33efc3..5c64e00 100644 --- a/test/normalizers/get-1.js +++ b/test/normalizers/get-1.js @@ -8,9 +8,9 @@ module.exports = { "": function (t, a) { var i = 0 , fn = function (x) { - ++i; - return x; - }; + ++i; + return x; + }; fn = memoize(fn); return { @@ -36,15 +36,13 @@ module.exports = { a(fn(x, 9), x, "Second"); a(fn(x, 3), x, "Third"); a(i, 1, "Called once"); - } + }, }; }, "Delete": function (a) { var i = 0, fn, mfn, x = {}; - fn = function (a, b, c) { - return a + ++i; - }; + fn = function (a, b, c) { return a + ++i; }; mfn = memoize(fn, { length: 1 }); a(mfn(3), 4, "Init"); a(mfn(4, x, 1), 6, "Init #2"); @@ -58,5 +56,5 @@ module.exports = { a(i, 3, "Reinit count"); a(mfn(3, x, 1), 6, "Reinit Cached"); a(i, 3, "Reinit count"); - } + }, }; diff --git a/test/normalizers/get-fixed.js b/test/normalizers/get-fixed.js index f26e17e..f2b3b18 100644 --- a/test/normalizers/get-fixed.js +++ b/test/normalizers/get-fixed.js @@ -8,16 +8,16 @@ module.exports = { "": function (a) { var i = 0 , fn = function (x, y, z) { - ++i; - return [x, y, z]; - } + ++i; + return [x, y, z]; + } , r; fn = memoize(fn); return { "No args": function () { i = 0; - a.deep(r = fn(), [undefined, undefined, undefined], "First"); + a.deep((r = fn()), [undefined, undefined, undefined], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -25,41 +25,39 @@ module.exports = { "Some Args": function () { var x = {}; i = 0; - a.deep(r = fn(x, 8), [x, 8, undefined], "First"); + a.deep((r = fn(x, 8)), [x, 8, undefined], "First"); a(fn(x, 8), r, "Second"); a(fn(x, 8), r, "Third"); a(i, 1, "Called once"); return { Other: function () { - a.deep(r = fn(x, 5), [x, 5, undefined], "Second"); + a.deep((r = fn(x, 5)), [x, 5, undefined], "Second"); a(fn(x, 5), r, "Third"); a(i, 2, "Called once"); - } + }, }; }, "Full stuff": function () { var x = {}; i = 0; - a.deep(r = fn(x, 8, 23, 98), [x, 8, 23], "First"); + a.deep((r = fn(x, 8, 23, 98)), [x, 8, 23], "First"); a(fn(x, 8, 23, 43), r, "Second"); a(fn(x, 8, 23, 9), r, "Third"); a(i, 1, "Called once"); return { Other: function () { - a.deep(r = fn(x, 23, 8, 13), [x, 23, 8], "Second"); + a.deep((r = fn(x, 23, 8, 13)), [x, 23, 8], "Second"); a(fn(x, 23, 8, 22), r, "Third"); a(i, 2, "Called once"); - } + }, }; - } + }, }; }, "Delete": function (a) { var i = 0, fn, mfn, x = {}; - fn = function (a, b, c) { - return a + ++i; - }; + fn = function (a, b, c) { return a + ++i; }; mfn = memoize(fn); a(mfn(3, x, 1), 4, "Init"); a(mfn(4, x, 1), 6, "Init #2"); @@ -94,5 +92,5 @@ module.exports = { fn(1, x, 3); fn(1, x, 4); a(i, 4, "After clear"); - } + }, }; diff --git a/test/normalizers/get-primitive-fixed.js b/test/normalizers/get-primitive-fixed.js index e18d9cd..57faff7 100644 --- a/test/normalizers/get-primitive-fixed.js +++ b/test/normalizers/get-primitive-fixed.js @@ -8,15 +8,11 @@ module.exports = { "": function (a) { var i = 0 , fn = function (x, y, z) { - ++i; - return x + y + z; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x + y + z; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); @@ -25,46 +21,26 @@ module.exports = { "Delete": function (a) { var i = 0 , fn = function (x, y, z) { - ++i; - return x + y + z; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x + y + z; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete( - "foo", - { - toString: function () { - return "bar"; - } - }, - "zeta" - ); + mfn.delete("foo", { toString: function () { return "bar"; } }, "zeta"); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); }, "Clear": function (a) { var i = 0, fn; - fn = memoize(function (x) { - if (++i < 2) fn(x); - }); - a.throws(function () { - fn("foo"); - }, "CIRCULAR_INVOCATION"); + fn = memoize(function (x) { if (++i < 2) fn(x); }); + a.throws(function () { fn("foo"); }, "CIRCULAR_INVOCATION"); i = 0; - fn = memoize(function (x, y) { - if (++i < 2) fn(x, y); - }); - a.throws(function () { - fn("foo", "bar"); - }, "CIRCULAR_INVOCATION"); - } + fn = memoize(function (x, y) { if (++i < 2) fn(x, y); }); + a.throws(function () { fn("foo", "bar"); }, "CIRCULAR_INVOCATION"); + }, }; diff --git a/test/normalizers/get.js b/test/normalizers/get.js index e4d512b..22b9577 100644 --- a/test/normalizers/get.js +++ b/test/normalizers/get.js @@ -10,16 +10,16 @@ module.exports = function () { "": function (a) { var i = 0 , fn = function () { - ++i; - return arguments; - } + ++i; + return arguments; + } , r; fn = memoize(fn, { length: false }); return { "No args": function () { i = 0; - a.deep(aFrom(r = fn()), [], "First"); + a.deep(aFrom((r = fn())), [], "First"); a(fn(), r, "Second"); a(fn(), r, "Third"); a(i, 1, "Called once"); @@ -27,7 +27,7 @@ module.exports = function () { "Some Args": function () { var x = {}; i = 0; - a.deep(aFrom(r = fn(x, 8)), [x, 8], "First"); + a.deep(aFrom((r = fn(x, 8))), [x, 8], "First"); a(fn(x, 8), r, "Second"); a(fn(x, 8), r, "Third"); a(i, 1, "Called once"); @@ -35,19 +35,17 @@ module.exports = function () { "Many args": function () { var x = {}; i = 0; - a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First"); + a.deep(aFrom((r = fn(x, 8, 23, 98))), [x, 8, 23, 98], "First"); a(fn(x, 8, 23, 98), r, "Second"); a(fn(x, 8, 23, 98), r, "Third"); a(i, 1, "Called once"); - } + }, }; }, "Delete": function (a) { var i = 0, fn, mfn, x = {}; - fn = function (a, b, c) { - return a + ++i; - }; + fn = function (a, b, c) { return a + ++i; }; mfn = memoize(fn, { length: false }); a(mfn(3, x, 1), 4, "Init"); a(mfn(4, x, 1), 6, "Init #2"); @@ -61,6 +59,6 @@ module.exports = function () { a(i, 3, "Reinit count"); a(mfn(3, x, 1), 6, "Reinit Cached"); a(i, 3, "Reinit count"); - } + }, }; }; diff --git a/test/normalizers/primitive.js b/test/normalizers/primitive.js index 2873795..3d2443f 100644 --- a/test/normalizers/primitive.js +++ b/test/normalizers/primitive.js @@ -8,14 +8,10 @@ var memoize = require("../..") module.exports = function (a) { var i = 0 , fn = function () { - ++i; - return join.call(arguments, "|"); - } - , y = { - toString: function () { - return "foo"; + ++i; + return join.call(arguments, "|"); } - } + , y = { toString: function () { return "foo"; } } , mfn; mfn = memoize(fn, { primitive: true, length: false }); a(mfn(y, "bar", "zeta"), "foo|bar|zeta", "#1"); diff --git a/test/plain.js b/test/plain.js index 2f35012..2c5411c 100644 --- a/test/plain.js +++ b/test/plain.js @@ -7,15 +7,11 @@ module.exports = function (t) { "": function (a) { var i = 0 , fn = function (x) { - ++i; - return x; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = t(fn, { primitive: true }); a(typeof mfn, "function", "Returns"); a(mfn.__memoized__, true, "Marked"); @@ -27,30 +23,18 @@ module.exports = function (t) { "Clear cache": function (a) { var i = 0 , fn = function (x, y, z) { - ++i; - return x + y + z; - } - , mfn - , y = { - toString: function () { - return "foo"; + ++i; + return x + y + z; } - }; + , mfn + , y = { toString: function () { return "foo"; } }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete( - "foo", - { - toString: function () { - return "bar"; - } - }, - "zeta" - ); + mfn.delete("foo", { toString: function () { return "bar"; } }, "zeta"); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); - } + }, }; }; diff --git a/test/weak-plain.js b/test/weak-plain.js index 460d4c7..faad9ec 100644 --- a/test/weak-plain.js +++ b/test/weak-plain.js @@ -12,12 +12,7 @@ module.exports = function (t, a) { a(arg, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } + { refCounter: true, dispose: function (val) { value.push(val); } } ); a(memoized(obj, 3, 7), 10); @@ -39,9 +34,7 @@ module.exports = function (t, a) { x = {}; y = {}; z = {}; - memoized = t(function (arg) { - return ++count; - }); + memoized = t(function (arg) { return ++count; }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); diff --git a/test/weak.js b/test/weak.js index 9170be7..eb71d01 100644 --- a/test/weak.js +++ b/test/weak.js @@ -9,12 +9,7 @@ module.exports = function (t, a, d) { a(arg, obj); return x + y; }, - { - refCounter: true, - dispose: function (val) { - value.push(val); - } - } + { refCounter: true, dispose: function (val) { value.push(val); } } ); a(memoized(obj, 3, 7), 10); @@ -36,9 +31,7 @@ module.exports = function (t, a, d) { x = {}; y = {}; z = {}; - memoized = t(function (arg) { - return ++count; - }); + memoized = t(function (arg) { return ++count; }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); @@ -46,12 +39,7 @@ module.exports = function (t, a, d) { a(count, 3); count = 0; - memoized = t( - function (arg) { - return ++count; - }, - { maxAge: 1 } - ); + memoized = t(function (arg) { return ++count; }, { maxAge: 1 }); memoized(obj); setTimeout(function () {