diff --git a/lib/sinon/call.js b/lib/sinon/call.js index d1088adf8..ed613baca 100644 --- a/lib/sinon/call.js +++ b/lib/sinon/call.js @@ -2,7 +2,7 @@ var arrayProto = require("@sinonjs/commons").prototypes.array; var sinonMatch = require("./match"); -var deepEqual = require("./util/core/deep-equal").use(sinonMatch); +var deepEqual = require("@sinonjs/samsam").deepEqual; var functionName = require("@sinonjs/commons").functionName; var sinonFormat = require("./util/core/format"); var valueToString = require("@sinonjs/commons").valueToString; @@ -41,7 +41,7 @@ var callProto = { return reduce( calledWithArgs, function(prev, arg, i) { - return prev && deepEqual(arg, self.args[i]); + return prev && deepEqual(self.args[i], arg); }, true ); @@ -79,7 +79,7 @@ var callProto = { }, returned: function returned(value) { - return deepEqual(value, this.returnValue); + return deepEqual(this.returnValue, value); }, threw: function threw(error) { diff --git a/lib/sinon/match.js b/lib/sinon/match.js index 43e3aa9de..2422f8b32 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -1,428 +1,5 @@ "use strict"; -var arrayProto = require("@sinonjs/commons").prototypes.array; -var deepEqual = require("./util/core/deep-equal").use(match); // eslint-disable-line no-use-before-define -var every = require("./util/core/every"); -var functionName = require("@sinonjs/commons").functionName; -var get = require("lodash.get"); -var iterableToString = require("./util/core/iterable-to-string"); -var objectProto = require("@sinonjs/commons").prototypes.object; -var stringProto = require("@sinonjs/commons").prototypes.string; -var typeOf = require("./util/core/typeOf"); -var valueToString = require("@sinonjs/commons").valueToString; +var samsam = require("@sinonjs/samsam"); -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 (typeof value[method] === "undefined") { - 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(expectation, actual) { - 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(exp, act)) { - return false; - } - } else if (!deepEqual(exp, act)) { - 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(expectation, actual); - }; - 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 (type in TYPE_MAP) { - TYPE_MAP[type](m, expectation, message); - } else { - m.test = function(actual) { - return deepEqual(expectation, actual); - }; - } - - if (!m.message) { - m.message = "match(" + valueToString(expectation) + ")"; - } - - return m; -} - -matcher.or = function(m2) { - var matcher2 = m2; - if (!arguments.length) { - throw new TypeError("Matcher expected"); - } else if (!isMatcher(m2)) { - matcher2 = match(m2); - } - var m1 = this; - var or = Object.create(matcher); - or.test = function(actual) { - return m1.test(actual) || matcher2.test(actual); - }; - or.message = m1.message + ".or(" + matcher2.message + ")"; - return or; -}; - -matcher.and = function(m2) { - var matcher2 = m2; - if (!arguments.length) { - throw new TypeError("Matcher expected"); - } else if (!isMatcher(m2)) { - matcher2 = match(m2); - } - var m1 = this; - var and = Object.create(matcher); - and.test = function(actual) { - return m1.test(actual) && matcher2.test(actual); - }; - and.message = m1.message + ".and(" + matcher2.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 Boolean(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 (!Array.isArray(arrayOfExpectations)) { - 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(value, actual[property]); - }, 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(value, get(actual, property)); - }, 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 ( - Boolean(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 ( - Boolean(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) { - return expectation[index] === 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; +module.exports = samsam.createMatcher; diff --git a/lib/sinon/mock-expectation.js b/lib/sinon/mock-expectation.js index aa168b97d..b644098b3 100644 --- a/lib/sinon/mock-expectation.js +++ b/lib/sinon/mock-expectation.js @@ -8,7 +8,7 @@ var extend = require("./util/core/extend"); var match = require("./match"); var stub = require("./stub"); var assert = require("./assert"); -var deepEqual = require("./util/core/deep-equal").use(match); +var deepEqual = require("@sinonjs/samsam").deepEqual; var format = require("./util/core/format"); var valueToString = require("@sinonjs/commons").valueToString; @@ -201,7 +201,7 @@ var mockExpectation = { ); } - if (!deepEqual(expectedArgument, args[i])) { + if (!deepEqual(args[i], expectedArgument)) { mockExpectation.fail( this.method + " received wrong arguments " + @@ -246,7 +246,7 @@ var mockExpectation = { return false; } - if (!deepEqual(expectedArgument, _args[i])) { + if (!deepEqual(_args[i], expectedArgument)) { return false; } diff --git a/lib/sinon/mock.js b/lib/sinon/mock.js index 5164ec832..f4c36b80d 100644 --- a/lib/sinon/mock.js +++ b/lib/sinon/mock.js @@ -4,8 +4,7 @@ var arrayProto = require("@sinonjs/commons").prototypes.array; var mockExpectation = require("./mock-expectation"); var spyCallToString = require("./call").toString; var extend = require("./util/core/extend"); -var match = require("./match"); -var deepEqual = require("./util/core/deep-equal").use(match); +var deepEqual = require("@sinonjs/samsam").deepEqual; var wrapMethod = require("./util/core/wrap-method"); var usePromiseLibrary = require("./util/core/use-promise-library"); diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 56372c67f..584dc8f9b 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -6,8 +6,7 @@ var extend = require("./util/core/extend"); var functionName = require("@sinonjs/commons").functionName; var functionToString = require("./util/core/function-to-string"); var getPropertyDescriptor = require("./util/core/get-property-descriptor"); -var sinonMatch = require("./match"); -var deepEqual = require("./util/core/deep-equal").use(sinonMatch); +var deepEqual = require("@sinonjs/samsam").deepEqual; var isEsModule = require("./util/core/is-es-module"); var spyCall = require("./call"); var wrapMethod = require("./util/core/wrap-method"); @@ -431,7 +430,7 @@ var spyApi = { matches: function(args, strict) { var margs = this.matchingArguments; - if (margs.length <= args.length && deepEqual(margs, slice(args, 0, margs.length))) { + if (margs.length <= args.length && deepEqual(slice(args, 0, margs.length), margs)) { return !strict || margs.length === args.length; } diff --git a/lib/sinon/util/core/deep-equal.js b/lib/sinon/util/core/deep-equal.js deleted file mode 100644 index 1922d5759..000000000 --- a/lib/sinon/util/core/deep-equal.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; - -var arrayProto = require("@sinonjs/commons").prototypes.array; -var toString = require("@sinonjs/commons").prototypes.object.toString; -var samsam = require("@sinonjs/samsam"); - -var every = arrayProto.every; -var join = arrayProto.join; -var sort = arrayProto.sort; - -function isReallyNaN(val) { - // eslint-disable-next-line no-self-compare - return val !== val; -} - -var deepEqual = (module.exports = function deepEqual(a, b, matcher) { - if (a === null && b === null) { - return true; - } - - if (typeof a !== "object" || typeof b !== "object") { - return (isReallyNaN(a) && isReallyNaN(b)) || a === b; - } - - if (a instanceof Error && b instanceof Error) { - return a === b; - } - - if (toString(a) !== toString(b)) { - return false; - } - - if (join(sort(Object.keys(a))) !== join(sort(Object.keys(b)))) { - return false; - } - - if (samsam.deepEqual(a, b)) { - return true; - } - - if (matcher) { - var keys = Object.keys(a); - var allKeysMatch = every(keys, function(key) { - return matcher(a[key], b[key]); - }); - - return keys.length > 0 && allKeysMatch; - } - - return false; -}); - -deepEqual.use = function(match) { - return function deepEqual$matcher(a, b) { - // 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.isMatcher(a)) { - if (match.isMatcher(b)) { - return a === b; - } - return a.test(b); - } - - return deepEqual(a, b, deepEqual$matcher); - }; -}; diff --git a/lib/sinon/util/core/every.js b/lib/sinon/util/core/every.js deleted file mode 100644 index f4614ef08..000000000 --- a/lib/sinon/util/core/every.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; - -// This is an `every` implementation that works for all iterables -module.exports = function every(obj, fn) { - var pass = true; - - try { - /* eslint-disable-next-line local-rules/no-prototype-methods */ - obj.forEach(function() { - if (!fn.apply(this, arguments)) { - // Throwing an error is the only way to break `forEach` - throw new Error(); - } - }); - } catch (e) { - pass = false; - } - - return pass; -}; diff --git a/lib/sinon/util/core/iterable-to-string.js b/lib/sinon/util/core/iterable-to-string.js deleted file mode 100644 index 2bf2357af..000000000 --- a/lib/sinon/util/core/iterable-to-string.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; - -var slice = require("@sinonjs/commons").prototypes.string.slice; -var typeOf = require("./typeOf"); - -module.exports = function iterableToString(obj) { - var representation = ""; - - function stringify(item) { - return typeof item === "string" ? "'" + item + "'" : String(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); -}; diff --git a/lib/sinon/util/core/typeOf.js b/lib/sinon/util/core/typeOf.js deleted file mode 100644 index e8d2ff75c..000000000 --- a/lib/sinon/util/core/typeOf.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -var type = require("type-detect"); - -module.exports = function typeOf(value) { - return type(value).toLowerCase(); -}; diff --git a/package-lock.json b/package-lock.json index 1b6c013f2..0da47127d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -187,21 +187,11 @@ } }, "@sinonjs/formatio": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.0.0.tgz", - "integrity": "sha512-vdjoYLDptCgvtJs57ULshak3iJe4NW3sJ3g36xVDGff5AE8P30S6A093EIEPjdi2noGhfuNOEkbxt3J3awFW1w==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.1.0.tgz", + "integrity": "sha512-ZAR2bPHOl4Xg6eklUGpsdiIJ4+J1SNag1DHHrG/73Uz/nVwXqjgUtRPLoS+aVyieN9cSbc0E4LsU984tWcDyNg==", "requires": { - "@sinonjs/samsam": "2.1.0" - }, - "dependencies": { - "@sinonjs/samsam": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.0.tgz", - "integrity": "sha512-5x2kFgJYupaF1ns/RmharQ90lQkd2ELS8A9X0ymkAAdemYHGtI2KiUHG8nX2WU0T1qgnOU5YMqnBM2V7NUanNw==", - "requires": { - "array-from": "^2.1.1" - } - } + "@sinonjs/samsam": "^2 || ^3" } }, "@sinonjs/referee": { @@ -218,12 +208,35 @@ "lodash.includes": "^4.3.0", "lodash.isarguments": "^3.1.0", "object-assign": "^4.1.1" + }, + "dependencies": { + "@sinonjs/samsam": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.3.tgz", + "integrity": "sha512-8zNeBkSKhU9a5cRNbpCKau2WWPfan+Q2zDlcXvXyhn9EsMqgYs4qzo0XHNVlXC6ABQL8fT6nV+zzo5RTHJzyXw==", + "dev": true + } } }, "@sinonjs/samsam": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.2.tgz", - "integrity": "sha512-ZwTHAlC9akprWDinwEPD4kOuwaYZlyMwVJIANsKNC3QVp0AHB04m7RnB4eqeWfgmxw8MGTzS9uMaw93Z3QcZbw==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.0.0.tgz", + "integrity": "sha512-HYQiZXtwBEtjLPPZ3/X/wiKFNY9fMrJEjdSvYfeUEgTmppNVuDVQKIYGNTdM08sHkfes17KaE0RLOwHSbA0/ww==", + "requires": { + "@sinonjs/commons": "1.0.2", + "array-from": "^2.1.1", + "lodash.get": "4.4.2" + }, + "dependencies": { + "@sinonjs/commons": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.0.2.tgz", + "integrity": "sha512-WR3dlgqJP4QNrLC4iXN/5/2WaLQQ0VijOOkmflqFGVJ6wLEpbSjo7c0ZeGIdtY8Crk7xBBp87sM6+Mkerz7alw==", + "requires": { + "type-detect": "4.0.8" + } + } + } }, "@types/estree": { "version": "0.0.39", @@ -5491,6 +5504,22 @@ "text-encoding": "^0.6.4" }, "dependencies": { + "@sinonjs/formatio": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.0.0.tgz", + "integrity": "sha512-vdjoYLDptCgvtJs57ULshak3iJe4NW3sJ3g36xVDGff5AE8P30S6A093EIEPjdi2noGhfuNOEkbxt3J3awFW1w==", + "requires": { + "@sinonjs/samsam": "2.1.0" + } + }, + "@sinonjs/samsam": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.0.tgz", + "integrity": "sha512-5x2kFgJYupaF1ns/RmharQ90lQkd2ELS8A9X0ymkAAdemYHGtI2KiUHG8nX2WU0T1qgnOU5YMqnBM2V7NUanNw==", + "requires": { + "array-from": "^2.1.1" + } + }, "lolex": { "version": "2.7.5", "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.5.tgz", diff --git a/package.json b/package.json index 106db8ef2..8b805b330 100644 --- a/package.json +++ b/package.json @@ -56,14 +56,12 @@ }, "dependencies": { "@sinonjs/commons": "^1.2.0", - "@sinonjs/formatio": "^3.0.0", - "@sinonjs/samsam": "^2.1.2", + "@sinonjs/formatio": "^3.1.0", + "@sinonjs/samsam": "^3.0.0", "diff": "^3.5.0", - "lodash.get": "^4.4.2", "lolex": "^3.0.0", "nise": "^1.4.6", - "supports-color": "^5.5.0", - "type-detect": "^4.0.8" + "supports-color": "^5.5.0" }, "devDependencies": { "@babel/core": "^7.1.6", diff --git a/test/util/core/deep-equal-test.js b/test/util/core/deep-equal-test.js index 34e3f8e16..03f34e299 100644 --- a/test/util/core/deep-equal-test.js +++ b/test/util/core/deep-equal-test.js @@ -1,7 +1,7 @@ "use strict"; var referee = require("@sinonjs/referee"); -var deepEqual = require("../../../lib/sinon/util/core/deep-equal"); +var deepEqual = require("@sinonjs/samsam").deepEqual; var match = require("../../../lib/sinon/match"); var createSpy = require("../../../lib/sinon/spy").create; var assert = referee.assert; @@ -330,23 +330,19 @@ describe("util/core/deepEqual", function() { }); it("does not run matchers against each other when using a matcher library", function() { - var matchDeepEqual = deepEqual.use(match); - var spyA = createSpy(); var matchA = match(spyA); var spyB = createSpy(); var matchB = match(spyB); - matchDeepEqual(matchA, matchB); + deepEqual(matchA, matchB); assert.equals(spyA.callCount, 0); assert.equals(spyB.callCount, 0); }); it("strictly compares instances when passed two matchers and using a matcher library", function() { - var matchDeepEqual = deepEqual.use(match); - var matchA = match(function a() { return "a"; }); @@ -357,8 +353,8 @@ describe("util/core/deepEqual", function() { var duplicateA = matchA; - assert(matchDeepEqual(matchA, duplicateA)); - assert.isFalse(matchDeepEqual(matchA, matchB)); + assert(deepEqual(matchA, duplicateA)); + assert.isFalse(deepEqual(matchA, matchB)); }); it("handles shallow cyclic objects", function() { @@ -392,8 +388,6 @@ describe("util/core/deepEqual", function() { }); it("handles cyclic objects when a matcher provided", function() { - var matchDeepEqual = deepEqual.use(match); - var a = { foo: "bar" }; @@ -404,6 +398,6 @@ describe("util/core/deepEqual", function() { }; b.cyclicKeyName = b; - assert(matchDeepEqual(a, b)); + assert(deepEqual(a, b)); }); }); diff --git a/test/util/core/every-test.js b/test/util/core/every-test.js deleted file mode 100644 index 70fafca83..000000000 --- a/test/util/core/every-test.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; - -var referee = require("@sinonjs/referee"); -var createSpy = require("../../../lib/sinon/spy"); -var every = require("../../../lib/sinon/util/core/every"); -var assert = referee.assert; - -describe("util/core/every", function() { - it("returns true when the callback function returns true for every element in an iterable", function() { - var obj = [true, true, true, true]; - var allTrue = every(obj, function(val) { - return val; - }); - - assert(allTrue); - }); - - it("returns false when the callback function returns false for any element in an iterable", function() { - var obj = [true, true, true, false]; - var result = every(obj, function(val) { - return val; - }); - - assert.isFalse(result); - }); - - it("calls the given callback once for each item in an iterable until it returns false", function() { - var iterableOne = [true, true, true, true]; - var iterableTwo = [true, true, false, true]; - var callback = createSpy(function(val) { - return val; - }); - - every(iterableOne, callback); - assert.equals(callback.callCount, 4); - - callback.resetHistory(); - - every(iterableTwo, callback); - assert.equals(callback.callCount, 3); - }); -}); diff --git a/test/util/core/iterable-to-string-test.js b/test/util/core/iterable-to-string-test.js deleted file mode 100644 index ce64737ab..000000000 --- a/test/util/core/iterable-to-string-test.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; - -var referee = require("@sinonjs/referee"); -var iterableToString = require("../../../lib/sinon/util/core/iterable-to-string"); -var assert = referee.assert; - -describe("util/core/iterable-to-string", function() { - it("returns an String representation of Array objects", function() { - var arr = [1, "one", true, undefined, null]; - var expected = "1,'one',true,undefined,null"; - - assert.equals(iterableToString(arr), expected); - }); - - if (typeof Map === "function") { - it("returns an String representation of Map objects", function() { - var map = new Map(); - map.set(1, 1); - map.set("one", "one"); - map.set(true, true); - map.set(undefined, undefined); - map.set(null, null); - var expected = "[1,1],['one','one'],[true,true],[undefined,undefined],[null,null]"; - - assert.equals(iterableToString(map), expected); - }); - } - - if (typeof Set === "function") { - it("returns an String representation of Set objects", function() { - var set = new Set(); - set.add(1); - set.add("one"); - set.add(true); - set.add(undefined); - set.add(null); - - var expected = "1,'one',true,undefined,null"; - - assert.equals(iterableToString(set), expected); - }); - } -}); diff --git a/test/util/core/typeOf-test.js b/test/util/core/typeOf-test.js deleted file mode 100644 index 888da7f99..000000000 --- a/test/util/core/typeOf-test.js +++ /dev/null @@ -1,52 +0,0 @@ -"use strict"; - -var referee = require("@sinonjs/referee"); -var sinonTypeOf = require("../../../lib/sinon/util/core/typeOf"); -var assert = referee.assert; - -describe("typeOf", function() { - it("returns boolean", function() { - assert.equals(sinonTypeOf(false), "boolean"); - }); - - it("returns string", function() { - assert.equals(sinonTypeOf("Sinon.JS"), "string"); - }); - - it("returns number", function() { - assert.equals(sinonTypeOf(123), "number"); - }); - - it("returns object", function() { - assert.equals(sinonTypeOf({}), "object"); - }); - - it("returns function", function() { - assert.equals( - sinonTypeOf(function() { - return; - }), - "function" - ); - }); - - it("returns undefined", function() { - assert.equals(sinonTypeOf(undefined), "undefined"); - }); - - it("returns null", function() { - assert.equals(sinonTypeOf(null), "null"); - }); - - it("returns array", function() { - assert.equals(sinonTypeOf([]), "array"); - }); - - it("returns regexp", function() { - assert.equals(sinonTypeOf(/.*/), "regexp"); - }); - - it("returns date", function() { - assert.equals(sinonTypeOf(new Date()), "date"); - }); -});