12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // Copyright (C) 2017 Ecma International. All rights reserved.
- // This code is governed by the BSD license found in the LICENSE file.
- /*---
- description: |
- Collection of assertion functions used throughout test262
- ---*/
- function assert(mustBeTrue, message) {
- if (mustBeTrue === true) {
- return;
- }
- if (message === undefined) {
- message = 'Expected true but got ' + String(mustBeTrue);
- }
- $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 = '';
- } else {
- message += ' ';
- }
- 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 = '';
- } else {
- message += ' ';
- }
- message += 'Expected SameValue(«' + String(actual) + '», «' + String(unexpected) + '») to be false';
- $ERROR(message);
- };
- assert.throws = function (expectedErrorConstructor, func, message) {
- if (typeof func !== "function") {
- $ERROR('assert.throws requires two arguments: the error constructor ' +
- 'and a function to run');
- return;
- }
- if (message === undefined) {
- message = '';
- } else {
- message += ' ';
- }
- try {
- func();
- } catch (thrown) {
- if (typeof thrown !== 'object' || thrown === null) {
- message += 'Thrown value was not an object!';
- $ERROR(message);
- } else if (thrown.constructor !== expectedErrorConstructor) {
- message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
- $ERROR(message);
- }
- return;
- }
- message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
- $ERROR(message);
- };
|