A fluent assertion library for MoonBit
moon add moonrockz/expectimport {
"moonrockz/expect",
} for "test"test "basic assertions" {
// Equality
@expect.expect(1 + 1).to_equal(2)
@expect.expect(1).to_not_equal(2)
// Booleans
@expect.expect(true).to_be_true()
@expect.expect(false).to_be_false()
// Options
@expect.expect(Some(42)).to_be_some()
@expect.expect((None : Int?)).to_be_none()
// Strings
@expect.expect("hello world").to_contain("world")
@expect.expect("").to_be_empty_string()
@expect.expect("abc").to_have_length_string(3)
// Arrays
@expect.expect([1, 2, 3]).to_contain_element(2)
@expect.expect(([] : Array[Int])).to_be_empty()
@expect.expect([1, 2, 3]).to_have_length(3)
}struct Point {
x : Int
y : Int
} derive(Eq, Debug)pub struct Expectation[T] {
actual : T
}fn[T : Eq + Debug] Expectation::to_contain_element(self : Expectation[Array[T]], element : T) -> Unit raisefn[T : Debug] Expectation::to_have_length(self : Expectation[Array[T]], expected : Int) -> Unit raise