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 ¶
- func Any[T comparable](actual T, values ...T) T
- func AtLeast[C types.Ordered](least C, value C) C
- func AtMost[C types.Ordered](most C, value C) C
- func EmptyMap[K comparable, V any](collection map[K]V)
- func EmptySlice[E any](collection []E)
- func EmptyString(s string)
- func Equal[T comparable](v1, v2 T)
- func EqualMaps[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2)
- func EqualSlices[S ~[]E, E comparable](s1, s2 S)
- func False(v bool)
- func Negative[T types.SignedInteger](v T) T
- func NonNegative[T types.SignedInteger](v T) T
- func NonPositive[T types.Integer](v T) T
- func NonZero[T types.Integer](v T) T
- func NonZeroSlice[E types.Integer](s []E) []E
- func Positive[T types.Integer](v T) T
- func Require(condition bool, message string)
- func Required(val any, message string)
- func Success(err error, message string)
- func True(v bool)
- func Type[T any](unknown interface{}, message string) T
- func Unequal[T comparable](v1, v2 T)
- func Zero[T types.Integer](v T) T
- func ZeroSlice[E types.Integer](s []E) []E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any[T comparable](actual T, values ...T) T
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 Negative ¶
func Negative[T types.SignedInteger](v T) T
func NonNegative ¶
func NonNegative[T types.SignedInteger](v T) T
func NonPositive ¶
func NonZeroSlice ¶
func Success ¶
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 Unequal ¶
func Unequal[T comparable](v1, v2 T)
Types ¶
This section is empty.