A powerful quotation meta programming library that hacks MoonBit's snapshot test system, allowing you to customize `moon test` behavior with automatic source file updates and enhanced testing capabilities.
{
"deps": {
"illusory0x0/inspect": "*"
}
}moon add illusory0x0/inspect///|
test "basic usage example" {
TestBlock::define(fn(t) {
t.inspect(1 + 1, expected="2")
t.inspect("hello".length(), expected="5")
t.inspect([1, 2, 3].length(), expected="3")
})
}moon testILLU_MOON_UPDATE=true moon test///|
test "multiple assertions" {
TestBlock::define(fn(t) {
let data = [1, 2, 3, 4, 5]
t.inspect(data.length(), expected="5")
t.inspect(data[0], expected="1")
t.inspect(data.filter(fn(x) { x > 3 }), expected="[4, 5]")
})
}///|
struct Point {
x : Int
y : Int
} derive(Show)
///|
test "struct testing" {
TestBlock::define(fn(t) {
let p = Point::{ x: 10, y: 20 }
t.inspect(p, expected="{x: 10, y: 20}")
t.inspect(p.x + p.y, expected="30")
})
}///|
test "math that auto-corrects" {
TestBlock::define(fn(t) {
// Write the wrong expected value initially
t.inspect(fibonacci(10), expected="55")
// Run with ILLU_MOON_UPDATE=true and it becomes:
// t.inspect(fibonacci(10), expected="55")
})
}
///|
fn fibonacci(n : Int) -> Int {
if n <= 1 {
n
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}///|
test "api response format" {
TestBlock::define(fn(t) {
let response : Map[String, String] = { "status": "ok", "data": "numbers" }
t.inspect(
response.to_string(),
expected="{\"status\": \"ok\", \"data\": \"numbers\"}",
) // Auto-fills!
})
}type TestBlockInstall
Download zipA powerful quotation meta programming library that hacks MoonBit's snapshot test system, allowing you to customize `moon test` behavior with automatic source file updates and enhanced testing capabilities.