hooks

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBoolean = errors.New("CmpHook(got, expected) failed")

Functions

This section is empty.

Types

type Info

type Info struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Info gathers all hooks information.

func NewInfo

func NewInfo() *Info

NewInfo returns a new instance of *Info.

func (*Info) AddCmpHooks

func (i *Info) AddCmpHooks(fns []interface{}) error

AddCmpHooks records new Cmp hooks using functions contained in "fns".

Each function in "fns" has to be a function with the following possible signatures:

func (A, A) bool
func (A, A) error

First arg is always "got", and second is always "expected".

A cannot be an interface. This retriction can be removed in the future, if really needed.

It returns an error if an item of "fns" is not a function or if its signature does not match the expected ones.

func (*Info) AddIgnoreUnexported added in v1.10.0

func (i *Info) AddIgnoreUnexported(ts []interface{}) error

AddIgnoreUnexported records types of values contained in "ts" as ignoring unexported struct fields. "ts" can also contain reflect.Type instances.

func (*Info) AddSmuggleHooks

func (i *Info) AddSmuggleHooks(fns []interface{}) error

AddSmuggleHooks records new Smuggle hooks using functions contained in "fns".

Each function in "fns" has to be a function with the following possible signatures:

func (A) B
func (A) (B, error)

A cannot be an interface. This retriction can be removed in the future, if really needed.

B can be an interface.

It returns an error if an item of "fns" is not a function or if its signature does not match the expected ones.

func (*Info) AddUseEqual added in v1.10.0

func (i *Info) AddUseEqual(ts []interface{}) error

AddUseEqual records types of values contained in "ts" as using Equal method. "ts" can also contain reflect.Type instances.

func (*Info) Cmp

func (i *Info) Cmp(got, expected reflect.Value) (bool, error)

Cmp checks if a Cmp hook exists matching "got" and "expected" types.

If no, it returns (false, nil)

If yes, it calls it and returns (true, nil) if it succeeds, (true, <an error>) if it fails. If the hook returns a false bool, the error returned is ErrBoolean.

func (*Info) Copy

func (i *Info) Copy() *Info

Copy returns a new instance of *Info with the same hooks as i. As a special case, if i is nil, returned instance is non-nil.

func (*Info) IgnoreUnexported added in v1.10.0

func (i *Info) IgnoreUnexported(t reflect.Type) bool

IgnoreUnexported returns true if the unexported fields of the type "t" have to be ignored.

func (*Info) Smuggle

func (i *Info) Smuggle(got *reflect.Value) (bool, error)

Smuggle checks if a Smuggle hook exists matching "*got" type.

If no, it returns (false, nil)

If yes, it calls it and returns (true, nil) if it succeeds, (true, <an error>) if it fails.

func (*Info) UseEqual added in v1.10.0

func (i *Info) UseEqual(t reflect.Type) bool

UseEqual returns true if the type "t" needs to use its Equal method to be compared.

Jump to

Keyboard shortcuts

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