Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 1.13 KB

testing.md

File metadata and controls

59 lines (37 loc) · 1.13 KB

testing

Test assertions. import testing.

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

Assert that a string contains a substring.

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

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

Assert that a is greater than b.

testing.assert_gt(10, 5)

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

Assert that an Option is some (not none).

testing.assert_some(some("value"))

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

Assert that a Result is ok (not err).

testing.assert_ok(ok("success"))