From: Maciej MaƂecki Date: Mon, 19 Dec 2011 22:28:42 +0000 (+0100) Subject: assert: test `RegExp`'s properties when checking for equality X-Git-Tag: v0.7.0~89 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5c7532e5b3fad40a50696e43fc2ff066af7037c3;p=platform%2Fupstream%2Fnodejs.git assert: test `RegExp`'s properties when checking for equality Previous code ignored the fact that `/a/ != /a/g`. Test case included. --- diff --git a/lib/assert.js b/lib/assert.js index ad89f7b..7c013eb 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -171,9 +171,14 @@ function _deepEqual(actual, expected) { return actual.getTime() === expected.getTime(); // 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. + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). } else if (actual instanceof RegExp && expected instanceof RegExp) { - return actual.source === expected.source; + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; // 7.4. Other pairs that do not both pass typeof value == 'object', // equivalence is determined by ==. diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js index 6a64cbd..1c68c44 100644 --- a/test/simple/test-assert.js +++ b/test/simple/test-assert.js @@ -83,7 +83,19 @@ assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000, 3, 14)), // 7.3 assert.doesNotThrow(makeBlock(a.deepEqual, /a/, /a/)); +assert.doesNotThrow(makeBlock(a.deepEqual, /a/g, /a/g)); +assert.doesNotThrow(makeBlock(a.deepEqual, /a/i, /a/i)); +assert.doesNotThrow(makeBlock(a.deepEqual, /a/m, /a/m)); +assert.doesNotThrow(makeBlock(a.deepEqual, /a/igm, /a/igm)); assert.throws(makeBlock(a.deepEqual, /ab/, /a/)); +assert.throws(makeBlock(a.deepEqual, /a/g, /a/)); +assert.throws(makeBlock(a.deepEqual, /a/i, /a/)); +assert.throws(makeBlock(a.deepEqual, /a/m, /a/)); +assert.throws(makeBlock(a.deepEqual, /a/igm, /a/im)); + +var re1 = /a/; +re1.lastIndex = 3; +assert.throws(makeBlock(a.deepEqual, re1, /a/)); // 7.4