summaryrefslogtreecommitdiffstats
path: root/debian/tests/test_modules/chai-iterator
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/test_modules/chai-iterator')
-rw-r--r--debian/tests/test_modules/chai-iterator/LICENSE20
-rw-r--r--debian/tests/test_modules/chai-iterator/chai-iterator.js334
-rw-r--r--debian/tests/test_modules/chai-iterator/package.json70
3 files changed, 424 insertions, 0 deletions
diff --git a/debian/tests/test_modules/chai-iterator/LICENSE b/debian/tests/test_modules/chai-iterator/LICENSE
new file mode 100644
index 0000000..34f7723
--- /dev/null
+++ b/debian/tests/test_modules/chai-iterator/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2016-2017 Akim McMath
+Copyright (c) 2018 Harry Sarson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/debian/tests/test_modules/chai-iterator/chai-iterator.js b/debian/tests/test_modules/chai-iterator/chai-iterator.js
new file mode 100644
index 0000000..e2c9f93
--- /dev/null
+++ b/debian/tests/test_modules/chai-iterator/chai-iterator.js
@@ -0,0 +1,334 @@
+(function (chaiIterator) {
+ 'use strict';
+
+ /* istanbul ignore else */
+ if (typeof module === 'object' && typeof exports === 'object') {
+ module.exports = chaiIterator;
+ } else if (typeof define === 'function' && define.amd) {
+ define(function () {
+ return chaiIterator;
+ });
+ } else {
+ chai.use(chaiIterator);
+ }
+})(function (chai, utils) {
+ 'use strict';
+
+ var Assertion = chai.Assertion;
+ var assert = chai.assert;
+
+ var noop = function () {};
+
+ var ELLIPSIS = unquote('...');
+
+ // Expect/should assertions =============================
+
+ Assertion.addProperty('iterable', function () {
+ this.assert(isIterable(this._obj),
+ 'expected #{this} to be iterable',
+ 'expected #{this} not to be iterable'
+ );
+ });
+
+ Assertion.addProperty('iterate', function () {
+ new Assertion(this._obj).iterable;
+
+ utils.flag(this, 'iterate', true);
+ });
+
+ Assertion.addMethod('over', iterateMethod('to iterate over', function (exp) {
+ var it = this._obj[Symbol.iterator]();
+ var actual = slice(it, exp.length + 2);
+ var suffix = it.next().done ? [] : [ELLIPSIS];
+
+ return actual.concat(suffix);
+ }));
+
+ Assertion.addMethod('from', iterateMethod('to begin iteration with', function (exp) {
+ return slice(this._obj[Symbol.iterator](), exp.length);
+ }));
+
+ Assertion.addMethod('until', iterateMethod('to end iteration with', function (exp) {
+ var it = this._obj[Symbol.iterator]();
+ var actual = slice(it, exp.length);
+ var step = it.next();
+
+ while (!step.done) {
+ actual.push(step.value);
+ actual.shift();
+ step = it.next();
+ }
+
+ return actual;
+ }));
+
+ Assertion.addProperty('for', noop);
+
+ Assertion.overwriteChainableMethod('lengthOf', function (_super) {
+ return function (exp) {
+ if (utils.flag(this, 'iterate')) {
+ var len = iterableLength(this._obj, exp);
+
+ this.assert(
+ len === exp,
+ 'expected #{this} to iterate for length of #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length of #{exp}',
+ exp,
+ len
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ }, function (_super) {
+ return function () {
+ _super.apply(this);
+ };
+ });
+
+ Assertion.overwriteMethod('above', function (_super) {
+ return function (exp) {
+ if (utils.flag(this, 'iterate')) {
+ var len = iterableLength(this._obj, exp);
+
+ this.assert(
+ len > exp,
+ 'expected #{this} to iterate for length above #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length above #{exp}',
+ exp,
+ len
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ });
+
+ Assertion.overwriteMethod('below', function (_super) {
+ return function (exp) {
+ if (utils.flag(this, 'iterate')) {
+ var max = exp + 100;
+ var len = iterableLength(this._obj, max);
+ var act = len === Infinity ? unquote('more than ' + max) : len;
+
+ this.assert(
+ len < exp,
+ 'expected #{this} to iterate for length below #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length below #{exp}',
+ exp,
+ act
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ });
+
+ Assertion.overwriteMethod('least', function (_super) {
+ return function (exp) {
+ if (utils.flag(this, 'iterate')) {
+ var len = iterableLength(this._obj, exp);
+
+ this.assert(
+ len >= exp,
+ 'expected #{this} to iterate for length of at least #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length of at least #{exp}',
+ exp,
+ len
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ });
+
+ Assertion.overwriteMethod('most', function (_super) {
+ return function (exp) {
+ if (utils.flag(this, 'iterate')) {
+ var max = exp + 100;
+ var len = iterableLength(this._obj, max);
+ var act = len === Infinity ? unquote('more than ' + max) : len;
+
+ this.assert(
+ len <= exp,
+ 'expected #{this} to iterate for length of at most #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length of at most #{exp}',
+ exp,
+ act
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ });
+
+ Assertion.overwriteMethod('within', function (_super) {
+ return function (min, max) {
+ if (utils.flag(this, 'iterate')) {
+ var cutoff = max + 100;
+ var len = iterableLength(this._obj, cutoff);
+ var exp = unquote(min + 'and' + max);
+ var act = len === Infinity ? unquote('more than ' + cutoff) : len;
+
+ this.assert(
+ min <= len && len <= max,
+ 'expected #{this} to iterate for length within #{exp}, but got #{act}',
+ 'expected #{this} not to iterate for length within #{exp}',
+ exp,
+ act
+ );
+ } else {
+ _super.apply(this, arguments);
+ }
+ };
+ });
+
+ // Assert methods =======================================
+
+ assert.isIterable = function (value, msg) {
+ new Assertion(value, msg).iterable;
+ };
+
+ assert.isNotIterable = function (value, msg) {
+ new Assertion(value, msg).not.iterable;
+ };
+
+ assert.iteratesFrom = function (value, exp, msg) {
+ new Assertion(value, msg).iterate.from(exp);
+ };
+
+ assert.doesNotIterateFrom = function (value, exp, msg) {
+ new Assertion(value, msg).not.iterate.from(exp);
+ };
+
+ assert.deepIteratesFrom = function (value, exp, msg) {
+ new Assertion(value, msg).deep.iterate.from(exp);
+ };
+
+ assert.doesNotDeepIterateFrom = function (value, exp, msg) {
+ new Assertion(value, msg).not.deep.iterate.from(exp);
+ };
+
+ assert.iteratesOver = function (value, exp, msg) {
+ new Assertion(value, msg).iterate.over(exp);
+ };
+
+ assert.doesNotIterateOver = function (value, exp, msg) {
+ new Assertion(value, msg).not.iterate.over(exp);
+ };
+
+ assert.deepIteratesOver = function (value, exp, msg) {
+ new Assertion(value, msg).deep.iterate.over(exp);
+ };
+
+ assert.doesNotDeepIterateOver = function (value, exp, msg) {
+ new Assertion(value, msg).not.deep.iterate.over(exp);
+ };
+
+ assert.iteratesUntil = function (value, exp, msg) {
+ new Assertion(value, msg).iterate.until(exp);
+ };
+
+ assert.doesNotIterateUntil = function (value, exp, msg) {
+ new Assertion(value, msg).not.iterate.until(exp);
+ };
+
+ assert.deepIteratesUntil = function (value, exp, msg) {
+ new Assertion(value, msg).deep.iterate.until(exp);
+ };
+
+ assert.doesNotDeepIterateUntil = function (value, exp, msg) {
+ new Assertion(value, msg).not.deep.iterate.until(exp);
+ };
+
+ var _lengthOf = assert.lengthOf;
+
+ assert.lengthOf = function (value, exp, msg) {
+ if (isIterable(value) && typeof value.length !== 'number') {
+ new Assertion(value, msg).iterate.for.lengthOf(exp);
+ } else {
+ _lengthOf.apply(assert, arguments);
+ }
+ };
+
+ // Helpers ==============================================
+
+ function iterateMethod(predicate, getActual) {
+ return function (iterable) {
+ assert(utils.flag(this, 'iterate'), 'the iterate flag must be set');
+ new Assertion(iterable).iterable;
+
+ var exp = slice(iterable[Symbol.iterator]());
+ var act = getActual.call(this, exp);
+
+ var deep = utils.flag(this, 'deep') ? ' deep' : '';
+
+ this.assert(compareArrays(exp, act, deep),
+ 'expected #{this} ' + predicate + deep + ' values #{exp}, but got #{act}',
+ 'expected #{this} not ' + predicate + deep + ' values #{exp}',
+ exp,
+ act
+ );
+ };
+ }
+
+ // Utilities ============================================
+
+ function isIterable(value) {
+ return value !== undefined && value !== null && typeof value[Symbol.iterator] === 'function';
+ }
+
+ function iterableLength(iterable, max) {
+ max = max === undefined ? Infinity : max;
+
+ var it = iterable[Symbol.iterator]();
+
+ for (var i = 0; i <= max; i++) {
+ if (it.next().done) {
+ return i;
+ }
+ }
+
+ return Infinity;
+ }
+
+ function strictEqual(a, b) {
+ return a === b;
+ }
+
+ function compareArrays(exp, act, deep) {
+ var equalFn = deep ? utils.eql : strictEqual;
+
+ return exp.length === act.length && exp.every(function (value, i) {
+ return equalFn(value, act[i]);
+ });
+ }
+
+ function slice(it, stop) {
+ stop = stop === undefined ? Infinity : stop;
+
+ var result = [];
+ var max = stop - 1;
+ var step = it.next();
+
+ for (var i = 0; i <= max && !step.done; i++) {
+ result.push(step.value);
+ if (i < max) {
+ step = it.next();
+ }
+ }
+
+ return result;
+ }
+
+ function unquote(str) {
+ return {
+ inspect: function () {
+ return this.toString();
+ },
+ toString: function () {
+ return str;
+ }
+ };
+ }
+});
diff --git a/debian/tests/test_modules/chai-iterator/package.json b/debian/tests/test_modules/chai-iterator/package.json
new file mode 100644
index 0000000..34f76c1
--- /dev/null
+++ b/debian/tests/test_modules/chai-iterator/package.json
@@ -0,0 +1,70 @@
+{
+ "name": "chai-iterator",
+ "version": "3.0.2",
+ "description": "Chai assertions for iterable objects",
+ "main": "chai-iterator.js",
+ "scripts": {
+ "test:lint": "xo",
+ "test:mocha": "mocha test/**/*.js",
+ "test:cover": "nyc npm run test:mocha",
+ "test": "npm run test:lint && npm run test:cover",
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "files": [
+ "chai-iterator.js",
+ "LICENSE",
+ "CHANGELOG.md",
+ "README.md"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/harrysarson/chai-iterator.git"
+ },
+ "keywords": [
+ "chai",
+ "chai-plugin",
+ "browser",
+ "iterator",
+ "iterable",
+ "iteration",
+ "generator",
+ "yield",
+ "es6",
+ "es2015",
+ "typescript"
+ ],
+ "engines": {
+ "node": ">=6.0"
+ },
+ "author": "Harry Sarson <harry.sarson@hotmail.co.uk>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/harrysarson/chai-iterator/issues"
+ },
+ "homepage": "https://github.com/harrysarson/chai-iterator",
+ "peerDependencies": {
+ "chai": "4.x"
+ },
+ "devDependencies": {
+ "chai": "4.1.2",
+ "coveralls": "3.0.2",
+ "mocha": "6.0.0",
+ "nyc": "13.3.0",
+ "xo": "0.24.0"
+ },
+ "xo": {
+ "esnext": false,
+ "globals": [
+ "chai",
+ "define",
+ "module"
+ ],
+ "env": [
+ "mocha"
+ ],
+ "rules": {
+ "no-unused-expressions": "off",
+ "no-use-extend-native/no-use-extend-native": "off"
+ }
+ }
+}