Skip to content

testing

import testing
FunctionSignatureDescription
assert_throws(fn() -> Unit, String) -> UnitAssert that a function throws an error containing the expected message.
assert_contains(String, String) -> UnitAssert that a string contains a substring.
assert_approx(Float, Float, Float) -> UnitAssert two floats are approximately equal within tolerance.
assert_gt(Int, Int) -> UnitAssert that a is greater than b.
assert_lt(Int, Int) -> UnitAssert that a is less than b.
assert_some(Option[String]) -> UnitAssert that an Option is some (not none).
assert_ok(Result[String, String]) -> UnitAssert that a Result is ok (not err).

testing.assert_throws(f: fn() -> Unit, expected: String) -> Unit

Section titled “testing.assert_throws(f: fn() -> Unit, expected: String) -> Unit”

Assert that a function throws an error containing the expected message.

testing.assert_throws(fn() => panic("oh no"), "oh no")

testing.assert_contains(haystack: String, needle: String) -> Unit

Section titled “testing.assert_contains(haystack: String, needle: String) -> Unit”

Assert that a string contains a substring.

testing.assert_contains("hello world", "world")

testing.assert_approx(a: Float, b: Float, tolerance: Float) -> Unit

Section titled “testing.assert_approx(a: Float, b: Float, tolerance: Float) -> Unit”

Assert two floats are approximately equal within tolerance.

testing.assert_approx(3.14, 3.14159, 0.01)

Assert that a is greater than b.

testing.assert_gt(10, 5)

Assert that a is less than b.

testing.assert_lt(3, 7)

testing.assert_some(opt: Option[String]) -> Unit

Section titled “testing.assert_some(opt: Option[String]) -> Unit”

Assert that an Option is some (not none).

testing.assert_some(some("value"))

testing.assert_ok(result: Result[String, String]) -> Unit

Section titled “testing.assert_ok(result: Result[String, String]) -> Unit”

Assert that a Result is ok (not err).

testing.assert_ok(ok("success"))