assert

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 6 Imported by: 0 modules, 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 parses and evaluates `# @assert` expressions of the form `<selector> <op> <value>` or `<selector> exists` / `<selector> not exists`.

Index

Constants

This section is empty.

Variables

View Source
var Operators = []string{"==", "!=", "<=", ">=", "<", ">", "contains", "matches", "startsWith", "endsWith", "exists", "not exists"}

Operators lists the supported comparison operators.

Functions

func ParseNumber

func ParseNumber(s string) (*big.Rat, bool)

ParseNumber reads a decimal number exactly, so large integers such as 9007199254740993 keep their value instead of rounding through float64, and values beyond float64's range (1e1000) still compare as numbers. Words, Inf, NaN, fractions like 1/2 and numbers with more than 4096 digits or an exponent beyond ±4096 are not numbers here and compare as text.

Types

type Expr

type Expr struct {
	Selector string
	Op       string
	Value    string // raw right-hand side; may contain {{placeholders}}
}

Expr is a parsed assertion.

func Parse

func Parse(expr string) (Expr, error)

Parse splits an expression into selector, operator and value.

type Result

type Result struct {
	Expr     string `json:"expr"`
	Pass     bool   `json:"pass"`
	Actual   string `json:"actual,omitempty"`
	Expected string `json:"expected,omitempty"`
	Error    string `json:"error,omitempty"`
}

Result is the outcome of evaluating one assertion.

func Eval

func Eval(e Expr, expected string, resp *selector.Response) Result

Eval evaluates a parsed expression against a response. expected is the right-hand side after template rendering.

Jump to

Keyboard shortcuts

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