assertion

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotated

type Annotated struct {
	Inner Assertion
	Msg   string
	Args  []any
}

Annotated wraps the given assertion with a message and format arguments.

func (Annotated) Check

func (a Annotated) Check(ctx context.Context) error

func (Annotated) String

func (a Annotated) String() string

type Ascending

type Ascending[V cmp.Ordered] struct {
	List []V
}

Ascending asserts that the given list is sorted in ascending order (each item is less or equal to the next item).

func (Ascending[V]) Check

func (a Ascending[V]) Check(ctx context.Context) error

func (Ascending[V]) String

func (a Ascending[V]) String() string

type Assertion

type Assertion interface {
	// String presents a readable version of the condition.
	String() string
	// Check runs the assertion.
	// This returns an error if the context is canceled or the assertion fails.
	Check(ctx context.Context) error
}

Assertion assertions are deferred as objects, to allow for Go-generics type-safe assertions, and to make user-provided assertions fit in easily.

type DeepEqual

type DeepEqual[V any] struct {
	Expected V
	Got      V
}

DeepEqual runs a deep-equal assertion

func (DeepEqual[V]) Check

func (s DeepEqual[V]) Check(ctx context.Context) error

func (DeepEqual[V]) String

func (s DeepEqual[V]) String() string

type Descending

type Descending[V cmp.Ordered] struct {
	List []V
}

Descending asserts that the given list is sorted in descending order (each item is greater or equal to the next item).

func (Descending[V]) Check

func (d Descending[V]) Check(ctx context.Context) error

func (Descending[V]) String

func (d Descending[V]) String() string

type Empty

type Empty[V any] struct {
	List []V
}

Empty asserts that the given list is empty.

func (Empty[V]) Check

func (e Empty[V]) Check(ctx context.Context) error

func (Empty[V]) String

func (e Empty[V]) String() string

type Equal

type Equal[V comparable] struct {
	Expected V
	Got      V
}

Equal runs a shallow-equal assertion

func (Equal[V]) Check

func (s Equal[V]) Check(ctx context.Context) error

func (Equal[V]) String

func (s Equal[V]) String() string

type ErrorIs

type ErrorIs struct {
	V      error
	Target error
}

ErrorIs asserts that the given error is linked to the target error.

func (ErrorIs) Check

func (e ErrorIs) Check(ctx context.Context) error

func (ErrorIs) String

func (e ErrorIs) String() string

type Eventually

type Eventually struct {
	Fn       func(ctx context.Context) error
	Tick     time.Duration
	Attempts uint
}

Eventually runs a function repeatedly until it succeeds or the context is done.

func (Eventually) Check

func (e Eventually) Check(ctx context.Context) error

func (Eventually) String

func (e Eventually) String() string

type Failed

type Failed struct{}

Failed is a pseudo-assertion that always fails, for placeholder usage.

func (Failed) Check

func (a Failed) Check(ctx context.Context) error

func (Failed) String

func (a Failed) String() string

type False

type False struct {
	V bool
}

False asserts that the given value is false.

func (False) Check

func (a False) Check(ctx context.Context) error

func (False) String

func (a False) String() string

type Greater

type Greater[V cmp.Ordered] struct {
	A, B V
}

func (Greater[V]) Check

func (g Greater[V]) Check(ctx context.Context) error

func (Greater[V]) String

func (g Greater[V]) String() string

type GreaterOrEq

type GreaterOrEq[V cmp.Ordered] struct {
	A, B V
}

func (GreaterOrEq[V]) Check

func (g GreaterOrEq[V]) Check(ctx context.Context) error

func (GreaterOrEq[V]) String

func (g GreaterOrEq[V]) String() string

type Implemented

type Implemented[T any] struct {
	V any
}

Implemented asserts that the given value implements the given interface.

func (Implemented[T]) Check

func (s Implemented[T]) Check(ctx context.Context) error

func (Implemented[T]) String

func (s Implemented[T]) String() string

type InDelta

type InDelta[V constraints.Number] struct {
	A     V
	B     V
	Delta V
}

InDelta asserts that the given values are within the given delta. The delta bound is inclusive. The delta must be positive. If the delta is zero, the values must be equal.

func (InDelta[V]) Check

func (s InDelta[V]) Check(ctx context.Context) error

func (InDelta[V]) String

func (s InDelta[V]) String() string

type InList

type InList[V comparable] struct {
	List []V
	Item V
}

InList asserts that V is contained in the list

func (InList[V]) Check

func (i InList[V]) Check(ctx context.Context) error

func (InList[V]) String

func (i InList[V]) String() string

type InMap

type InMap[K comparable, V any] struct {
	Key K
	Map map[K]V
}

InMap asserts that the Key is present in Map

func (InMap[K, V]) Check

func (i InMap[K, V]) Check(ctx context.Context) error

func (InMap[K, V]) String

func (i InMap[K, V]) String() string

type Len

type Len[V any] struct {
	List        []V
	ExpectedLen int
}

Len asserts that the given list has the given length.

func (Len[V]) Check

func (l Len[V]) Check(ctx context.Context) error

func (Len[V]) String

func (l Len[V]) String() string

type Less

type Less[V cmp.Ordered] struct {
	A, B V
}

func (Less[V]) Check

func (l Less[V]) Check(ctx context.Context) error

func (Less[V]) String

func (l Less[V]) String() string

type LessOrEq

type LessOrEq[V cmp.Ordered] struct {
	A, B V
}

func (LessOrEq[V]) Check

func (l LessOrEq[V]) Check(ctx context.Context) error

func (LessOrEq[V]) String

func (l LessOrEq[V]) String() string

type Negative

