assert

package
v0.68.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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,
	OpaqueBlock: true,
}

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

func Bundle

func Bundle(_ map[string]string) compiler.Bundle

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL