builder

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package builder is main underlying package in the implementation of `verify.That()` and `require.That()`, with the `Builder` type providing the core functionality of the predicate builder. It used go generate and a code generator to forward individual predicates from `predicate/impl` onto the `Builder` type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureCallsite

func CaptureCallsite(b *Builder, skip int)

CaptureCallsite is intended to be called right after creation of a new builder, to capture the callsite location and allow better reporting.

func Evaluate

func Evaluate(b *Builder)

Evaluate is used to evaluate the predicate on the value and test context captured by the builder. Note that if no test context is set, no evaluation is performed.

func VerifyCompletness

func VerifyCompletness(b *Builder)

VerifyCompletness is used during test cleanup to report improperly constructed predicates that do not evaluate any condition. Note that if no test context is set, no verification is performed.

Types

type Builder

type Builder struct {
	Ctx []predicate.ContextValue
	// contains filtered or unexported fields
}

Builder is the main type of the package, used to build predicates by chaining calls to transformation builder functions followed by one final predicate builder function.

func New

func New(t predicate.T, value interface{}, required bool) *Builder

New returns a new predicate builder capture the given test context, value and the required flag indicating that a failed evaluation should fail the test.

func (*Builder) All

All tests if all values of a collection match the given predicate

func (*Builder) Any

Any tests if at least one values of a collection match the given predicate

func (*Builder) AsError added in v1.3.0

func (b *Builder) AsError(target interface{}) *Builder

AsError tests if a value is an error matching or wrapping the expected error (according to go 1.13 error.As()) and returns the unwrapped error for further evaluation.

func (*Builder) Capacity

func (b *Builder) Capacity() *Builder

Capacity is a transformation predicate that extract the capacity of a value for further evaluation. It applies to values of type Array, Slice and Channel.

func (*Builder) Contains

func (b *Builder) Contains(rhs interface{}) *predicate.Predicate

Contains tests if a sequence value contains the given sequence, and can be applied to strings, arrays and slices.

func (*Builder) EndsWith

func (b *Builder) EndsWith(rhs interface{}) *predicate.Predicate

EndsWith tests if a sequence value ends with the given sequence, and can be applied to strings, arrays and slices.

func (*Builder) Eq

func (b *Builder) Eq(rhs interface{}) *predicate.Predicate

Eq tests if a value is equatable and equal to the specified value.

func (*Builder) Eval

func (b *Builder) Eval(desc string, f predicate.TransformFunc) *Builder

Eval is an extension point allowing for the definition of custom transformation functions in a predicate chain

func (*Builder) Field

func (b *Builder) Field(keypath string) *Builder

Field is a transformation predicate that extract a field from a struct or a value from a map, identified by the given `keypath`. See value.Field() for more details.

func (*Builder) Ge

func (b *Builder) Ge(rhs interface{}) *predicate.Predicate

Ge tests if a value is greater than or equal to a reference value

func (*Builder) Gt

func (b *Builder) Gt(rhs interface{}) *predicate.Predicate

Gt tests if a value is strictly greater than a reference value

func (*Builder) HasPrefix

func (b *Builder) HasPrefix(rhs interface{}) *predicate.Predicate

HasPrefix tests if a sequence value starts with the given sequence, and can be applied to strings, arrays and slices.

func (*Builder) HasSuffix

func (b *Builder) HasSuffix(rhs interface{}) *predicate.Predicate

HasSuffix tests if a sequence value ends with the given sequence, and can be applied to strings, arrays and slices.

func (*Builder) Is

Is is an extension point allowing for the definition of a custom predicate function to evaluate a predicate chain

func (*Builder) IsCloseTo

func (b *Builder) IsCloseTo(rhs interface{}, tolerance float64) *predicate.Predicate

IsCloseTo tests if a value is within tolerance of a reference value

func (*Builder) IsDisjointSetFrom

func (b *Builder) IsDisjointSetFrom(rhs interface{}) *predicate.Predicate

IsDisjointSetFrom tests if two containers contain no common values

func (*Builder) IsEmpty

func (b *Builder) IsEmpty() *predicate.Predicate

IsEmpty tests if a sequence or container is empty.

func (*Builder) IsEqualSet

func (b *Builder) IsEqualSet(rhs interface{}) *predicate.Predicate

IsEqualSet tests if two containers contain the same set of values, independently of order.

func (*Builder) IsEqualTo

func (b *Builder) IsEqualTo(rhs interface{}) *predicate.Predicate

IsEqualTo tests if a value is equatable and equal to the specified value.

func (*Builder) IsError

func (b *Builder) IsError(expected any) *predicate.Predicate

IsError tests an error value to be either nil, a specific error according to `errors.Is()`, or an error whose message contains a specified string or matches a regexp. `.IsError("")` matches any error whose message contains an empty string, which is any non-nil error.

