Assert Module
Import using: use assert. All functions throw on failure with a descriptive error message.
Truthiness Assertions
assert.isTrue(condition, message)- Assert condition is truthy.assert.isFalse(condition, message)- Assert condition is falsy.
use assert
assert.isTrue(1 == 1, "math check")
assert.isTrue("hello", "string truthiness")
assert.isFalse(1 == 2, "inequality")
assert.isFalse(False, "false value")
# assert.isTrue(1 == 2, "impossible") # would throw
Value Assertions
assert.equal(a, b, message)- Assert a == b via value equality.assert.notEqual(a, b, message)- Assert a != b.assert.notNull(val, message)- Assert val is not Null.assert.isNullVal(val, message)- Assert val is Null.
use assert
assert.equal(5, 5, "five equals five")
assert.equal("hello", "hello", "string equality")
assert.notEqual(1, 2, "inequality")
assert.notNull("value", "myValue")
assert.isNullVal(Null, "myNull")
# assert.equal(1, 2, "cmp") # would throw
Type Assertions
assert.string(val, name)- Assert val is a String.assert.number(val, name)- Assert val is a Number.assert.boolean(val, name)- Assert val is a Boolean.assert.array(val, name)- Assert val is an Array.assert.map(val, name)- Assert val is a Map.assert.function(val, name)- Assert val is a Function (closure or native).assert.instance(val, name)- Assert val is a class Instance.assert.resource(val, name)- Assert val is a native Resource handle.assert.positive(val, name)- Assert val is a positive number (>= 0).
use assert
assert.string("hello", "myString")
assert.number(42, "myNum")
assert.boolean(True, "myBool")
assert.array([1, 2, 3], "myArray")
assert.map({"key": "val"}, "myMap")
assert.function(fn() end, "myFn")
assert.positive(5, "myVal")
# assert.positive(-1, "neg") # would throw