Help us shape the future of Go! Take the 2026 Go Developer Survey

assert

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 6 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