Documentation
¶
Overview ¶
Package assert provides the `assert(cond, msg)` keyword and the `@assert` directive. The keyword yields a compiler.AssertExpr (evaluated later by the runtime with expr-lang); the directive appends expressions to meta["asserts"] and their source positions to `asserts.positions`. Core does not know what an assertion is: the parser dispatches the keyword through the bundle's Primaries, and the directive is handled by the bundle's Directive table.
Typical use:
@assert: result.status == "ok"
@assert {
result.count > 0
result.status == "ok"
}
{ score: 95 } -> assert(.score >= 50, "score too low")
Index ¶
Constants ¶
View Source
const ID = "assert"
Variables ¶
View Source
var Directive = compiler.Directive{
Name: "assert",
Example: `@assert: result != nil
@assert {
result.count > 0
result.status == "ok"
}
@assert: { result.count > 0, result.status == "ok" }`,
Handler: handleDirective,
}
Directive parses post-run assertions and appends their expressions to meta["asserts"]. It accepts a single expression, a multiline block, or a compact comma-separated list.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.