about summary refs log tree commit diff stats
path: root/test/js/asserts.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/asserts.js')
-rw-r--r--test/js/asserts.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/js/asserts.js b/test/js/asserts.js
new file mode 100644
index 00000000..4d8fd62c
--- /dev/null
+++ b/test/js/asserts.js
@@ -0,0 +1,19 @@
+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);
+}