diff options
Diffstat (limited to 'test/asserts.js')
-rw-r--r-- | test/asserts.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/asserts.js b/test/asserts.js new file mode 100644 index 00000000..6ef3033a --- /dev/null +++ b/test/asserts.js @@ -0,0 +1,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); +} |