Documentation ¶
Overview ¶
Package assert provides type-safe assertions with clean error messages.
Index ¶
- func Compare[T any](t testing.TB, x, y T, options ...CompareOption) bool
- func Contains(t testing.TB, haystack string, needle string, msgAndArgs ...any)
- func Diff[T any](before, after T, compareOptions ...CompareOption) string
- func Equal[T any](t testing.TB, expected, actual T, msgArgsAndCompareOptions ...any)
- func EqualError(t testing.TB, err error, errString string, msgAndArgs ...any)
- func Error(t testing.TB, err error, msgAndArgs ...any)
- func False(t testing.TB, ok bool, msgAndArgs ...any)
- func HasPrefix(t testing.TB, s, prefix string, msgAndArgs ...any)
- func HasSuffix(t testing.TB, s, suffix string, msgAndArgs ...any)
- func IsError(t testing.TB, err, target error, msgAndArgs ...any)
- func NoError(t testing.TB, err error, msgAndArgs ...any)
- func NotContains(t testing.TB, haystack string, needle string, msgAndArgs ...any)
- func NotEqual[T any](t testing.TB, expected, actual T, msgArgsAndCompareOptions ...any)
- func NotIsError(t testing.TB, err, target error, msgAndArgs ...any)
- func NotPanics(t testing.TB, fn func(), msgAndArgs ...any)
- func NotSliceContains[T any](t testing.TB, haystack []T, needle T, msgAndArgs ...interface{})
- func NotZero[T any](t testing.TB, value T, msgAndArgs ...any)
- func Panics(t testing.TB, fn func(), msgAndArgs ...any)
- func SliceContains[T any](t testing.TB, haystack []T, needle T, msgAndArgs ...interface{})
- func True(t testing.TB, ok bool, msgAndArgs ...any)
- func Zero[T any](t testing.TB, value T, msgAndArgs ...any)
- type CompareOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
func Compare[T any](t testing.TB, x, y T, options ...CompareOption) bool
Compare two values for equality and return true or false.
func Diff ¶ added in v2.10.0
func Diff[T any](before, after T, compareOptions ...CompareOption) string
Diff returns a unified diff of the string representation of two values.
func Equal ¶
Equal asserts that "expected" and "actual" are equal.
If they are not, a diff of the Go representation of the values will be displayed.
func EqualError ¶
EqualError asserts that either an error is non-nil and that its message is what is expected, or that error is nil if the expected message is empty.
func NotContains ¶
NotContains asserts that "haystack" does not contain "needle".
func NotEqual ¶
NotEqual asserts that "expected" is not equal to "actual".
If they are equal the expected value will be displayed.
func NotIsError ¶ added in v2.3.0
NotIsError asserts than no error in "err"'s tree matches "target".
func NotSliceContains ¶ added in v2.11.0
NotSliceContains asserts that "haystack" does not contain "needle".
func SliceContains ¶ added in v2.11.0
SliceContains asserts that "haystack" contains "needle".
Types ¶
type CompareOption ¶ added in v2.4.0
A CompareOption modifies how object comparisons behave.
func Exclude ¶ added in v2.4.0
func Exclude[T any]() CompareOption
Exclude fields of the given type from comparison.
func IgnoreGoStringer ¶ added in v2.8.0
func IgnoreGoStringer() CompareOption
IgnoreGoStringer ignores GoStringer implementations when comparing.