| 1 | export function assert(actual, expected, message) { |
| 2 | if (arguments.length === 1) |
| 3 | expected = true; |
| 4 | |
| 5 | if (typeof actual === typeof expected) { |
| 6 | if (actual === expected) { |
| 7 | if (actual !== 0 || (1 / actual) === (1 / expected)) |
| 8 | return; |
| 9 | } |
| 10 | if (typeof actual === 'number') { |
| 11 | if (isNaN(actual) && isNaN(expected)) |
| 12 | return; |
| 13 | } |
| 14 | if (typeof actual === 'object') { |
| 15 | if (actual !== null && expected !== null |
| 16 | && actual.constructor === expected.constructor |
| 17 | && actual.toString() === expected.toString()) |
| 18 | return; |
| 19 | } |
| 20 | } |
| 21 | throw Error("assertion failed: got |" + actual + "|" + |
| 22 | ", expected |" + expected + "|" + |
| 23 | (message ? " (" + message + ")" : "")); |
| 24 | } |
| 25 | |
| 26 | export function assertThrows(err, func) |
| 27 | { |