f

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 1 Imported by: 0

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

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.

func (FailureMessage) Require added in v0.2.0

func (msg FailureMessage) Require(t interface{ Fatal(args ...any) }, args ...any) bool

Require calls t.Fatal if the failure message is not empty.

func (FailureMessage) Requiref added in v0.2.0

func (msg FailureMessage) Requiref(t interface {
	Fatalf(format string, args ...any)
}, format string, args ...any,
) bool

Requiref calls t.Fatalf 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 Obj added in v0.2.0

func Obj[T any](got T) FluentObj[T]

Obj is used for testing 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.

Jump to

Keyboard shortcuts

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