Documentation
¶
Overview ¶
Package f contains the most useful type-safe fluent assertion functions.
It also provides the FailureMessage type which you can use for creating your own fluent assertions.
At last, you may embed a Fluent* type to extend it with additional assertion functions.
Index ¶
- type FailureMessage
- func (msg FailureMessage) Assert(t interface{ ... }, args ...any) bool
- func (msg FailureMessage) Assertf(t interface{ ... }, format string, args ...any) bool
- func (msg FailureMessage) Require(t interface{ ... }, args ...any) bool
- func (msg FailureMessage) Requiref(t interface{ ... }, format string, args ...any) bool
- type FluentComparable
- type FluentObj
- func (x FluentObj[T]) Check(fn func(got T) string) FailureMessage
- func (x FluentObj[T]) DeepEqual(want T, opts ...cmp.Option) FailureMessage
- func (x FluentObj[T]) NonZero() FailureMessage
- func (x FluentObj[T]) NotDeepEqual(want T, opts ...cmp.Option) FailureMessage
- func (x FluentObj[T]) Should(pred func(got T) bool) FailureMessage
- func (x FluentObj[T]) ShouldNot(fn func(got T) bool) FailureMessage
- func (x FluentObj[T]) Zero() FailureMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FailureMessage ¶ added in v0.2.0
type FailureMessage string
FailureMessage encapsulates failure message that can by emitted using objects compatible with the testing.TB interface.
func (FailureMessage) Assert ¶ added in v0.2.0
func (msg FailureMessage) Assert(t interface{ Error(args ...any) }, args ...any) bool
Assert calls t.Error if the failure message is not empty.
func (FailureMessage) Assertf ¶ added in v0.2.0
func (msg FailureMessage) Assertf(t interface { Errorf(format string, args ...any) }, format string, args ...any, ) bool
Assertf calls t.Errorf if the failure message is not empty.
type FluentComparable ¶ added in v0.2.0
type FluentComparable[T comparable] struct { FluentObj[T] }
FluentComparable encapsulates assertions for comparable object.
func Comparable ¶ added in v0.2.0
func Comparable[T comparable](got T) FluentComparable[T]
Comparable is used for testing a comparable object.
func (FluentComparable[T]) Equal ¶ added in v0.2.0
func (x FluentComparable[T]) Equal(want T) FailureMessage
Equal tests if the objects are equal using == operator.
func (FluentComparable[T]) NotEqual ¶ added in v0.2.0
func (x FluentComparable[T]) NotEqual(want T) FailureMessage
NotEqual tests if the objects are equal using == operator.
type FluentObj ¶ added in v0.2.0
type FluentObj[T any] struct { Got T }
FluentObj encapsulates assertions for any object.
func (FluentObj[T]) Check ¶ added in v0.2.0
func (x FluentObj[T]) Check(fn func(got T) string) FailureMessage
Check tests the object using the provided function
func (FluentObj[T]) DeepEqual ¶ added in v0.2.0
func (x FluentObj[T]) DeepEqual(want T, opts ...cmp.Option) FailureMessage
DeepEqual tests if the objects are deep equal using github.com/google/go-cmp/cmp.
func (FluentObj[T]) NonZero ¶ added in v0.2.0
func (x FluentObj[T]) NonZero() FailureMessage
NonZero tests if the object is a non-zero value.
func (FluentObj[T]) NotDeepEqual ¶ added in v0.2.0
func (x FluentObj[T]) NotDeepEqual(want T, opts ...cmp.Option) FailureMessage
NotDeepEqual tests if the objects are not deep equal using github.com/google/go-cmp/cmp.
func (FluentObj[T]) Should ¶ added in v0.2.0
func (x FluentObj[T]) Should(pred func(got T) bool) FailureMessage
Should tests if the object meets the predicate criteria.
func (FluentObj[T]) ShouldNot ¶ added in v0.2.0
func (x FluentObj[T]) ShouldNot(fn func(got T) bool) FailureMessage
ShouldNot tests if the object does not the predicate criteria.
func (FluentObj[T]) Zero ¶ added in v0.2.0
func (x FluentObj[T]) Zero() FailureMessage
Zero tests if the object is a zero value.