assert

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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, including optional failure-message expressions); 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