diff --git a/lib/assert.js b/lib/assert.js index e44c3a1350f4d5..ad89f7bee35c7d 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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 diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js index 9a3b021f3ce447..6a64cbd5da5083 100644 --- a/test/simple/test-assert.js +++ b/test/simple/test-assert.js @@ -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'}));