cmp

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Or added in v2.9.0

func Or[T comparable](values ...T) T

Or is an alias to stdcmp.Or in the standard library:

  • It returns the leftmost argument that is not zero.
  • It returns zero when all its arguments are zero.

This is here so test authors can import fewer "cmp" packages.

Types

type Comparison

type Comparison = gotest.Comparison

func Contains

func Contains(collection, item any) Comparison

Contains succeeds if item is in collection. The collection may be a string, map, slice, or array. See gotest.tools/v3/assert/cmp.Contains. When either item or collection is a multi-line string, the failure message contains a multi-line report of the differences.

func DeepEqual

func DeepEqual[T any](x, y T, opts ...gocmp.Option) Comparison

DeepEqual compares two values using github.com/google/go-cmp/cmp and succeeds if the values are equal. The comparison can be customized using comparison Options. See github.com/google/go-cmp/cmp.Option constructors and github.com/google/go-cmp/cmp/cmpopts.

func Equal added in v2.9.0

func Equal[T any](x, y T) Comparison

Equal succeeds if x == y, the same as gotest.tools/v3/assert.Equal. The type constraint makes it easier to compare against numeric literals and typed constants.

func Len added in v2.9.0

func Len[Slice ~[]E, E any](actual Slice, expected int) Comparison

Len succeeds if actual has the expected length.

func LenMap added in v2.9.0

func LenMap[Map ~map[K]V, K comparable, V any](actual Map, expected int) Comparison

LenMap succeeds if actual has the expected length.

func MarshalContains

func MarshalContains(actual any, expected string) Comparison

MarshalContains converts actual to YAML and succeeds if expected is in the result.

func MarshalMatches

func MarshalMatches(actual any, expected string) Comparison

MarshalMatches converts actual to YAML and compares that to expected.

func Regexp

func Regexp[RE *regexp.Regexp | ~string](regex RE, value string) Comparison

Regexp succeeds if value contains any match of the regular expression. The regular expression may be a *regexp.Regexp or a string that is a valid regexp pattern.

Jump to

Keyboard shortcuts

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