|
| 1 | + |
| 2 | +// Taken from node/lib/assert.js |
| 3 | +exports.deepEqual = function (actual, expected) { |
| 4 | + if (actual === expected) { |
| 5 | + return true; |
| 6 | + |
| 7 | + } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { |
| 8 | + if (actual.length != expected.length) return false; |
| 9 | + |
| 10 | + for (var i = 0; i < actual.length; i++) { |
| 11 | + if (actual[i] !== expected[i]) return false; |
| 12 | + } |
| 13 | + return true; |
| 14 | + |
| 15 | + } else if (actual instanceof Date && expected instanceof Date) { |
| 16 | + return actual.getTime() === expected.getTime(); |
| 17 | + |
| 18 | + } else if (typeof actual != 'object' && typeof expected != 'object') { |
| 19 | + return actual == expected; |
| 20 | + |
| 21 | + } else { |
| 22 | + return objEquiv(actual, expected); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// Taken from node/lib/assert.js |
| 27 | +exports.notDeepEqual = function (actual, expected, message) { |
| 28 | + if (exports.deepEqual(actual, expected)) { |
| 29 | + fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// Taken from node/lib/assert.js |
| 34 | +function isUndefinedOrNull(value) { |
| 35 | + return value === null || value === undefined; |
| 36 | +} |
| 37 | + |
| 38 | +// Taken from node/lib/assert.js |
| 39 | +function isArguments(object) { |
| 40 | + return Object.prototype.toString.call(object) == '[object Arguments]'; |
| 41 | +} |
| 42 | + |
| 43 | +// Taken from node/lib/assert.js |
| 44 | +function objEquiv(a, b) { |
| 45 | + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) |
| 46 | + return false; |
| 47 | + if (a.prototype !== b.prototype) return false; |
| 48 | + if (isArguments(a)) { |
| 49 | + if (!isArguments(b)) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + a = pSlice.call(a); |
| 53 | + b = pSlice.call(b); |
| 54 | + return exports.deepEqual(a, b); |
| 55 | + } |
| 56 | + try { |
| 57 | + var ka = Object.keys(a), |
| 58 | + kb = Object.keys(b), |
| 59 | + key, i; |
| 60 | + } catch (e) { |
| 61 | + return false; |
| 62 | + } |
| 63 | + if (ka.length != kb.length) |
| 64 | + return false; |
| 65 | + ka.sort(); |
| 66 | + kb.sort(); |
| 67 | + for (i = ka.length - 1; i >= 0; i--) { |
| 68 | + if (ka[i] != kb[i]) |
| 69 | + return false; |
| 70 | + } |
| 71 | + for (i = ka.length - 1; i >= 0; i--) { |
| 72 | + key = ka[i]; |
| 73 | + if (!exports.deepEqual(a[key], b[key])) return false; |
| 74 | + } |
| 75 | + return true; |
| 76 | +} |
| 77 | + |
0 commit comments