assert

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Panic func(error) = func(err error) { panic(err) }

	LogOnError func(error)

	AssertionFailedError AssertError = "assertion failed"
)

Functions

func Assert

func Assert(cond bool, msg any, args ...interface{}) error

Assert asserts that the condition is true if the condition is false, it panics with the message

func AssertFunc

func AssertFunc(fail func(err error) error, cond bool, msg any, args ...interface{}) error

AssertFunc asserts that the condition is true if the condition is false, it panics with the message

func Contains

func Contains[T comparable](v T, a []T, msg any, args ...interface{}) error

Contains asserts that the value is in the slice if the value is not in the slice, it panics with the message

func ContainsFunc

func ContainsFunc[T any](a []T, f func(T) (in bool), msg any, args ...interface{}) error

ContainsFunc asserts that the value is in the slice if the value is not in the slice, it panics with the message

func Equal

func Equal[T comparable](a, b T, msg any, args ...interface{}) error

Equal asserts that the two values are equal if the two values are not equal, it panics with the message

func Err

func Err(err error) error

Err asserts that the error is nil if the error is not nil, it panics with the message

func ErrNil

func ErrNil(err error) error

ErrNil asserts that the error is not nil if the error is nil, it panics with the message

func Fail

func Fail(msg any, args ...interface{}) error

Fail is called when an assertion fails It is used to either return an error if PanicEnabled is false or panic if PanicEnabled is true

func FailFunc

func FailFunc(failFn func(err error) error, msg any, args ...interface{}) error

FailFunc is a function that is called when an assertion fails it is used to customize the behavior of the assertion

func False

func False(cond bool, msg any, args ...interface{}) error

False asserts that the condition is false if the condition is true, it panics with the message

func Falsy

func Falsy(v any, msg any, args ...interface{}) error

Falsy asserts that the value is falsy A value is falsy if it is an invalid value or the zero value

func Gt

func Gt[T any](a []T, min int, msg any, args ...interface{}) error

Gt asserts that the length of the slice is greater than the min if the length is less than or equal to the min, it panics with the message

func Gte

func Gte[T any](a []T, min int, msg any, args ...interface{}) error

Gte asserts that the length of the slice is greater than or equal to the min if the length is less than the min, it panics with the message

func Lt

func Lt[T any](a []T, max int, msg any, args ...interface{}) error

Lt asserts that the length of the slice is less than the max if the length is greater than or equal to the max, it panics with the message

func Lte

func Lte[T any](a []T, max int, msg any, args ...interface{}) error

Lte asserts that the length of the slice is less than or equal to the max if the length is greater than the max, it panics with the message

func True

func True(cond bool, msg any, args ...interface{}) error

True asserts that the condition is true if the condition is false, it panics with the message

func Truthy

func Truthy(v any, msg any, args ...interface{}) error

Truthy asserts that the value is truthy A value is truthy if it is not an invalid value and not the zero value

Types

type AssertError

type AssertError = errs.Error

Jump to

Keyboard shortcuts

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