Merge pull request #124 from domenic/asserts

Initial assert helpers
This commit is contained in:
Brian Terlson 2014-12-01 19:53:51 -08:00
commit 3b49ec5108
2 changed files with 44 additions and 6 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);
};

View File

@ -8,10 +8,6 @@ description: thisArg should be bound to this if provided
var globalThis = this;
[1].find(function () {
if (this !== Array) {
$ERROR('#1: this !== Array');
}
if (this === globalThis) {
$ERROR('#2: this === globalThis. Should be Array');
}
assert.sameValue(this, Array, 'this should equal Array');
assert.notSameValue(this, globalThis, 'this should not equal globalThis');
}, Array);