Skip to content

Commit

Permalink
Adding tests and support for comparing arrow functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 15, 2014
1 parent fb03635 commit 57c719d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var ObjectPrototype = Object.prototype;
var toString = ObjectPrototype.toString;
var has = ObjectPrototype.hasOwnProperty;
var isGenerator = require('is-generator-function');
var isArrowFunction = require('is-arrow-function');

var getPrototypeOf = Object.getPrototypeOf;
if (!getPrototypeOf) {
Expand Down Expand Up @@ -74,6 +75,10 @@ module.exports = function isEqual(value, other) {
var otherIsGen = isGenerator(other);
if (valueIsGen !== otherIsGen) { return false; }

var valueIsArrow = isArrowFunction(value);
var otherIsArrow = isArrowFunction(other);
if (valueIsArrow !== otherIsArrow) { return false; }

return isEqual(String(value), String(other));
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"equality"
],
"dependencies": {
"is-arrow-function": "~2.0.0",
"is-generator-function": "~1.0.0"
},
"devDependencies": {
"tape": "~3.0.3",
"covert": "1.0.0",
"jscs": "~1.8.1",
"foreach": "~2.0.5",
"make-arrow-function": "~1.0.0",
"make-generator-function": "~1.0.0"
},
"testling": {
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var test = require('tape');
var isEqual = require('./');
var hasGeneratorSupport = typeof require('make-generator-function') === 'function';
var arrowFunctions = require('make-arrow-function').list();
var hasArrowFunctionSupport = arrowFunctions.length > 0;

var forEach = require('foreach');
var copyFunction = function (fn) {
Expand Down Expand Up @@ -161,6 +163,15 @@ test('functions', function (t) {
st.end();
});

t.test('arrow functions', { skip: !hasArrowFunctionSupport }, function (st) {
forEach(arrowFunctions, function (fn) {
st.notOk(isEqual(fnNoSpace, fn), fn + ' not equal to ' + fnNoSpace);
st.ok(isEqual(fn, fn), fn + ' equal to itself');
st.ok(isEqual(fn, copyFunction(fn)), fn + ' equal to copyFunction(fn)');
});
st.end();
});

t.end();
});

Expand Down

0 comments on commit 57c719d

Please sign in to comment.