blob: 6ed766e9415f6fa2796eebb230f2c27b4e174f39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
var assert = {
sameValue: assertEq,
notSameValue(a, b, msg) {
try {
assertEq(a, b);
throw "equal"
} catch (e) {
if (e === "equal")
throw new Error("Assertion failed: expected different values, got " + a);
}
},
throws(ctor, f) {
var fullmsg;
try {
f();
} catch (exc) {
if (exc instanceof ctor)
return;
fullmsg = "Assertion failed: expected exception " + ctor.name + ", got " + exc;
}
if (fullmsg === undefined)
fullmsg = "Assertion failed: expected exception " + ctor.name + ", no exception thrown";
if (msg !== undefined)
fullmsg += " - " + msg;
throw new Error(fullmsg);
}
}
|