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 ¶
- func CaptureCallsite(b *Builder, skip int)
- func Evaluate(b *Builder)
- func VerifyCompletness(b *Builder)
- type Builder
- func (b *Builder) All(p *predicate.Predicate) *predicate.Predicate
- func (b *Builder) Any(p *predicate.Predicate) *predicate.Predicate
- func (b *Builder) AsError(target interface{}) *Builder
- func (b *Builder) Capacity() *Builder
- func (b *Builder) Contains(rhs interface{}) *predicate.Predicate
- func (b *Builder) EndsWith(rhs interface{}) *predicate.Predicate
- func (b *Builder) Eq(rhs interface{}) *predicate.Predicate
- func (b *Builder) Eval(desc string, f predicate.TransformFunc) *Builder
- func (b *Builder) Field(keypath string) *Builder
- func (b *Builder) Ge(rhs interface{}) *predicate.Predicate
- func (b *Builder) Gt(rhs interface{}) *predicate.Predicate
- func (b *Builder) HasPrefix(rhs interface{}) *predicate.Predicate
- func (b *Builder) HasSuffix(rhs interface{}) *predicate.Predicate
- func (b *Builder) Is(desc string, f predicate.PredicateFunc) *predicate.Predicate
- func (b *Builder) IsCloseTo(rhs interface{}, tolerance float64) *predicate.Predicate
- func (b *Builder) IsDisjointSetFrom(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsEmpty() *predicate.Predicate
- func (b *Builder) IsEqualSet(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsEqualTo(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsError(expected any) *predicate.Predicate
- func (b *Builder) IsFalse() *predicate.Predicate
- func (b *Builder) IsGreaterOrEqualTo(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsGreaterThan(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsLessOrEqualTo(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsLessThan(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsNil() *predicate.Predicate
- func (b *Builder) IsNotEmpty() *predicate.Predicate
- func (b *Builder) IsNotEqualTo(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsNotNil() *predicate.Predicate
- func (b *Builder) IsSubsetOf(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsSupersetOf(rhs interface{}) *predicate.Predicate
- func (b *Builder) IsTrue() *predicate.Predicate
- func (b *Builder) Le(rhs interface{}) *predicate.Predicate
- func (b *Builder) Length() *Builder
- func (b *Builder) Lt(rhs interface{}) *predicate.Predicate
- func (b *Builder) MapKeys() *Builder
- func (b *Builder) MapValues() *Builder
- func (b *Builder) Matches(re string) *predicate.Predicate
- func (b *Builder) Ne(rhs interface{}) *predicate.Predicate
- func (b *Builder) Panics() *predicate.Predicate
- func (b *Builder) PanicsAndRecoveredValue() *Builder
- func (b *Builder) Passes(p *predicate.Predicate) *predicate.Predicate
- func (b *Builder) StartsWith(rhs interface{}) *predicate.Predicate
- func (b *Builder) ToLower() *Builder
- func (b *Builder) ToString() *Builder
- func (b *Builder) ToUpper() *Builder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureCallsite ¶
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 ¶
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) AsError ¶ added in v1.3.0
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 ¶
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 ¶
Contains tests if a sequence value contains the given sequence, and can be applied to strings, arrays and slices.
func (*Builder) EndsWith ¶
EndsWith tests if a sequence value ends with the given sequence, and can be applied to strings, arrays and slices.
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 ¶
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) HasPrefix ¶
HasPrefix tests if a sequence value starts with the given sequence, and can be applied to strings, arrays and slices.
func (*Builder) HasSuffix ¶
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) IsDisjointSetFrom ¶
IsDisjointSetFrom tests if two containers contain no common values
func (*Builder) IsEqualSet ¶
IsEqualSet tests if two containers contain the same set of values, independently of order.
func (*Builder) IsEqualTo ¶
IsEqualTo tests if a value is equatable and equal to the specified value.
func (*Builder) IsError ¶
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) IsGreaterOrEqualTo ¶
IsGreaterOrEqualTo tests if a value is greater than or equal to a reference value
func (*Builder) IsGreaterThan ¶
IsGreaterThan tests if a value is strictly greater than a reference value
func (*Builder) IsLessOrEqualTo ¶
IsLessOrEqualTo tests if a value is less than or equal to a reference value
func (*Builder) IsLessThan ¶
IsLessThan tests if a value is strictly less than a reference value
func (*Builder) IsNil ¶
IsNil tests if a value is either a nil literal or a nillable type set to nil
func (*Builder) IsNotEmpty ¶
IsNotEmpty tests if a sequence or container is not empty.
func (*Builder) IsNotEqualTo ¶
IsNotEqualTo tests if a value is equatable but different from the specified value.
func (*Builder) IsNotNil ¶
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 ¶
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 ¶
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) Length ¶
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) MapKeys ¶
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 ¶
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) Panics ¶
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 ¶
PanicsAndRecoveredValue verifies that the value under test is a callable function that panics, and captures the recovered value for further evalation.
func (*Builder) StartsWith ¶
StartsWith tests if a sequence value starts with the given sequence, and can be applied to strings, arrays and slices.
func (*Builder) ToLower ¶
ToLower is a transformation predicate that converts any value to a string representation using `%v` formatting option.