UNPKG

1.2 kBJavaScriptView Raw
1/* -*- Mode: js; js-indent-level: 2; -*- */
2/*
3 * Copyright 2011 Mozilla Foundation and contributors
4 * Licensed under the New BSD license. See LICENSE or:
5 * http://opensource.org/licenses/BSD-3-Clause
6 */
7define('test/source-map/assert', ['exports'], function (exports) {
8
9 let do_throw = function (msg) {
10 throw new Error(msg);
11 };
12
13 exports.init = function (throw_fn) {
14 do_throw = throw_fn;
15 };
16
17 exports.doesNotThrow = function (fn) {
18 try {
19 fn();
20 }
21 catch (e) {
22 do_throw(e.message);
23 }
24 };
25
26 exports.equal = function (actual, expected, msg) {
27 msg = msg || String(actual) + ' != ' + String(expected);
28 if (actual != expected) {
29 do_throw(msg);
30 }
31 };
32
33 exports.ok = function (val, msg) {
34 msg = msg || String(val) + ' is falsey';
35 if (!Boolean(val)) {
36 do_throw(msg);
37 }
38 };
39
40 exports.strictEqual = function (actual, expected, msg) {
41 msg = msg || String(actual) + ' !== ' + String(expected);
42 if (actual !== expected) {
43 do_throw(msg);
44 }
45 };
46
47 exports.throws = function (fn) {
48 try {
49 fn();
50 do_throw('Expected an error to be thrown, but it wasn\'t.');
51 }
52 catch (e) {
53 }
54 };
55
56});