assert

package
v0.0.0-...-89d9e6b Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: GPL-3.0, LGPL-3.0 Imports: 4 Imported by: 7

Documentation

Overview

assert provides various assertion functions that can be used to confirm certain conditions such that these conditions are guaranteed true afterwards. These functions are particularly useful to catch unexpected and unsupported use cases, without having to litter the code with if-statements. Assertions may be placeholders for use cases that will later be supported, or they may indicate failure conditions that will not or cannot ever be supported, or cannot even occur. Some use cases or possible error conditions are illusions created by the type-system, for example when a function implements an interface but will never fail the operation. Regardless, assertions allow you to (subtly) handle cases and failure conditions that you do not handle otherwise.

For use in testing, check `/std/testing` for assertions that accept `t` following Go's testing/benchmarking practices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T comparable](actual T, values ...T) T

func AtLeast

func AtLeast[C types.Ordered](least C, value C) C

func AtMost

func AtMost[C types.Ordered](most C, value C) C

func EmptyMap

func EmptyMap[K comparable, V any](collection map[K]V)

func EmptySlice

func EmptySlice[E any](collection []E)

func EmptyString

func EmptyString(s string)

func Equal

func Equal[T comparable](v1, v2 T)

func EqualMaps

func EqualMaps[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2)

func EqualSlices

func EqualSlices[S ~[]E, E comparable](s1, s2 S)

func False

func False(v bool)

func Negative

func Negative[T types.SignedInteger](v T) T

func NonNegative

func NonNegative[T types.SignedInteger](v T) T

func NonPositive

func NonPositive[T types.Integer](v T) T

func NonZero

func NonZero[T types.Integer](v T) T

func NonZeroSlice

func NonZeroSlice[E types.Integer](s []E) []E

func Positive

func Positive[T types.Integer](v T) T

func Require

func Require(condition bool, message string)

Require check required condition and panics if condition does not hold.

func Required

func Required(val any, message string)

Required checks if provided value is nil, if so panics with provided message.

func Success

func Success(err error, message string)

Success checks that err is nil. If the error is non-nil, it will panic. `message` can have '%v' format specifier so that it can be substituted with the error message.

func True

func True(v bool)

func Type

func Type[T any](unknown interface{}, message string) T

func Unequal

func Unequal[T comparable](v1, v2 T)

func Zero

func Zero[T types.Integer](v T) T

func ZeroSlice

func ZeroSlice[E types.Integer](s []E) []E

Types

This section is empty.

Jump to

Keyboard shortcuts

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