Documentation
¶
Overview ¶
Package operators evaluates assertion operators (equals, contains, greaterThan, between, ...) against an extracted actual value and the assertion's expected value.
One Comparator per operator type, dispatched through a registry: comparators maps an OperatorType to a func(actual, expected any) (bool, error). Compare looks up and applies it; IsKnown reports whether a type is registered (used to reject a bad operator at flow-decode rather than at execution). Adding an operator = register a Comparator (built-ins in registry.go; external ones via Register from an init()) — no switch to edit.
Comparisons are deliberately lenient: string operators compare stringified forms (so 200 == "200") and numeric operators coerce via toFloat. This mirrors the wire, which delivers expected values as strings. It is a tested contract, not type-aware equality — see Compare and registry_test.go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
func Compare(operatorType OperatorType, actual, expected any) (bool, error)
Compare applies the registered comparator for operatorType, returning an error when the operator is unknown.
Coercion contract: comparisons are lenient. equals/notEquals/contains and the other string operators compare the stringified forms (toString), so the integer 200 and the string "200" are equal; the numeric operators (greaterThan/between/...) coerce both sides via toFloat. This matches the wire, which delivers expected values as strings. It is a deliberate, tested contract, not type-aware equality.
func IsKnown ¶
func IsKnown(operatorType OperatorType) bool
IsKnown reports whether operatorType has a registered comparator. Callers use it to reject an unknown operator at flow-decode time (mirroring the extractor registry) instead of failing deep inside Compare during execution.
func Register ¶
func Register(operatorType OperatorType, comparator Comparator)
Register adds (or overrides) the comparator for an operator type. Call from an init() so a new operator becomes available without editing the dispatch core.
Types ¶
type Comparator ¶
Comparator applies an operator to an extracted actual value and the assertion's expected value. Comparisons are lenient (stringify/coerce) because the wire delivers expected values as strings while extracted actuals are typed (e.g. an int statusCode vs the string "200").
type OperatorType ¶
type OperatorType string
OperatorType is the wire identifier for an assertion operator. Each value has one registered Comparator (see registry.go); the constants below are the built-ins.
const ( OperatorTypeEquals OperatorType = "equals" OperatorTypeNotEquals OperatorType = "notEquals" OperatorTypeContains OperatorType = "contains" OperatorTypeNotContains OperatorType = "notContains" OperatorTypeStartsWith OperatorType = "startsWith" OperatorTypeEndsWith OperatorType = "endsWith" OperatorTypeRegex OperatorType = "regex" OperatorTypeEmpty OperatorType = "empty" OperatorTypeNotEmpty OperatorType = "notEmpty" OperatorTypeGreaterThan OperatorType = "greaterThan" OperatorTypeLessThan OperatorType = "lessThan" OperatorTypeGreaterThanOrEqual OperatorType = "greaterThanOrEqual" OperatorTypeLessThanOrEqual OperatorType = "lessThanOrEqual" OperatorTypeBetween OperatorType = "between" )