Documentation ¶
Overview ¶
assert is a assertion library for test.
Example ¶
package main import ( "fmt" "github.com/snowmerak/generics-for-go/v2/test/assert" ) func main() { assertions := assert.Of( assert.If(true, "true is not true"), assert.Less(20, 10), assert.Greater(10, 20), assert.Equal(10, 10), assert.DeepEqual("string", "string"), assert.Equal("string", "string"), assert.NotZero(0), assert.Zero("1"), assert.NotNil(new(int)), assert.Nil[int](nil), ) fmt.Println(assertions.Result()) }
Output: 0: 20 is not less than 10 1: 10 is not greater than 20 2: 0 is zero value 3: 1 is not zero value
Index ¶
- func Between[T constraints.Ordered](a T, min, max T) error
- func CloseTo[T constraints.Integer | constraints.Float](a T, b T, epsilon T) error
- func DeepEqual[T any](a, b T) error
- func Equal[T comparable](a, b T) error
- func Greater[T constraints.Ordered](a, b T) error
- func GreaterEqual[T constraints.Ordered](a, b T) error
- func If(b bool, format string, a ...interface{}) error
- func Less[T constraints.Ordered](a, b T) error
- func LessEqual[T constraints.Ordered](a, b T) error
- func MapEqual[K, V comparable](a, b map[K]V) error
- func MapKeyEqual[K comparable, V any](a, b map[K]V) error
- func MapKeyNotEqual[K comparable, V any](a, b map[K]V) error
- func MapLenEqual[K comparable, V any](m map[K]V, n int) error
- func MapLenGreater[K comparable, V any](m map[K]V, n int) error
- func MapLenGreaterEqual[K comparable, V any](m map[K]V, n int) error
- func MapLenLess[K comparable, V any](m map[K]V, n int) error
- func MapLenLessEqual[K comparable, V any](m map[K]V, n int) error
- func MapLenNotEqual[K comparable, V any](m map[K]V, n int) error
- func MapNotEqual[K, V comparable](a, b map[K]V) error
- func Max[T constraints.Integer | constraints.Float](a T) error
- func Min[T constraints.Integer | constraints.Float](a T) error
- func Nagative[T constraints.Signed | constraints.Float](a T) error
- func Nil[T any](a *T) error
- func NotCloseTo[T constraints.Integer | constraints.Float](a T, b T, epsilon T) error
- func NotNil[T any](a *T) error
- func NotZero[T any](a T) error
- func Positive[T constraints.Signed | constraints.Float](a T) error
- func SliceEqual[T comparable](a []T, b ...T) error
- func SliceLenEqual[T any](slice []T, n int) error
- func SliceLenGreater[T any](slice []T, n int) error
- func SliceLenGreaterEqual[T any](slice []T, n int) error
- func SliceLenLess[T any](slice []T, n int) error
- func SliceLenLessEqual[T any](slice []T, n int) error
- func SliceLenNotEqual[T any](slice []T, n int) error
- func SliceNotEqual[T comparable](a []T, b ...T) error
- func StrLenEqual(s string, n int) error
- func StrLenGreater(s string, n int) error
- func StrLenGreaterEqual(s string, n int) error
- func StrLenLess(s string, n int) error
- func StrLenLessEqual(s string, n int) error
- func StrLenNotEqual(s string, n int) error
- func Zero[T any](a T) error
- type Assert
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
func Between[T constraints.Ordered](a T, min, max T) error
Between asserts that the value is between the expected values. The expected values are inclusive.
func CloseTo ¶
func CloseTo[T constraints.Integer | constraints.Float](a T, b T, epsilon T) error
CloseTo asserts that the value is close to the expected value. The expected value is within epsilon of the actual value.
func Greater ¶
func Greater[T constraints.Ordered](a, b T) error
Greater is check what a is greater than b.
func GreaterEqual ¶
func GreaterEqual[T constraints.Ordered](a, b T) error
GreaterEqual is check what a is greater than or equal to b.
func LessEqual ¶
func LessEqual[T constraints.Ordered](a, b T) error
LessEqual is check what a is less than or equal to b.
func MapEqual ¶
func MapEqual[K, V comparable](a, b map[K]V) error
MapEqual asserts that the value is equal to the expected value.
func MapKeyEqual ¶
func MapKeyEqual[K comparable, V any](a, b map[K]V) error
MapKeyEqual asserts that the value is equal to the expected value.
func MapKeyNotEqual ¶
func MapKeyNotEqual[K comparable, V any](a, b map[K]V) error
MapKeyNotEqual asserts that the value is not equal to the expected value.
func MapLenEqual ¶
func MapLenEqual[K comparable, V any](m map[K]V, n int) error
MapLenEqual asserts that the length of the map is equal to n.
func MapLenGreater ¶
func MapLenGreater[K comparable, V any](m map[K]V, n int) error
SliceLenGreater asserts that the length of the slice is greater than n.
func MapLenGreaterEqual ¶
func MapLenGreaterEqual[K comparable, V any](m map[K]V, n int) error
SliceLenGreaterEqual asserts that the length of the slice is greater than or equal to n.
func MapLenLess ¶
func MapLenLess[K comparable, V any](m map[K]V, n int) error
MapLenLess asserts that the length of the map is less than n.
func MapLenLessEqual ¶
func MapLenLessEqual[K comparable, V any](m map[K]V, n int) error
SliceLenLessEqual asserts that the length of the slice is less than or equal to n.
func MapLenNotEqual ¶
func MapLenNotEqual[K comparable, V any](m map[K]V, n int) error
MapLenNotEqual asserts that the length of the map is not equal to n.
func MapNotEqual ¶
func MapNotEqual[K, V comparable](a, b map[K]V) error
MapDeepEqual asserts that the value is equal to the expected value.
func Max ¶
func Max[T constraints.Integer | constraints.Float](a T) error
Max asserts that the value is the maximum value.
func Min ¶
func Min[T constraints.Integer | constraints.Float](a T) error
Min asserts that the value is the minimum value.
func Nagative ¶
func Nagative[T constraints.Signed | constraints.Float](a T) error
Nagative asserts that the value is negative.
func NotCloseTo ¶
func NotCloseTo[T constraints.Integer | constraints.Float](a T, b T, epsilon T) error
NotCloseTo asserts that the value is not close to the expected value. The expected value is within epsilon of the actual value.
func Positive ¶
func Positive[T constraints.Signed | constraints.Float](a T) error
Positive asserts that the value is positive.
func SliceEqual ¶
func SliceEqual[T comparable](a []T, b ...T) error
SliceEqual asserts that the value is equal to the expected value.
func SliceLenEqual ¶
SliceLenEqual asserts that the length of the slice is equal to n.
func SliceLenGreater ¶
SliceLenGreater asserts that the length of the slice is greater than n.
func SliceLenGreaterEqual ¶
SliceLenGreaterEqual asserts that the length of the slice is greater than or equal to n.
func SliceLenLess ¶
SliceLenLess asserts that the length of the slice is less than n.
func SliceLenLessEqual ¶
SliceLenLessEqual asserts that the length of the slice is less than or equal to n.
func SliceLenNotEqual ¶
SliceLenNotEqual asserts that the length of the slice is not equal to n.
func SliceNotEqual ¶
func SliceNotEqual[T comparable](a []T, b ...T) error
SliceNotEqual asserts that the value is not equal to the expected value.
func StrLenEqual ¶
StrLenEqual asserts that the length of the string is equal to n.
func StrLenGreater ¶
StrLenGreater asserts that the length of the string is greater than n.
func StrLenGreaterEqual ¶
StrLenGreaterEqual asserts that the length of the string is greater than or equal to n.
func StrLenLess ¶
StrLenLess asserts that the length of the string is less than n.
func StrLenLessEqual ¶
StrLenLessEqual asserts that the length of the string is less than or equal to n.
func StrLenNotEqual ¶
StrLenNotEqual asserts that the length of the string is not equal to n.