expect

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FailedPredicateError added in v0.0.9

type FailedPredicateError struct {
	// The underlying error.
	Cause error
	// Stack of JSON field names that lead to the current expectation.
	FieldStack []string
}

A FailedPredicateError indicates that a predicate failed.

func CompareValues

func CompareValues(expected, actual any, exactJSON bool) []*FailedPredicateError

CompareValues compares an expected value to an actual value.

func (*FailedPredicateError) Error added in v0.0.9

func (e *FailedPredicateError) Error() string

func (*FailedPredicateError) FieldString added in v0.0.9

func (e *FailedPredicateError) FieldString() string

FieldString returns a dot-delimited string representation of the field stack.

func (*FailedPredicateError) PushField added in v0.0.9

func (e *FailedPredicateError) PushField(field string)

PushField pushes a field name onto the field stack.

func (*FailedPredicateError) Unwrap added in v0.0.9

func (e *FailedPredicateError) Unwrap() error

type Predicate

type Predicate func(any) error

A Predicate is a function that takes a test result value and possibly returns an error.

func Bool

func Bool(expected ...bool) Predicate

Bool creates a predicate requiring a value to be a bool, optionally matching against a set of values.

func Float added in v0.0.9

func Float(expected ...float64) Predicate

Float creates a predicate requiring a value to be an floating point number, optionally matching against a set of values.

func Int added in v0.0.9

func Int(expected ...int64) Predicate

Int creates a predicate requiring a value to be an integer, optionally matching against a set of values.

func Map

func Map(expected ...map[string]any) Predicate

Map creates a predicate requiring a value to be a map, optionally matching against a set of values.

func Pattern added in v0.0.9

func Pattern(regex string) Predicate

Pattern creates a predicate requiring a value to be a string that matches a regular expression, optionally matching against a set of values.

func Regex added in v0.0.9

func Regex(regex *regexp.Regexp) Predicate

Regex creates a predicate requiring a value to be a string that matches a regular expression, optionally matching against a set of values.

func Slice

func Slice(expected ...[]any) Predicate

Slice creates a predicate requiring a value to be a slice, optionally matching against a set of values.

func String

func String(expected ...string) Predicate

String creates a predicate requiring a value to be a string, optionally matching against a set of values.

func (Predicate) And added in v0.0.9

func (p Predicate) And(next Predicate) Predicate

And chains a new Predicate to run after the current Predicate if the current Predicate succeeds.

func (Predicate) Or added in v0.0.9

func (p Predicate) Or(next Predicate) Predicate

Or chains a new Predicate to run after the current Predicate if the current Predicate fails.

func (Predicate) Then

func (p Predicate) Then(next Predicate) Predicate

Then chains a new Predicate to run after the current Predicate.

Jump to

Keyboard shortcuts

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