diff --git a/test/harness/assert.js b/test/harness/assert.js new file mode 100644 index 0000000000..1d9d4a48f2 --- /dev/null +++ b/test/harness/assert.js @@ -0,0 +1,42 @@ +function assert(mustBeTrue, message) { + if (mustBeTrue === true) { + return; + } + + if (message === undefined) { + message = 'Expected true but got ' + String(truthy); + } + $ERROR(message); +} + +assert._isSameValue = function (a, b) { + if (a === b) { + // Handle +/-0 vs. -/+0 + return a !== 0 || 1 / a === 1 / b; + } + + // Handle NaN vs. NaN + return a !== a && b !== b; +}; + +assert.sameValue = function (actual, expected, message) { + if (assert._isSameValue(actual, expected)) { + return; + } + + if (message === undefined) { + message = 'Expected SameValue(' + String(actual) + ', ' + String(expected) + ') to be true'; + } + $ERROR(message); +}; + +assert.notSameValue = function (actual, unexpected, message) { + if (!assert._isSameValue(actual, unexpected)) { + return; + } + + if (message === undefined) { + message = 'Expected SameValue(' + String(actual) + ', ' + String(unexpected) + ') to be false'; + } + $ERROR(message); +};