type Negative[V cmp.Ordered] struct {
	V V
}

func (Negative[V]) Check

func (n Negative[V]) Check(ctx context.Context) error

func (Negative[V]) String

func (n Negative[V]) String() string

type Nil

type Nil struct {
	V any
}

Nil asserts that the given value is nil, including interface values that contain nil pointers.

func (Nil) Check

func (n Nil) Check(ctx context.Context) error

func (Nil) String

func (n Nil) String() string

type NilPtr

type NilPtr[V any] struct {
	P *V
}

NilPtr asserts that the given pointer is nil.

func (NilPtr[V]) Check

func (n NilPtr[V]) Check(ctx context.Context) error

func (NilPtr[V]) String

func (n NilPtr[V]) String() string

type NoError

type NoError struct {
	V error
}

NoError asserts that the given error is nil.

func (NoError) Check

func (e NoError) Check(ctx context.Context) error

func (NoError) String

func (e NoError) String() string

type NoPanic

type NoPanic struct {
	Fn func()
}

NoPanic asserts that the given function does not panic.

func (NoPanic) Check

func (a NoPanic) Check(ctx context.Context) error

func (NoPanic) String

func (a NoPanic) String() string

type NonEmpty

type NonEmpty[V any] struct {
	List []V
}

NonEmpty asserts that the given list is not empty.

func (NonEmpty[V]) Check

func (n NonEmpty[V]) Check(ctx context.Context) error

func (NonEmpty[V]) String

func (n NonEmpty[V]) String() string

type NonNil

type NonNil struct {
	V any
}

NonNil asserts that the given value is not nil, including interface values that contain nil pointers.

func (NonNil) Check

func (n NonNil) Check(ctx context.Context) error

func (NonNil) String

func (n NonNil) String() string

type NonNilPtr

type NonNilPtr[V any] struct {
	P *V
}

NonNilPtr asserts that the given pointer is not nil.

func (NonNilPtr[V]) Check

func (n NonNilPtr[V]) Check(ctx context.Context) error

func (NonNilPtr[V]) String

func (n NonNilPtr[V]) String() string

type Not

type Not struct {
	Inner Assertion
}

Not asserts that the given assertion fails. For better readability and error reporting, use the assertion-specific inverse assertions instead.

func (Not) Check

func (a Not) Check(ctx context.Context) error

func (Not) String

func (a Not) String() string

type NotDeepEqual

type NotDeepEqual[V any] struct {
	Unexpected V
	Got        V
}

NotDeepEqual runs a deep-not-equal assertion

func (NotDeepEqual[V]) Check

func (s NotDeepEqual[V]) Check(ctx context.Context) error

func (NotDeepEqual[V]) String

func (s NotDeepEqual[V]) String() string

type NotEqual

type NotEqual[V comparable] struct {
	Unexpected V
	Got        V
}

NotEqual runs a shallow-not-equal assertion

func (NotEqual[V]) Check

func (s NotEqual[V]) Check(ctx context.Context) error

func (NotEqual[V]) String

func (s NotEqual[V]) String() string

type NotZero

type NotZero[V comparable] struct {
	V V
}

func (NotZero[V]) Check

func (n NotZero[V]) Check(ctx context.Context) error

func (NotZero[V]) String

func (n NotZero[V]) String() string

type OfType

type OfType[T any] struct {
	V any
}

OfType asserts that the given value is of the given type. The reflect type of T is compared to the reflect type of the given value.

func (OfType[T]) Check

func (s OfType[T]) Check(ctx context.Context) error

func (OfType[T]) String

func (s OfType[T]) String() string

type Panic

type Panic struct {
	Fn func()
}

Panic asserts that the given function panics.

func (Panic) Check

func (a Panic) Check(ctx context.Context) error

func (Panic) String

func (a Panic) String() string

type Passed

type Passed struct{}

Passed is a pseudo-assertion that always passes, for placeholder usage.

func (Passed) Check

func (a Passed) Check(ctx context.Context) error

func (Passed) String

func (a Passed) String() string

type Positive

type Positive[V cmp.Ordered] struct {
	V V
}

func (Positive[V]) Check

func (p Positive[V]) Check(ctx context.Context) error

func (Positive[V]) String

func (p Positive[V]) String() string

type Prefix

type Prefix struct {
	V      string
	Prefix string
}

Prefix asserts that V is prefixed by Prefix

func (Prefix) Check

func (s Prefix) Check(ctx context.Context) error

func (Prefix) String

func (s Prefix) String() string

type Same

type Same[V any] struct {
	Expected *V
	Got      *V
}

Same asserts that the pointers are pointing to the same thing.

func (Same[V]) Check

func (s Same[V]) Check(ctx context.Context) error

func (Same[V]) String

func (s Same[V]) String() string

type Substring

type Substring struct {
	V   string
	Sub string
}

Substring asserts that V contains Sub

func (Substring) Check

func (s Substring) Check(ctx context.Context) error

func (Substring) String

func (s Substring) String() string

type Suffix

type Suffix struct {
	V      string
	Suffix string
}

Suffix asserts that V is suffixed by Suffix

func (Suffix) Check

func (s Suffix) Check(ctx context.Context) error

func (Suffix) String

func (s Suffix) String() string

type True

type True struct {
	V bool
}

True asserts that the given value is true.

func (True) Check

func (a True) Check(ctx context.Context) error

func (True) String

func (a True) String() string

type Zero

type Zero[V comparable] struct {
	V V
}

func (Zero[V]) Check

func (z Zero[V]) Check(ctx context.Context) error

func (Zero[V]) String

func (z Zero[V]) String() string

Jump to

Keyboard shortcuts

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