func (*Builder) IsFalse

func (b *Builder) IsFalse() *predicate.Predicate

IsFalse tests if a value is false

func (*Builder) IsGreaterOrEqualTo

func (b *Builder) IsGreaterOrEqualTo(rhs interface{}) *predicate.Predicate

IsGreaterOrEqualTo tests if a value is greater than or equal to a reference value

func (*Builder) IsGreaterThan

func (b *Builder) IsGreaterThan(rhs interface{}) *predicate.Predicate

IsGreaterThan tests if a value is strictly greater than a reference value

func (*Builder) IsLessOrEqualTo

func (b *Builder) IsLessOrEqualTo(rhs interface{}) *predicate.Predicate

IsLessOrEqualTo tests if a value is less than or equal to a reference value

func (*Builder) IsLessThan

func (b *Builder) IsLessThan(rhs interface{}) *predicate.Predicate

IsLessThan tests if a value is strictly less than a reference value

func (*Builder) IsNil

func (b *Builder) IsNil() *predicate.Predicate

IsNil tests if a value is either a nil literal or a nillable type set to nil

func (*Builder) IsNotEmpty

func (b *Builder) IsNotEmpty() *predicate.Predicate

IsNotEmpty tests if a sequence or container is not empty.

func (*Builder) IsNotEqualTo

func (b *Builder) IsNotEqualTo(rhs interface{}) *predicate.Predicate

IsNotEqualTo tests if a value is equatable but different from the specified value.

func (*Builder) IsNotNil

func (b *Builder) IsNotNil() *predicate.Predicate

IsNotNil tests if a value is neither a nil literal nor a nillable type set to nil; any value of a non-nillable type is considered not nil.

func (*Builder) IsSubsetOf

func (b *Builder) IsSubsetOf(rhs interface{}) *predicate.Predicate

IsSubsetOf tests if the value under test is a subset of the reference value. Both values must be containers and are treated as unordered sets.

func (*Builder) IsSupersetOf

func (b *Builder) IsSupersetOf(rhs interface{}) *predicate.Predicate

IsSupersetOf tests if the value under test is a superset of the reference value. Both values must be containers and are treated as unordered sets.

func (*Builder) IsTrue

func (b *Builder) IsTrue() *predicate.Predicate

IsTrue tests if a value is true

func (*Builder) Le

func (b *Builder) Le(rhs interface{}) *predicate.Predicate

Le tests if a value is less than or equal to a reference value

func (*Builder) Length

func (b *Builder) Length() *Builder

Length is a transformation predicate that extract the length of a value for further evaluation. It applies to values of type String, Array, Slice, Map, and Channel.

func (*Builder) Lt

func (b *Builder) Lt(rhs interface{}) *predicate.Predicate

Lt tests if a value is strictly less than a reference value

func (*Builder) MapKeys

func (b *Builder) MapKeys() *Builder

MapKeys is a transformation predicate that applies only to map values and extract its keys into an sequence for further evaluation. Note that the keys Will appear in no particular order.

func (*Builder) MapValues

func (b *Builder) MapValues() *Builder

MapValues is a transformation predicate that applies only to map values and extract its values into an sequence for further evaluation. Note that the values Will appear in no particular order.

func (*Builder) Matches

func (b *Builder) Matches(re string) *predicate.Predicate

Matches tests if a string matches a regular expression

func (*Builder) Ne

func (b *Builder) Ne(rhs interface{}) *predicate.Predicate

Ne tests if a value is equatable but different from the specified value.

func (*Builder) Panics

func (b *Builder) Panics() *predicate.Predicate

Panics verifies that the value under test is a callable function that panics. Special case using panic(nil) is considered an error because common recover() code will not catch it.

func (*Builder) PanicsAndRecoveredValue

func (b *Builder) PanicsAndRecoveredValue() *Builder

PanicsAndRecoveredValue verifies that the value under test is a callable function that panics, and captures the recovered value for further evalation.

func (*Builder) Passes

Passes evaluates a sub-expression predicate against the value.

func (*Builder) StartsWith

func (b *Builder) StartsWith(rhs interface{}) *predicate.Predicate

StartsWith tests if a sequence value starts with the given sequence, and can be applied to strings, arrays and slices.

func (*Builder) ToLower

func (b *Builder) ToLower() *Builder

ToLower is a transformation predicate that converts any value to a string representation using `%v` formatting option.

func (*Builder) ToString

func (b *Builder) ToString() *Builder

ToString is a transformation predicate that converts any value to a string representation using `%v` formatting option.

func (*Builder) ToUpper

func (b *Builder) ToUpper() *Builder

ToUpper is a transformation predicate that converts any value to a string representation using `%v` formatting option.

Jump to

Keyboard shortcuts

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