assert

package
v0.0.0-...-48ad680 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T any](t testing.TB, expected, actual T)

Equal compares two objects of any type for equality. If the objects implement the Comparable interface, it uses the Equal method for comparison. Otherwise, it uses reflect.DeepEqual to compare the objects. If the objects are not equal, it calls the fail function to log a fatal error.

func False

func False(t testing.TB, value bool)

False checks if the provided value is false.

func IsError

func IsError(t testing.TB, err error, message string, args ...any)

IsError checks if the provided error's message matches the expected message. It takes a testing object, an error, and a string message as parameters. If the message is empty, it assumes that there should be no error If the error is nil, it logs a fatal error indicating that an error was expected. Otherwise, the function uses the Equal function to compare the error's message with the expected message. If the messages do not match, it logs a fatal error.

func Nil

func Nil(t testing.TB, v any)

Nil checks if the provided value is nil. It takes a testing object and an interface value as parameters. If the value is not nil, it logs a fatal error with a message.

func NoError

func NoError(t testing.TB, err error)

NoError checks if the provided error is nil. It takes a testing object and an error as parameters. If the error is not nil, it logs a fatal error with the error message.

func NotEqual

func NotEqual[T any](t testing.TB, first, second T)

NotEqual is the exact inverse of Equal. It uses the Equal function if the passed values are Comparators, otherwise it uses reflect to assert that the two values are not equal.

func NotNil

func NotNil(t testing.TB, v any)

NotNil checks if the provided value is not nil. It takes a testing object and an interface value as parameters. If the value is nil, it logs a fatal error with a message.

func True

func True(t testing.TB, value bool)

True checks if the provided value is true.

Types

type Comparable

type Comparable[T any] interface {
	Equal(other T) bool
}

Comparable is a generic interface that requires the implementation of the Equal method. The Equal method should compare the current object with another object of the same type and return true if they are equal, otherwise false.

Jump to

Keyboard shortcuts

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