Skip to content

Commit

Permalink
refactored to use stored methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fearphage committed Jul 11, 2018
1 parent 76acd6b commit a54020d
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 64 deletions.
7 changes: 4 additions & 3 deletions lib/sinon/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var functionName = require("./util/core/function-name");
var nextTick = require("./util/core/next-tick");
var valueToString = require("./util/core/value-to-string");

var concat = require("./var/concat");
var join = require("./var/join");
var slice = require("./var/slice");
var arrayProto = require("./var/array");
var concat = arrayProto.concat;
var join = arrayProto.join;
var slice = arrayProto.slice;
var useLeftMostCallback = -1;
var useRightMostCallback = -2;

Expand Down
7 changes: 4 additions & 3 deletions lib/sinon/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ var functionName = require("./util/core/function-name");
var sinonFormat = require("./util/core/format");
var valueToString = require("./util/core/value-to-string");

var concat = require("./var/concat");
var slice = require("./var/slice");
var filter = require("./var/filter");
var arrayProto = require("./var/array");
var concat = arrayProto.concat;
var filter = arrayProto.filter;
var slice = arrayProto.slice;

function throwYieldError(proxy, text, args) {
var msg = functionName(proxy) + text;
Expand Down
3 changes: 2 additions & 1 deletion lib/sinon/collect-own-methods.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";

var objectProto = require("./var/object");
var walk = require("./util/core/walk");
var getPropertyDescriptor = require("./util/core/get-property-descriptor");

function collectMethod(methods, object, prop, propOwner) {
if (
typeof getPropertyDescriptor(propOwner, prop).value === "function" &&
object.hasOwnProperty(prop)
objectProto.hasOwnProperty(object, prop)
) {
methods.push(object[prop]);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/sinon/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var every = require("./util/core/every");
var functionName = require("./util/core/function-name");
var get = require("lodash.get");
var iterableToString = require("./util/core/iterable-to-string");
var objectProto = require("./var/object");
var typeOf = require("./util/core/typeOf");
var valueToString = require("./util/core/value-to-string");

var indexOf = Array.prototype.indexOf;
var indexOf = require("./var/array").indexOf;

function assertType(value, type, name) {
var actual = typeOf(value);
Expand All @@ -31,7 +32,7 @@ var matcher = {
};

function isMatcher(object) {
return matcher.isPrototypeOf(object);
return objectProto.isPrototypeOf(matcher, object);
}

function matchObject(expectation, actual) {
Expand Down Expand Up @@ -325,7 +326,7 @@ match.array.endsWith = function (expectation) {
match.array.contains = function (expectation) {
return match(function (actual) {
return typeOf(actual) === "array" && every(expectation, function (expectedElement) {
return indexOf.call(actual, expectedElement) !== -1;
return indexOf(actual, expectedElement) !== -1;
});
}, "contains([" + iterableToString(expectation) + "])");
};
Expand Down
9 changes: 5 additions & 4 deletions lib/sinon/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ var match = require("./match");
var deepEqual = require("./util/core/deep-equal").use(match);
var wrapMethod = require("./util/core/wrap-method");

var filter = require("./var/filter");
var push = require("./var/push");
var slice = require("./var/slice");
var unshift = require("./var/unshift");
var arrayProto = require("./var/array");
var filter = arrayProto.filter;
var push = arrayProto.push;
var slice = arrayProto.slice;
var unshift = arrayProto.unshift;

function mock(object) {
if (!object || typeof object === "string") {
Expand Down
2 changes: 1 addition & 1 deletion lib/sinon/util/core/order-by-first-call.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var sort = require("../../var/sort");
var sort = require("../../var/array").sort;

module.exports = function orderByFirstCall(spies) {
return sort(spies, function (a, b) {
Expand Down
4 changes: 3 additions & 1 deletion lib/sinon/var/array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

module.exports = [];
var copyPrototype = require("./copy-prototype");

module.exports = copyPrototype(Array.prototype);
5 changes: 0 additions & 5 deletions lib/sinon/var/call.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sinon/var/concat.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sinon/var/filter.js

This file was deleted.

4 changes: 3 additions & 1 deletion lib/sinon/var/function.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

module.exports = function noop() {};
var copyPrototype = require("./copy-prototype");

module.exports = copyPrototype(Function.prototype);
6 changes: 0 additions & 6 deletions lib/sinon/var/join.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/sinon/var/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var copyPrototype = require("./copy-prototype");

module.exports = copyPrototype(Object.prototype);
6 changes: 0 additions & 6 deletions lib/sinon/var/push.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sinon/var/slice.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sinon/var/sort.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sinon/var/unshift.js

This file was deleted.

0 comments on commit a54020d

Please sign in to comment.