Skip to content

Commit

Permalink
tests all updated for the removal of deepEqual from the main lib
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 23, 2011
1 parent 9d5148a commit 9ebde92
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.
3 changes: 2 additions & 1 deletion test/circular.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var assert = require('assert');
var Traverse = require('traverse');
var deepEqual = require('./lib/deep_equal');
var util = require('util');

exports.circular = function () {
Expand Down Expand Up @@ -108,7 +109,7 @@ exports.circMapScrub = function () {
Object.keys(scrubbed).sort(),
[ 'a', 'b' ]
);
assert.ok(Traverse.deepEqual(scrubbed, { a : 1, b : 2 }));
assert.ok(deepEqual(scrubbed, { a : 1, b : 2 }));

assert.equal(obj.c, obj);
};
71 changes: 36 additions & 35 deletions test/equal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var assert = require('assert');
var traverse = require('traverse');
var deepEqual = require('./lib/deep_equal');

exports.deepDates = function () {
assert.ok(
traverse.deepEqual(
deepEqual(
{ d : new Date, x : [ 1, 2, 3 ] },
{ d : new Date, x : [ 1, 2, 3 ] }
),
Expand All @@ -13,7 +14,7 @@ exports.deepDates = function () {
var d0 = new Date;
setTimeout(function () {
assert.ok(
!traverse.deepEqual(
!deepEqual(
{ d : d0, x : [ 1, 2, 3 ], },
{ d : new Date, x : [ 1, 2, 3 ] }
),
Expand All @@ -30,53 +31,53 @@ exports.deepCircular = function () {
b.push(a); // b = [ 1, [ 1, *a ] ]

assert.ok(
!traverse.deepEqual(a, b),
!deepEqual(a, b),
'circular ref mount points count towards equality'
);

var c = [1];
c.push(c); // c = [ 1, *c ]
assert.ok(
traverse.deepEqual(a, c),
deepEqual(a, c),
'circular refs are structurally the same here'
);

var d = [1];
d.push(a); // c = [ 1, [ 1, *d ] ]
assert.ok(
traverse.deepEqual(b, d),
deepEqual(b, d),
'non-root circular ref structural comparison'
);
};

exports.deepInstances = function () {
assert.ok(
!traverse.deepEqual([ new Boolean(false) ], [ false ]),
!deepEqual([ new Boolean(false) ], [ false ]),
'boolean instances are not real booleans'
);

assert.ok(
!traverse.deepEqual([ new String('x') ], [ 'x' ]),
!deepEqual([ new String('x') ], [ 'x' ]),
'string instances are not real strings'
);

assert.ok(
!traverse.deepEqual([ new Number(4) ], [ 4 ]),
!deepEqual([ new Number(4) ], [ 4 ]),
'number instances are not real numbers'
);

assert.ok(
traverse.deepEqual([ new RegExp('x') ], [ /x/ ]),
deepEqual([ new RegExp('x') ], [ /x/ ]),
'regexp instances are real regexps'
);

assert.ok(
!traverse.deepEqual([ new RegExp(/./) ], [ /../ ]),
!deepEqual([ new RegExp(/./) ], [ /../ ]),
'these regexps aren\'t the same'
);

assert.ok(
!traverse.deepEqual(
!deepEqual(
[ function (x) { return x * 2 } ],
[ function (x) { return x * 2 } ]
),
Expand All @@ -85,47 +86,47 @@ exports.deepInstances = function () {

var f = function (x) { return x * 2 };
assert.ok(
traverse.deepEqual([ f ], [ f ]),
deepEqual([ f ], [ f ]),
'these functions are actually equal'
);
};

exports.deepEqual = function () {
assert.ok(
!traverse.deepEqual([ 1, 2, 3 ], { 0 : 1, 1 : 2, 2 : 3 }),
!deepEqual([ 1, 2, 3 ], { 0 : 1, 1 : 2, 2 : 3 }),
'arrays are not objects'
);
};

exports.falsy = function () {
assert.ok(
!traverse.deepEqual([ undefined ], [ null ]),
!deepEqual([ undefined ], [ null ]),
'null is not undefined!'
);

assert.ok(
!traverse.deepEqual([ null ], [ undefined ]),
!deepEqual([ null ], [ undefined ]),
'undefined is not null!'
);

assert.ok(
!traverse.deepEqual(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
'undefined is not null, however deeply!'
);

assert.ok(
!traverse.deepEqual(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
'null is not undefined, however deeply!'
);

assert.ok(
!traverse.deepEqual(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
Expand All @@ -143,18 +144,18 @@ exports.deletedArrayEqual = function () {
ys[3] = 4;

assert.ok(
traverse.deepEqual(xs, ys),
deepEqual(xs, ys),
'arrays with deleted elements are only equal to'
+ ' arrays with similarly deleted elements'
);

assert.ok(
!traverse.deepEqual(xs, [ 1, 2, undefined, 4 ]),
!deepEqual(xs, [ 1, 2, undefined, 4 ]),
'deleted array elements cannot be undefined'
);

assert.ok(
!traverse.deepEqual(xs, [ 1, 2, null, 4 ]),
!deepEqual(xs, [ 1, 2, null, 4 ]),
'deleted array elements cannot be null'
);
};
Expand All @@ -164,38 +165,38 @@ exports.deletedObjectEqual = function () {
delete obj.c;

assert.ok(
traverse.deepEqual(obj, { a : 1, b : 2 }),
deepEqual(obj, { a : 1, b : 2 }),
'deleted object elements should not show up'
);

assert.ok(
!traverse.deepEqual(obj, { a : 1, b : 2, c : undefined }),
!deepEqual(obj, { a : 1, b : 2, c : undefined }),
'deleted object elements are not undefined'
);

assert.ok(
!traverse.deepEqual(obj, { a : 1, b : 2, c : null }),
!deepEqual(obj, { a : 1, b : 2, c : null }),
'deleted object elements are not null'
);
};

exports.emptyKeyEqual = function () {
assert.ok(!traverse.deepEqual(
assert.ok(!deepEqual(
{ a : 1 }, { a : 1, '' : 55 }
));
};

exports.deepArguments = function () {
assert.ok(
!traverse.deepEqual(
!deepEqual(
[ 4, 5, 6 ],
(function () { return arguments })(4, 5, 6)
),
'arguments are not arrays'
);

assert.ok(
traverse.deepEqual(
deepEqual(
(function () { return arguments })(4, 5, 6),
(function () { return arguments })(4, 5, 6)
),
Expand All @@ -204,16 +205,16 @@ exports.deepArguments = function () {
};

exports.deepUn = function () {
assert.ok(!traverse.deepEqual({ a : 1, b : 2 }, undefined));
assert.ok(!traverse.deepEqual({ a : 1, b : 2 }, {}));
assert.ok(!traverse.deepEqual(undefined, { a : 1, b : 2 }));
assert.ok(!traverse.deepEqual({}, { a : 1, b : 2 }));
assert.ok(traverse.deepEqual(undefined, undefined));
assert.ok(traverse.deepEqual(null, null));
assert.ok(!traverse.deepEqual(undefined, null));
assert.ok(!deepEqual({ a : 1, b : 2 }, undefined));
assert.ok(!deepEqual({ a : 1, b : 2 }, {}));
assert.ok(!deepEqual(undefined, { a : 1, b : 2 }));
assert.ok(!deepEqual({}, { a : 1, b : 2 }));
assert.ok(deepEqual(undefined, undefined));
assert.ok(deepEqual(null, null));
assert.ok(!deepEqual(undefined, null));
};

exports.deepLevels = function () {
var xs = [ 1, 2, [ 3, 4, [ 5, 6 ] ] ];
assert.ok(!traverse.deepEqual(xs, []));
assert.ok(!deepEqual(xs, []));
};
31 changes: 16 additions & 15 deletions test/mutability.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var assert = require('assert');
var Traverse = require('traverse');
var deepEqual = require('./lib/deep_equal');

exports.mutate = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
Expand Down Expand Up @@ -112,15 +113,15 @@ exports.delete = function () {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
obj, { a : 1, c : [ 3, undefined ] }
));

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
obj, { a : 1, c : [ 3 ] }
));

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
obj, { a : 1, c : [ 3, null ] }
));
};
Expand All @@ -131,19 +132,19 @@ exports.deleteRedux = function () {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
obj, { a : 1, c : [ 3, undefined, 5 ] }
));

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
obj, { a : 1, c : [ 3 ,, 5 ] }
));

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
obj, { a : 1, c : [ 3, null, 5 ] }
));

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
obj, { a : 1, c : [ 3, 5 ] }
));
};
Expand All @@ -154,23 +155,23 @@ exports.deleteMap = function () {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4 ] }
));

var xs = [ 3, 4 ];
delete xs[1];

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
res, { a : 1, c : xs }
));

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
res, { a : 1, c : [ 3, ] }
));

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
res, { a : 1, c : [ 3 ] }
));
};
Expand All @@ -181,23 +182,23 @@ exports.deleteMapRedux = function () {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4, 5 ] }
));

