about summary refs log tree commit diff stats
path: root/test/asserts.js
blob: 6ef3033a8cba0554645e077aa9c2bf0c0206a21e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function assert(x, msg) {
	const mymsg = msg ? ": " + msg : "";
	if (!x)
		throw new TypeError("Assertion failed" + mymsg);
}

function assert_throws(expr, error) {
	try {
		eval(expr);
	} catch (e) {
		if (e instanceof Error)
			return;
	}
	throw new TypeError("Assertion failed");
}

function assert_equals(a, b) {
	assert(a === b, "Expected " + b + " but got " + a);
}

function assert_instanceof(a, b) {
	assert(a instanceof b, a + " not an instance of " + b);
}