cmp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareErr

func CompareErr(t *testing.T, got error, want error, opts ...Option)

func Diff

func Diff(expected any, got any, options ...Option) string

Diff compares expected and got recursively and returns a human-readable report of their differences, or the empty string if they are equal. Each difference is reported as the path to the differing value followed by the expected (-) and got (+) values.

Values whose type has a method of the form Equal(T) bool are compared with that method. Comparing unexported struct fields or non-nil function values panics; skip them with IgnoreFields or compare a containing type with a Comparer option or an Equal method.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures how Diff and CompareErr compare values.

func Comparer

func Comparer(function any) Option

Comparer returns an Option that compares values with function, which must have the form func(T, T) bool. It applies wherever both compared values are assignable to T, taking precedence over any Equal method and the built-in comparison. It panics if function does not have the required form.

func EquateEmpty

func EquateEmpty() Option

EquateEmpty returns an Option that treats nil slices and maps as equal to empty ones.

func IgnoreFields

func IgnoreFields(structValue any, fieldNames ...string) Option

IgnoreFields returns an Option that skips the named fields of the struct type of structValue during comparison. It panics if structValue is not a struct or a pointer to one, or if a name does not match a field.

Jump to

Keyboard shortcuts

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