added unit testing, and started implementing unit tests...phew
This commit is contained in:
27
node_modules/@sinonjs/samsam/lib/create-set.js
generated
vendored
Normal file
27
node_modules/@sinonjs/samsam/lib/create-set.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
var typeOf = require("@sinonjs/commons").typeOf;
|
||||
|
||||
// This helper makes it convenient to create Set instances from a
|
||||
// collection, an overcomes the shortcoming that IE11 doesn't support
|
||||
// collection arguments
|
||||
//
|
||||
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
||||
function createSet(array) {
|
||||
if (arguments.length > 0 && !Array.isArray(array)) {
|
||||
throw new TypeError(
|
||||
"createSet can be called with either no arguments or an Array"
|
||||
);
|
||||
}
|
||||
|
||||
var items = typeOf(array) === "array" ? array : [];
|
||||
var set = new Set();
|
||||
|
||||
items.forEach(function(item) {
|
||||
set.add(item);
|
||||
});
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
module.exports = createSet;
|
74
node_modules/@sinonjs/samsam/lib/deep-equal-benchmark.js
generated
vendored
Normal file
74
node_modules/@sinonjs/samsam/lib/deep-equal-benchmark.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
|
||||
var Benchmark = require("benchmark");
|
||||
var deepEqual = require("./deep-equal");
|
||||
|
||||
var suite = new Benchmark.Suite();
|
||||
var complex1 = {
|
||||
"1e116061-59bf-433a-8ab0-017b67a51d26":
|
||||
"a7fd22ab-e809-414f-ad55-9c97598395d8",
|
||||
"3824e8b7-22f5-489c-9919-43b432e3af6b":
|
||||
"548baefd-f43c-4dc9-9df5-f7c9c96223b0",
|
||||
"123e5750-eb66-45e5-a770-310879203b33":
|
||||
"89ff817d-65a2-4598-b190-21c128096e6a",
|
||||
"1d66be95-8aaa-4167-9a47-e7ee19bb0735":
|
||||
"64349492-56e8-4100-9552-a89fb4a9aef4",
|
||||
"f5538565-dc92-4ee4-a762-1ba5fe0528f6": {
|
||||
"53631f78-2f2a-448f-89c7-ed3585e8e6f0":
|
||||
"2cce00ee-f5ee-43ef-878f-958597b23225",
|
||||
"73e8298b-72fd-4969-afc1-d891b61e744f":
|
||||
"4e57aa30-af51-4d78-887c-019755e5d117",
|
||||
"85439907-5b0e-4a08-8cfa-902a68dc3cc0":
|
||||
"9639add9-6897-4cf0-b3d3-2ebf9c214f01",
|
||||
"d4ae9d87-bd6c-47e0-95a1-6f4eb4211549":
|
||||
"41fd3dd2-43ce-47f2-b92e-462474d07a6f",
|
||||
"f70345a2-0ea3-45a6-bafa-8c7a72379277": {
|
||||
"1bce714b-cd0a-417d-9a0c-bf4b7d35c0c4":
|
||||
"3b8b0dde-e2ed-4b34-ac8d-729ba3c9667e",
|
||||
"13e05c60-97d1-43f0-a6ef-d5247f4dd11f":
|
||||
"60f685a4-6558-4ade-9d4b-28281c3989db",
|
||||
"925b2609-e7b7-42f5-82cf-2d995697cec5":
|
||||
"79115261-8161-4a6c-9487-47847276a717",
|
||||
"52d644ac-7b33-4b79-b5b3-5afe7fd4ec2c": [
|
||||
"3c2ae716-92f1-4a3d-b98f-50ea49f51c45",
|
||||
"de76b822-71b3-4b5a-a041-4140378b70e2",
|
||||
"0302a405-1d58-44fa-a0c6-dd07bb0ca26e",
|
||||
new Date(),
|
||||
new Error(),
|
||||
new RegExp(),
|
||||
// eslint-disable-next-line no-undef
|
||||
new Map(),
|
||||
new Set(),
|
||||
// eslint-disable-next-line no-undef, ie11/no-weak-collections
|
||||
new WeakMap(),
|
||||
// eslint-disable-next-line no-undef, ie11/no-weak-collections
|
||||
new WeakSet()
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
var complex2 = Object.create(complex1);
|
||||
|
||||
var cyclic1 = {
|
||||
"4a092cd1-225e-4739-8331-d6564aafb702":
|
||||
"d0cebbe0-23fb-4cc4-8fa0-ef11ceedf12e"
|
||||
};
|
||||
cyclic1.cyclicRef = cyclic1;
|
||||
|
||||
var cyclic2 = Object.create(cyclic1);
|
||||
|
||||
// add tests
|
||||
suite
|
||||
.add("complex objects", function() {
|
||||
return deepEqual(complex1, complex2);
|
||||
})
|
||||
.add("cyclic references", function() {
|
||||
return deepEqual(cyclic1, cyclic2);
|
||||
})
|
||||
// add listeners
|
||||
.on("cycle", function(event) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(String(event.target));
|
||||
})
|
||||
// run async
|
||||
.run({ async: true });
|
227
node_modules/@sinonjs/samsam/lib/deep-equal.js
generated
vendored
Normal file
227
node_modules/@sinonjs/samsam/lib/deep-equal.js
generated
vendored
Normal file
@ -0,0 +1,227 @@
|
||||
"use strict";
|
||||
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
|
||||
var getClass = require("./get-class");
|
||||
var identical = require("./identical");
|
||||
var isArguments = require("./is-arguments");
|
||||
var isDate = require("./is-date");
|
||||
var isElement = require("./is-element");
|
||||
var isNaN = require("./is-nan");
|
||||
var isObject = require("./is-object");
|
||||
var isSet = require("./is-set");
|
||||
var isSubset = require("./is-subset");
|
||||
var getClassName = require("./get-class-name");
|
||||
|
||||
var every = Array.prototype.every;
|
||||
var getTime = Date.prototype.getTime;
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var indexOf = Array.prototype.indexOf;
|
||||
var keys = Object.keys;
|
||||
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
||||
|
||||
/**
|
||||
* @name samsam.deepEqual
|
||||
* @param Object actual
|
||||
* @param Object expectation
|
||||
*
|
||||
* Deep equal comparison. Two values are "deep equal" if:
|
||||
*
|
||||
* - They are equal, according to samsam.identical
|
||||
* - They are both date objects representing the same time
|
||||
* - They are both arrays containing elements that are all deepEqual
|
||||
* - They are objects with the same set of properties, and each property
|
||||
* in ``actual`` is deepEqual to the corresponding property in ``expectation``
|
||||
*
|
||||
* Supports cyclic objects.
|
||||
*/
|
||||
function deepEqualCyclic(actual, expectation, match) {
|
||||
// used for cyclic comparison
|
||||
// contain already visited objects
|
||||
var actualObjects = [];
|
||||
var expectationObjects = [];
|
||||
// contain pathes (position in the object structure)
|
||||
// of the already visited objects
|
||||
// indexes same as in objects arrays
|
||||
var actualPaths = [];
|
||||
var expectationPaths = [];
|
||||
// contains combinations of already compared objects
|
||||
// in the manner: { "$1['ref']$2['ref']": true }
|
||||
var compared = {};
|
||||
|
||||
// does the recursion for the deep equal check
|
||||
return (function deepEqual(
|
||||
actualObj,
|
||||
expectationObj,
|
||||
actualPath,
|
||||
expectationPath
|
||||
) {
|
||||
// If both are matchers they must be the same instance in order to be
|
||||
// considered equal If we didn't do that we would end up running one
|
||||
// matcher against the other
|
||||
if (match && match.isMatcher(expectationObj)) {
|
||||
if (match.isMatcher(actualObj)) {
|
||||
return actualObj === expectationObj;
|
||||
}
|
||||
return expectationObj.test(actualObj);
|
||||
}
|
||||
|
||||
var actualType = typeof actualObj;
|
||||
var expectationType = typeof expectationObj;
|
||||
|
||||
// == null also matches undefined
|
||||
if (
|
||||
actualObj === expectationObj ||
|
||||
isNaN(actualObj) ||
|
||||
isNaN(expectationObj) ||
|
||||
actualObj == null ||
|
||||
expectationObj == null ||
|
||||
actualType !== "object" ||
|
||||
expectationType !== "object"
|
||||
) {
|
||||
return identical(actualObj, expectationObj);
|
||||
}
|
||||
|
||||
// Elements are only equal if identical(expected, actual)
|
||||
if (isElement(actualObj) || isElement(expectationObj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var isActualDate = isDate(actualObj);
|
||||
var isExpectationDate = isDate(expectationObj);
|
||||
if (isActualDate || isExpectationDate) {
|
||||
if (
|
||||
!isActualDate ||
|
||||
!isExpectationDate ||
|
||||
getTime.call(actualObj) !== getTime.call(expectationObj)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (actualObj instanceof RegExp && expectationObj instanceof RegExp) {
|
||||
if (valueToString(actualObj) !== valueToString(expectationObj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (actualObj instanceof Error && expectationObj instanceof Error) {
|
||||
return actualObj === expectationObj;
|
||||
}
|
||||
|
||||
var actualClass = getClass(actualObj);
|
||||
var expectationClass = getClass(expectationObj);
|
||||
var actualKeys = keys(actualObj);
|
||||
var expectationKeys = keys(expectationObj);
|
||||
var actualName = getClassName(actualObj);
|
||||
var expectationName = getClassName(expectationObj);
|
||||
var expectationSymbols =
|
||||
typeof Object.getOwnPropertySymbols === "function"
|
||||
? getOwnPropertySymbols(expectationObj)
|
||||
: [];
|
||||
var expectationKeysAndSymbols = expectationKeys.concat(
|
||||
expectationSymbols
|
||||
);
|
||||
|
||||
if (isArguments(actualObj) || isArguments(expectationObj)) {
|
||||
if (actualObj.length !== expectationObj.length) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
actualType !== expectationType ||
|
||||
actualClass !== expectationClass ||
|
||||
actualKeys.length !== expectationKeys.length ||
|
||||
(actualName &&
|
||||
expectationName &&
|
||||
actualName !== expectationName)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSet(actualObj) || isSet(expectationObj)) {
|
||||
if (
|
||||
!isSet(actualObj) ||
|
||||
!isSet(expectationObj) ||
|
||||
actualObj.size !== expectationObj.size
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isSubset(actualObj, expectationObj, deepEqual);
|
||||
}
|
||||
|
||||
return every.call(expectationKeysAndSymbols, function(key) {
|
||||
if (!hasOwnProperty.call(actualObj, key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var actualValue = actualObj[key];
|
||||
var expectationValue = expectationObj[key];
|
||||
var actualObject = isObject(actualValue);
|
||||
var expectationObject = isObject(expectationValue);
|
||||
// determines, if the objects were already visited
|
||||
// (it's faster to check for isObject first, than to
|
||||
// get -1 from getIndex for non objects)
|
||||
var actualIndex = actualObject
|
||||
? indexOf.call(actualObjects, actualValue)
|
||||
: -1;
|
||||
var expectationIndex = expectationObject
|
||||
? indexOf.call(expectationObjects, expectationValue)
|
||||
: -1;
|
||||
// determines the new paths of the objects
|
||||
// - for non cyclic objects the current path will be extended
|
||||
// by current property name
|
||||
// - for cyclic objects the stored path is taken
|
||||
var newActualPath =
|
||||
actualIndex !== -1
|
||||
? actualPaths[actualIndex]
|
||||
: actualPath + "[" + JSON.stringify(key) + "]";
|
||||
var newExpectationPath =
|
||||
expectationIndex !== -1
|
||||
? expectationPaths[expectationIndex]
|
||||
: expectationPath + "[" + JSON.stringify(key) + "]";
|
||||
var combinedPath = newActualPath + newExpectationPath;
|
||||
|
||||
// stop recursion if current objects are already compared
|
||||
if (compared[combinedPath]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// remember the current objects and their paths
|
||||
if (actualIndex === -1 && actualObject) {
|
||||
actualObjects.push(actualValue);
|
||||
actualPaths.push(newActualPath);
|
||||
}
|
||||
if (expectationIndex === -1 && expectationObject) {
|
||||
expectationObjects.push(expectationValue);
|
||||
expectationPaths.push(newExpectationPath);
|
||||
}
|
||||
|
||||
// remember that the current objects are already compared
|
||||
if (actualObject && expectationObject) {
|
||||
compared[combinedPath] = true;
|
||||
}
|
||||
|
||||
// End of cyclic logic
|
||||
|
||||
// neither actualValue nor expectationValue is a cycle
|
||||
// continue with next level
|
||||
return deepEqual(
|
||||
actualValue,
|
||||
expectationValue,
|
||||
newActualPath,
|
||||
newExpectationPath
|
||||
);
|
||||
});
|
||||
})(actual, expectation, "$1", "$2");
|
||||
}
|
||||
|
||||
deepEqualCyclic.use = function(match) {
|
||||
return function(a, b) {
|
||||
return deepEqualCyclic(a, b, match);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = deepEqualCyclic;
|
22
node_modules/@sinonjs/samsam/lib/get-class-name.js
generated
vendored
Normal file
22
node_modules/@sinonjs/samsam/lib/get-class-name.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
|
||||
var re = /function (\w+)\s*\(/;
|
||||
|
||||
function getClassName(value) {
|
||||
if (value.constructor && "name" in value.constructor) {
|
||||
return value.constructor.name;
|
||||
}
|
||||
|
||||
if (typeof value.constructor === "function") {
|
||||
var match = valueToString(value.constructor).match(re);
|
||||
if (match.length > 1) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = getClassName;
|
12
node_modules/@sinonjs/samsam/lib/get-class.js
generated
vendored
Normal file
12
node_modules/@sinonjs/samsam/lib/get-class.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var o = Object.prototype;
|
||||
|
||||
function getClass(value) {
|
||||
// Returns the internal [[Class]] by calling Object.prototype.toString
|
||||
// with the provided value as this. Return value is a string, naming the
|
||||
// internal class, e.g. "Array"
|
||||
return o.toString.call(value).split(/[ \]]/)[1];
|
||||
}
|
||||
|
||||
module.exports = getClass;
|
25
node_modules/@sinonjs/samsam/lib/identical.js
generated
vendored
Normal file
25
node_modules/@sinonjs/samsam/lib/identical.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var isNaN = require("./is-nan");
|
||||
var isNegZero = require("./is-neg-zero");
|
||||
|
||||
/**
|
||||
* @name samsam.equal
|
||||
* @param Object obj1
|
||||
* @param Object obj2
|
||||
*
|
||||
* Returns ``true`` if two objects are strictly equal. Compared to
|
||||
* ``===`` there are two exceptions:
|
||||
*
|
||||
* - NaN is considered equal to NaN
|
||||
* - -0 and +0 are not considered equal
|
||||
*/
|
||||
function identical(obj1, obj2) {
|
||||
if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) {
|
||||
return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = identical;
|
35
node_modules/@sinonjs/samsam/lib/is-arguments.js
generated
vendored
Normal file
35
node_modules/@sinonjs/samsam/lib/is-arguments.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
var getClass = require("./get-class");
|
||||
|
||||
/**
|
||||
* @name samsam.isArguments
|
||||
* @param Object object
|
||||
*
|
||||
* Returns ``true`` if ``object`` is an ``arguments`` object,
|
||||
* ``false`` otherwise.
|
||||
*/
|
||||
function isArguments(object) {
|
||||
if (getClass(object) === "Arguments") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
typeof object !== "object" ||
|
||||
typeof object.length !== "number" ||
|
||||
getClass(object) === "Array"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (typeof object.callee === "function") {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
object[object.length] = 6;
|
||||
delete object[object.length];
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = isArguments;
|
7
node_modules/@sinonjs/samsam/lib/is-date.js
generated
vendored
Normal file
7
node_modules/@sinonjs/samsam/lib/is-date.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
function isDate(value) {
|
||||
return value instanceof Date;
|
||||
}
|
||||
|
||||
module.exports = isDate;
|
27
node_modules/@sinonjs/samsam/lib/is-element.js
generated
vendored
Normal file
27
node_modules/@sinonjs/samsam/lib/is-element.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
var div = typeof document !== "undefined" && document.createElement("div");
|
||||
|
||||
/**
|
||||
* @name samsam.isElement
|
||||
* @param Object object
|
||||
*
|
||||
* Returns ``true`` if ``object`` is a DOM element node. Unlike
|
||||
* Underscore.js/lodash, this function will return ``false`` if ``object``
|
||||
* is an *element-like* object, i.e. a regular object with a ``nodeType``
|
||||
* property that holds the value ``1``.
|
||||
*/
|
||||
function isElement(object) {
|
||||
if (!object || object.nodeType !== 1 || !div) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
object.appendChild(div);
|
||||
object.removeChild(div);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = isElement;
|
11
node_modules/@sinonjs/samsam/lib/is-nan.js
generated
vendored
Normal file
11
node_modules/@sinonjs/samsam/lib/is-nan.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
function isNaN(value) {
|
||||
// Unlike global isNaN, this avoids type coercion
|
||||
// typeof check avoids IE host object issues, hat tip to
|
||||
// lodash
|
||||
var val = value; // JsLint thinks value !== value is "weird"
|
||||
return typeof value === "number" && value !== val;
|
||||
}
|
||||
|
||||
module.exports = isNaN;
|
13
node_modules/@sinonjs/samsam/lib/is-neg-zero.js
generated
vendored
Normal file
13
node_modules/@sinonjs/samsam/lib/is-neg-zero.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @name samsam.isNegZero
|
||||
* @param Object value
|
||||
*
|
||||
* Returns ``true`` if ``value`` is ``-0``.
|
||||
*/
|
||||
function isNegZero(value) {
|
||||
return value === 0 && 1 / value === -Infinity;
|
||||
}
|
||||
|
||||
module.exports = isNegZero;
|
24
node_modules/@sinonjs/samsam/lib/is-object.js
generated
vendored
Normal file
24
node_modules/@sinonjs/samsam/lib/is-object.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
// Returns true when the value is a regular Object and not a specialized Object
|
||||
//
|
||||
// This helps speeding up deepEqual cyclic checks
|
||||
// The premise is that only Objects are stored in the visited array.
|
||||
// So if this function returns false, we don't have to do the
|
||||
// expensive operation of searching for the value in the the array of already
|
||||
// visited objects
|
||||
function isObject(value) {
|
||||
return (
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
// none of these are collection objects, so we can return false
|
||||
!(value instanceof Boolean) &&
|
||||
!(value instanceof Date) &&
|
||||
!(value instanceof Error) &&
|
||||
!(value instanceof Number) &&
|
||||
!(value instanceof RegExp) &&
|
||||
!(value instanceof String)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = isObject;
|
7
node_modules/@sinonjs/samsam/lib/is-set.js
generated
vendored
Normal file
7
node_modules/@sinonjs/samsam/lib/is-set.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
function isSet(val) {
|
||||
return (typeof Set !== "undefined" && val instanceof Set) || false;
|
||||
}
|
||||
|
||||
module.exports = isSet;
|
18
node_modules/@sinonjs/samsam/lib/is-subset.js
generated
vendored
Normal file
18
node_modules/@sinonjs/samsam/lib/is-subset.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
function isSubset(s1, s2, compare) {
|
||||
var allContained = true;
|
||||
s1.forEach(function(v1) {
|
||||
var includes = false;
|
||||
s2.forEach(function(v2) {
|
||||
if (compare(v2, v1)) {
|
||||
includes = true;
|
||||
}
|
||||
});
|
||||
allContained = allContained && includes;
|
||||
});
|
||||
|
||||
return allContained;
|
||||
}
|
||||
|
||||
module.exports = isSubset;
|
42
node_modules/@sinonjs/samsam/lib/iterable-to-string.js
generated
vendored
Normal file
42
node_modules/@sinonjs/samsam/lib/iterable-to-string.js
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
var slice = require("@sinonjs/commons").prototypes.string.slice;
|
||||
var typeOf = require("@sinonjs/commons").typeOf;
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
|
||||
module.exports = function iterableToString(obj) {
|
||||
var representation = "";
|
||||
|
||||
function stringify(item) {
|
||||
return typeof item === "string"
|
||||
? "'" + item + "'"
|
||||
: valueToString(item);
|
||||
}
|
||||
|
||||
function mapToString(map) {
|
||||
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
||||
map.forEach(function(value, key) {
|
||||
representation +=
|
||||
"[" + stringify(key) + "," + stringify(value) + "],";
|
||||
});
|
||||
|
||||
representation = slice(representation, 0, -1);
|
||||
return representation;
|
||||
}
|
||||
|
||||
function genericIterableToString(iterable) {
|
||||
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
||||
iterable.forEach(function(value) {
|
||||
representation += stringify(value) + ",";
|
||||
});
|
||||
|
||||
representation = slice(representation, 0, -1);
|
||||
return representation;
|
||||
}
|
||||
|
||||
if (typeOf(obj) === "map") {
|
||||
return mapToString(obj);
|
||||
}
|
||||
|
||||
return genericIterableToString(obj);
|
||||
};
|
136
node_modules/@sinonjs/samsam/lib/match.js
generated
vendored
Normal file
136
node_modules/@sinonjs/samsam/lib/match.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
|
||||
var deepEqual = require("./deep-equal").use(match); // eslint-disable-line no-use-before-define
|
||||
var getClass = require("./get-class");
|
||||
var isDate = require("./is-date");
|
||||
var isSet = require("./is-set");
|
||||
var isSubset = require("./is-subset");
|
||||
var createMatcher = require("./matcher");
|
||||
|
||||
function arrayContains(array, subset, compare) {
|
||||
if (subset.length === 0) {
|
||||
return true;
|
||||
}
|
||||
var i, l, j, k;
|
||||
for (i = 0, l = array.length; i < l; ++i) {
|
||||
if (compare(array[i], subset[0])) {
|
||||
for (j = 0, k = subset.length; j < k; ++j) {
|
||||
if (i + j >= l) {
|
||||
return false;
|
||||
}
|
||||
if (!compare(array[i + j], subset[j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name samsam.match
|
||||
* @param Object object
|
||||
* @param Object matcher
|
||||
*
|
||||
* Compare arbitrary value ``object`` with matcher.
|
||||
*/
|
||||
function match(object, matcher) {
|
||||
if (matcher && typeof matcher.test === "function") {
|
||||
return matcher.test(object);
|
||||
}
|
||||
|
||||
if (typeof matcher === "function") {
|
||||
return matcher(object) === true;
|
||||
}
|
||||
|
||||
if (typeof matcher === "string") {
|
||||
matcher = matcher.toLowerCase();
|
||||
var notNull = typeof object === "string" || !!object;
|
||||
return (
|
||||
notNull &&
|
||||
valueToString(object)
|
||||
.toLowerCase()
|
||||
.indexOf(matcher) >= 0
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof matcher === "number") {
|
||||
return matcher === object;
|
||||
}
|
||||
|
||||
if (typeof matcher === "boolean") {
|
||||
return matcher === object;
|
||||
}
|
||||
|
||||
if (typeof matcher === "undefined") {
|
||||
return typeof object === "undefined";
|
||||
}
|
||||
|
||||
if (matcher === null) {
|
||||
return object === null;
|
||||
}
|
||||
|
||||
if (object === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isSet(object)) {
|
||||
return isSubset(matcher, object, match);
|
||||
}
|
||||
|
||||
if (getClass(object) === "Array" && getClass(matcher) === "Array") {
|
||||
return arrayContains(object, matcher, match);
|
||||
}
|
||||
|
||||
if (isDate(matcher)) {
|
||||
return isDate(object) && object.getTime() === matcher.getTime();
|
||||
}
|
||||
|
||||
if (matcher && typeof matcher === "object") {
|
||||
if (matcher === object) {
|
||||
return true;
|
||||
}
|
||||
if (typeof object !== "object") {
|
||||
return false;
|
||||
}
|
||||
var prop;
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (prop in matcher) {
|
||||
var value = object[prop];
|
||||
if (
|
||||
typeof value === "undefined" &&
|
||||
typeof object.getAttribute === "function"
|
||||
) {
|
||||
value = object.getAttribute(prop);
|
||||
}
|
||||
if (
|
||||
matcher[prop] === null ||
|
||||
typeof matcher[prop] === "undefined"
|
||||
) {
|
||||
if (value !== matcher[prop]) {
|
||||
return false;
|
||||
}
|
||||
} else if (
|
||||
typeof value === "undefined" ||
|
||||
!deepEqual(value, matcher[prop])
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Matcher was not a string, a number, a " +
|
||||
"function, a boolean or an object"
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(createMatcher).forEach(function(key) {
|
||||
match[key] = createMatcher[key];
|
||||
});
|
||||
|
||||
module.exports = match;
|
470
node_modules/@sinonjs/samsam/lib/matcher.js
generated
vendored
Normal file
470
node_modules/@sinonjs/samsam/lib/matcher.js
generated
vendored
Normal file
@ -0,0 +1,470 @@
|
||||
"use strict";
|
||||
|
||||
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
||||
var deepEqual = require("./deep-equal").use(match); // eslint-disable-line no-use-before-define
|
||||
var every = require("@sinonjs/commons").every;
|
||||
var functionName = require("@sinonjs/commons").functionName;
|
||||
var get = require("lodash").get;
|
||||
var iterableToString = require("./iterable-to-string");
|
||||
var objectProto = require("@sinonjs/commons").prototypes.object;
|
||||
var stringProto = require("@sinonjs/commons").prototypes.string;
|
||||
var typeOf = require("@sinonjs/commons").typeOf;
|
||||
var valueToString = require("@sinonjs/commons").valueToString;
|
||||
|
||||
var arrayIndexOf = arrayProto.indexOf;
|
||||
var arrayEvery = arrayProto.every;
|
||||
var join = arrayProto.join;
|
||||
var map = arrayProto.map;
|
||||
var some = arrayProto.some;
|
||||
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
var isPrototypeOf = objectProto.isPrototypeOf;
|
||||
|
||||
var stringIndexOf = stringProto.indexOf;
|
||||
|
||||
function assertType(value, type, name) {
|
||||
var actual = typeOf(value);
|
||||
if (actual !== type) {
|
||||
throw new TypeError(
|
||||
"Expected type of " +
|
||||
name +
|
||||
" to be " +
|
||||
type +
|
||||
", but was " +
|
||||
actual
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function assertMethodExists(value, method, name, methodPath) {
|
||||
if (value[method] == null) {
|
||||
throw new TypeError(
|
||||
"Expected " + name + " to have method " + methodPath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var matcher = {
|
||||
toString: function() {
|
||||
return this.message;
|
||||
}
|
||||
};
|
||||
|
||||
function isMatcher(object) {
|
||||
return isPrototypeOf(matcher, object);
|
||||
}
|
||||
|
||||
function matchObject(actual, expectation) {
|
||||
if (actual === null || actual === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return arrayEvery(Object.keys(expectation), function(key) {
|
||||
var exp = expectation[key];
|
||||
var act = actual[key];
|
||||
|
||||
if (isMatcher(exp)) {
|
||||
if (!exp.test(act)) {
|
||||
return false;
|
||||
}
|
||||
} else if (typeOf(exp) === "object") {
|
||||
if (!matchObject(act, exp)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!deepEqual(act, exp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
var TYPE_MAP = {
|
||||
function: function(m, expectation, message) {
|
||||
m.test = expectation;
|
||||
m.message = message || "match(" + functionName(expectation) + ")";
|
||||
},
|
||||
number: function(m, expectation) {
|
||||
m.test = function(actual) {
|
||||
// we need type coercion here
|
||||
return expectation == actual; // eslint-disable-line eqeqeq
|
||||
};
|
||||
},
|
||||
object: function(m, expectation) {
|
||||
var array = [];
|
||||
|
||||
if (typeof expectation.test === "function") {
|
||||
m.test = function(actual) {
|
||||
return expectation.test(actual) === true;
|
||||
};
|
||||
m.message = "match(" + functionName(expectation.test) + ")";
|
||||
return m;
|
||||
}
|
||||
|
||||
array = map(Object.keys(expectation), function(key) {
|
||||
return key + ": " + valueToString(expectation[key]);
|
||||
});
|
||||
|
||||
m.test = function(actual) {
|
||||
return matchObject(actual, expectation);
|
||||
};
|
||||
m.message = "match(" + join(array, ", ") + ")";
|
||||
|
||||
return m;
|
||||
},
|
||||
regexp: function(m, expectation) {
|
||||
m.test = function(actual) {
|
||||
return typeof actual === "string" && expectation.test(actual);
|
||||
};
|
||||
},
|
||||
string: function(m, expectation) {
|
||||
m.test = function(actual) {
|
||||
return (
|
||||
typeof actual === "string" &&
|
||||
stringIndexOf(actual, expectation) !== -1
|
||||
);
|
||||
};
|
||||
m.message = 'match("' + expectation + '")';
|
||||
}
|
||||
};
|
||||
|
||||
function match(expectation, message) {
|
||||
var m = Object.create(matcher);
|
||||
var type = typeOf(expectation);
|
||||
|
||||
if (message !== undefined && typeof message !== "string") {
|
||||
throw new TypeError("Message should be a string");
|
||||
}
|
||||
|
||||
if (arguments.length > 2) {
|
||||
throw new TypeError(
|
||||
"Expected 1 or 2 arguments, received " + arguments.length
|
||||
);
|
||||
}
|
||||
|
||||
if (type in TYPE_MAP) {
|
||||
TYPE_MAP[type](m, expectation, message);
|
||||
} else {
|
||||
m.test = function(actual) {
|
||||
return deepEqual(actual, expectation);
|
||||
};
|
||||
}
|
||||
|
||||
if (!m.message) {
|
||||
m.message = "match(" + valueToString(expectation) + ")";
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
matcher.or = function(m2) {
|
||||
if (!arguments.length) {
|
||||
throw new TypeError("Matcher expected");
|
||||
} else if (!isMatcher(m2)) {
|
||||
m2 = match(m2);
|
||||
}
|
||||
var m1 = this;
|
||||
var or = Object.create(matcher);
|
||||
or.test = function(actual) {
|
||||
return m1.test(actual) || m2.test(actual);
|
||||
};
|
||||
or.message = m1.message + ".or(" + m2.message + ")";
|
||||
return or;
|
||||
};
|
||||
|
||||
matcher.and = function(m2) {
|
||||
if (!arguments.length) {
|
||||
throw new TypeError("Matcher expected");
|
||||
} else if (!isMatcher(m2)) {
|
||||
m2 = match(m2);
|
||||
}
|
||||
var m1 = this;
|
||||
var and = Object.create(matcher);
|
||||
and.test = function(actual) {
|
||||
return m1.test(actual) && m2.test(actual);
|
||||
};
|
||||
and.message = m1.message + ".and(" + m2.message + ")";
|
||||
return and;
|
||||
};
|
||||
|
||||
match.isMatcher = isMatcher;
|
||||
|
||||
match.any = match(function() {
|
||||
return true;
|
||||
}, "any");
|
||||
|
||||
match.defined = match(function(actual) {
|
||||
return actual !== null && actual !== undefined;
|
||||
}, "defined");
|
||||
|
||||
match.truthy = match(function(actual) {
|
||||
return !!actual;
|
||||
}, "truthy");
|
||||
|
||||
match.falsy = match(function(actual) {
|
||||
return !actual;
|
||||
}, "falsy");
|
||||
|
||||
match.same = function(expectation) {
|
||||
return match(function(actual) {
|
||||
return expectation === actual;
|
||||
}, "same(" + valueToString(expectation) + ")");
|
||||
};
|
||||
|
||||
match.in = function(arrayOfExpectations) {
|
||||
if (typeOf(arrayOfExpectations) !== "array") {
|
||||
throw new TypeError("array expected");
|
||||
}
|
||||
|
||||
return match(function(actual) {
|
||||
return some(arrayOfExpectations, function(expectation) {
|
||||
return expectation === actual;
|
||||
});
|
||||
}, "in(" + valueToString(arrayOfExpectations) + ")");
|
||||
};
|
||||
|
||||
match.typeOf = function(type) {
|
||||
assertType(type, "string", "type");
|
||||
return match(function(actual) {
|
||||
return typeOf(actual) === type;
|
||||
}, 'typeOf("' + type + '")');
|
||||
};
|
||||
|
||||
match.instanceOf = function(type) {
|
||||
if (
|
||||
typeof Symbol === "undefined" ||
|
||||
typeof Symbol.hasInstance === "undefined"
|
||||
) {
|
||||
assertType(type, "function", "type");
|
||||
} else {
|
||||
assertMethodExists(
|
||||
type,
|
||||
Symbol.hasInstance,
|
||||
"type",
|
||||
"[Symbol.hasInstance]"
|
||||
);
|
||||
}
|
||||
return match(function(actual) {
|
||||
return actual instanceof type;
|
||||
}, "instanceOf(" +
|
||||
(functionName(type) || Object.prototype.toString.call(type)) +
|
||||
")");
|
||||
};
|
||||
|
||||
function createPropertyMatcher(propertyTest, messagePrefix) {
|
||||
return function(property, value) {
|
||||
assertType(property, "string", "property");
|
||||
var onlyProperty = arguments.length === 1;
|
||||
var message = messagePrefix + '("' + property + '"';
|
||||
if (!onlyProperty) {
|
||||
message += ", " + valueToString(value);
|
||||
}
|
||||
message += ")";
|
||||
return match(function(actual) {
|
||||
if (
|
||||
actual === undefined ||
|
||||
actual === null ||
|
||||
!propertyTest(actual, property)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return onlyProperty || deepEqual(actual[property], value);
|
||||
}, message);
|
||||
};
|
||||
}
|
||||
|
||||
match.has = createPropertyMatcher(function(actual, property) {
|
||||
if (typeof actual === "object") {
|
||||
return property in actual;
|
||||
}
|
||||
return actual[property] !== undefined;
|
||||
}, "has");
|
||||
|
||||
match.hasOwn = createPropertyMatcher(function(actual, property) {
|
||||
return hasOwnProperty(actual, property);
|
||||
}, "hasOwn");
|
||||
|
||||
match.hasNested = function(property, value) {
|
||||
assertType(property, "string", "property");
|
||||
var onlyProperty = arguments.length === 1;
|
||||
var message = 'hasNested("' + property + '"';
|
||||
if (!onlyProperty) {
|
||||
message += ", " + valueToString(value);
|
||||
}
|
||||
message += ")";
|
||||
return match(function(actual) {
|
||||
if (
|
||||
actual === undefined ||
|
||||
actual === null ||
|
||||
get(actual, property) === undefined
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return onlyProperty || deepEqual(get(actual, property), value);
|
||||
}, message);
|
||||
};
|
||||
|
||||
match.every = function(predicate) {
|
||||
if (!isMatcher(predicate)) {
|
||||
throw new TypeError("Matcher expected");
|
||||
}
|
||||
|
||||
return match(function(actual) {
|
||||
if (typeOf(actual) === "object") {
|
||||
return every(Object.keys(actual), function(key) {
|
||||
return predicate.test(actual[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
!!actual &&
|
||||
typeOf(actual.forEach) === "function" &&
|
||||
every(actual, function(element) {
|
||||
return predicate.test(element);
|
||||
})
|
||||
);
|
||||
}, "every(" + predicate.message + ")");
|
||||
};
|
||||
|
||||
match.some = function(predicate) {
|
||||
if (!isMatcher(predicate)) {
|
||||
throw new TypeError("Matcher expected");
|
||||
}
|
||||
|
||||
return match(function(actual) {
|
||||
if (typeOf(actual) === "object") {
|
||||
return !every(Object.keys(actual), function(key) {
|
||||
return !predicate.test(actual[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
!!actual &&
|
||||
typeOf(actual.forEach) === "function" &&
|
||||
!every(actual, function(element) {
|
||||
return !predicate.test(element);
|
||||
})
|
||||
);
|
||||
}, "some(" + predicate.message + ")");
|
||||
};
|
||||
|
||||
match.array = match.typeOf("array");
|
||||
|
||||
match.array.deepEquals = function(expectation) {
|
||||
return match(function(actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.length === expectation.length;
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
sameLength &&
|
||||
every(actual, function(element, index) {
|
||||
var expected = expectation[index];
|
||||
return typeOf(expected) === "array" &&
|
||||
typeOf(element) === "array"
|
||||
? match.array.deepEquals(expected).test(element)
|
||||
: deepEqual(expected, element);
|
||||
})
|
||||
);
|
||||
}, "deepEquals([" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.array.startsWith = function(expectation) {
|
||||
return match(function(actual) {
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement, index) {
|
||||
return actual[index] === expectedElement;
|
||||
})
|
||||
);
|
||||
}, "startsWith([" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.array.endsWith = function(expectation) {
|
||||
return match(function(actual) {
|
||||
// This indicates the index in which we should start matching
|
||||
var offset = actual.length - expectation.length;
|
||||
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement, index) {
|
||||
return actual[offset + index] === expectedElement;
|
||||
})
|
||||
);
|
||||
}, "endsWith([" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.array.contains = function(expectation) {
|
||||
return match(function(actual) {
|
||||
return (
|
||||
typeOf(actual) === "array" &&
|
||||
every(expectation, function(expectedElement) {
|
||||
return arrayIndexOf(actual, expectedElement) !== -1;
|
||||
})
|
||||
);
|
||||
}, "contains([" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.map = match.typeOf("map");
|
||||
|
||||
match.map.deepEquals = function mapDeepEquals(expectation) {
|
||||
return match(function(actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.size === expectation.size;
|
||||
return (
|
||||
typeOf(actual) === "map" &&
|
||||
sameLength &&
|
||||
every(actual, function(element, key) {
|
||||
return expectation.has(key) && expectation.get(key) === element;
|
||||
})
|
||||
);
|
||||
}, "deepEquals(Map[" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.map.contains = function mapContains(expectation) {
|
||||
return match(function(actual) {
|
||||
return (
|
||||
typeOf(actual) === "map" &&
|
||||
every(expectation, function(element, key) {
|
||||
return actual.has(key) && actual.get(key) === element;
|
||||
})
|
||||
);
|
||||
}, "contains(Map[" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.set = match.typeOf("set");
|
||||
|
||||
match.set.deepEquals = function setDeepEquals(expectation) {
|
||||
return match(function(actual) {
|
||||
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
||||
var sameLength = actual.size === expectation.size;
|
||||
return (
|
||||
typeOf(actual) === "set" &&
|
||||
sameLength &&
|
||||
every(actual, function(element) {
|
||||
return expectation.has(element);
|
||||
})
|
||||
);
|
||||
}, "deepEquals(Set[" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.set.contains = function setContains(expectation) {
|
||||
return match(function(actual) {
|
||||
return (
|
||||
typeOf(actual) === "set" &&
|
||||
every(expectation, function(element) {
|
||||
return actual.has(element);
|
||||
})
|
||||
);
|
||||
}, "contains(Set[" + iterableToString(expectation) + "])");
|
||||
};
|
||||
|
||||
match.bool = match.typeOf("boolean");
|
||||
match.number = match.typeOf("number");
|
||||
match.string = match.typeOf("string");
|
||||
match.object = match.typeOf("object");
|
||||
match.func = match.typeOf("function");
|
||||
match.regexp = match.typeOf("regexp");
|
||||
match.date = match.typeOf("date");
|
||||
match.symbol = match.typeOf("symbol");
|
||||
|
||||
module.exports = match;
|
21
node_modules/@sinonjs/samsam/lib/samsam.js
generated
vendored
Normal file
21
node_modules/@sinonjs/samsam/lib/samsam.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
var identical = require("./identical");
|
||||
var isArguments = require("./is-arguments");
|
||||
var isElement = require("./is-element");
|
||||
var isNegZero = require("./is-neg-zero");
|
||||
var isSet = require("./is-set");
|
||||
var match = require("./match");
|
||||
var deepEqualCyclic = require("./deep-equal").use(match);
|
||||
var createMatcher = require("./matcher");
|
||||
|
||||
module.exports = {
|
||||
createMatcher: createMatcher,
|
||||
deepEqual: deepEqualCyclic,
|
||||
identical: identical,
|
||||
isArguments: isArguments,
|
||||
isElement: isElement,
|
||||
isNegZero: isNegZero,
|
||||
isSet: isSet,
|
||||
match: match
|
||||
};
|
Reference in New Issue
Block a user