testing
import testingFunctions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
assert_throws | (fn() -> Unit, String) -> Unit | Assert that a function throws an error containing the expected message. |
assert_contains | (String, String) -> Unit | Assert that a string contains a substring. |
assert_approx | (Float, Float, Float) -> Unit | Assert two floats are approximately equal within tolerance. |
assert_gt | (Int, Int) -> Unit | Assert that a is greater than b. |
assert_lt | (Int, Int) -> Unit | Assert that a is less than b. |
assert_some | (Option[String]) -> Unit | Assert that an Option is some (not none). |
assert_ok | (Result[String, String]) -> Unit | Assert that a Result is ok (not err). |
Reference
Section titled “Reference”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)testing.assert_gt(a: Int, b: Int) -> Unit
Section titled “testing.assert_gt(a: Int, b: Int) -> Unit”Assert that a is greater than b.
testing.assert_gt(10, 5)testing.assert_lt(a: Int, b: Int) -> Unit
Section titled “testing.assert_lt(a: Int, b: Int) -> Unit”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"))