assert: .deepEqual() support for RegExp objects

v0.7.4-release
Pedro Teixeira 2011-02-02 11:09:02 +00:00 committed by Ben Noordhuis
parent 213b8af2f6
commit a805012d6f
2 changed files with 13 additions and 3 deletions

View File

@ -170,12 +170,17 @@ function _deepEqual(actual, expected) {
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
// 7.3. Other pairs that do not both pass typeof value == 'object',
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source.
} else if (actual instanceof RegExp && expected instanceof RegExp) {
return actual.source === expected.source;
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (typeof actual != 'object' && typeof expected != 'object') {
return actual == expected;
// 7.4. For all other Object pairs, including Array objects, equivalence is
// 7.5 For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
// (although not necessarily the same order), equivalent values for every

View File

@ -82,13 +82,18 @@ assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000, 3, 14)),
'deepEqual date');
// 7.3
assert.doesNotThrow(makeBlock(a.deepEqual, /a/, /a/));
assert.throws(makeBlock(a.deepEqual, /ab/, /a/));
// 7.4
assert.doesNotThrow(makeBlock(a.deepEqual, 4, '4'), 'deepEqual == check');
assert.doesNotThrow(makeBlock(a.deepEqual, true, 1), 'deepEqual == check');
assert.throws(makeBlock(a.deepEqual, 4, '5'),
a.AssertionError,
'deepEqual == check');
// 7.4
// 7.5
// having the same number of owned properties && the same set of keys
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4}, {a: 4}));
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '2'}, {a: 4, b: '2'}));