-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for not-yet-written deepEqual()
- Loading branch information
James Halliday
committed
Jun 3, 2011
1 parent
d0dac52
commit 5267ae1
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
var assert = require('assert'); | ||
var traverse = require('traverse'); | ||
|
||
exports.deepDates = function () { | ||
assert.ok(traverse.deepEqual( | ||
{ d : new Date, x : [ 1, 2, 3 ] }, | ||
{ d : new Date, x : [ 1, 2, 3 ] }, | ||
'dates should be equal' | ||
)); | ||
|
||
var d0 = new Date; | ||
setTimeout(function () { | ||
assert.ok(traverse.deepEqual( | ||
{ d : d0, x : [ 1, 2, 3 ], }, | ||
{ d : new Date, x : [ 1, 2, 3 ] }, | ||
'microseconds should count in date equality' | ||
)); | ||
}, 5); | ||
}; | ||
|
||
exports.deepCircular = function () { | ||
var a = [1]; | ||
a.push(a); // a = [ 1, a ] | ||
|
||
var b = [1]; | ||
b.push(a); // b = [ 1, [ 1, a ] ] | ||
|
||
assert.ok( | ||
!traverse.deepEqual(a, b), | ||
'circular ref mount points count towards equality' | ||
); | ||
}; | ||
|
||
exports.deepInstances = function () { | ||
assert.ok(!traverse.deepEqual( | ||
[ new Boolean(false) ], [ false ], | ||
'boolean instances are not real booleans' | ||
)); | ||
|
||
assert.ok(traverse.deepEqual( | ||
[ new String('x') ], [ 'x' ], | ||
'string instances are not real strings' | ||
)); | ||
|
||
assert.ok(traverse.deepEqual( | ||
[ new Number(4) ], [ 4 ], | ||
'number instances are not real numbers' | ||
)); | ||
|
||
assert.ok(traverse.deepEqual( | ||
[ new Regexp('x') ] | ||
[ /x/ ], | ||
'regexp instances are real regexps' | ||
)); | ||
|
||
assert.ok(!traverse.deepEqual( | ||
[ new Regexp(/./) ] | ||
[ /../ ], | ||
'these regexps aren\'t the same' | ||
)); | ||
|
||
assert.ok(!traverse.deepEqual( | ||
[ function (x) { return x * 2 } ], | ||
[ function (x) { return x * 2 } ], | ||
'functions with the same .toString() aren\'t necessarily the same' | ||
)); | ||
|
||
var f = function (x) { return x * 2 }; | ||
assert.ok(!traverse.deepEqual( | ||
[ f ], [ f ], | ||
'these functions are actually equal' | ||
)); | ||
}; | ||
|
||
exports.deepEqual = function () { | ||
assert.ok(!traverse.deepEqual( | ||
[ 1, 2, 3 ], | ||
{ 0 : 1, 1 : 2, 2 : 3 }, | ||
'arrays are not objects' | ||
)); | ||
}; | ||
|
||
exports.deepArguments = function () { | ||
assert.ok(!traverse.deepEqual( | ||
[ 4, 5, 6 ], | ||
(function () { return arguments })(4, 5, 6), | ||
'arguments are not arrays' | ||
)); | ||
|
||
assert.ok(traverse.deepEqual( | ||
(function () { return arguments })(4, 5, 6), | ||
(function () { return arguments })(4, 5, 6), | ||
'arguments should equal' | ||
)); | ||
}; |