var xs = [ 3, 4, 5 ];
delete xs[1];

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
res, { a : 1, c : xs }
));

assert.ok(!Traverse.deepEqual(
assert.ok(!deepEqual(
res, { a : 1, c : [ 3, 5 ] }
));

assert.ok(Traverse.deepEqual(
assert.ok(deepEqual(
res, { a : 1, c : [ 3 ,, 5 ] }
));
};
9 changes: 5 additions & 4 deletions test/super_deep.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
var assert = require('assert');
var traverse = require('traverse');
var deepEqual = require('./lib/deep_equal');

exports.super_deep = function () {
var util = require('util');
var a0 = make();
var a1 = make();
assert.ok(traverse.deepEqual(a0, a1));
assert.ok(deepEqual(a0, a1));

a0.c.d.moo = true;
assert.ok(!traverse.deepEqual(a0, a1));
assert.ok(!deepEqual(a0, a1));

a1.c.d.moo = true;
assert.ok(traverse.deepEqual(a0, a1));
assert.ok(deepEqual(a0, a1));

// TODO: this one
//a0.c.a = a1;
//assert.ok(!traverse.deepEqual(a0, a1));
//assert.ok(!deepEqual(a0, a1));
};

function make () {
Expand Down

0 comments on commit 9ebde92

Please sign in to comment.