Add initial assert helpers

Closes #110
This commit is contained in:
Domenic Denicola 2014-12-01 15:37:39 -05:00
parent bbeafbd3c6
commit 4bb8c027e4
1 changed files with 42 additions and 0 deletions

42
test/harness/assert.js Normal file
View File

@ -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);
};