assert

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 6 Imported by: 0

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

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 DeepEqual

func DeepEqual[T any](a, b T) error

DeepEqual is check what a is deep equal to b.

func Equal

func Equal[T comparable](a, b T) error

Equal is check what a is equal to b.

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 If

func If(b bool, format string, a ...interface{}) error

If is a custom assertion function.

func Less

func Less[T constraints.Ordered](a, b T) error

Less is check what a is less than 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

Max asserts that the value is the maximum value.

func Min

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 Nil

func Nil[T any](a *T) error

Nil asserts that the value is nil.

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 NotNil

func NotNil[T any](a *T) error

NotNil asserts that the value is not nil.

func NotZero

func NotZero[T any](a T) error

NotZero is check what a is not zero 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

func SliceLenEqual[T any](slice []T, n int) error

SliceLenEqual asserts that the length of the slice is equal to n.

func SliceLenGreater

func SliceLenGreater[T any](slice []T, n int) error

SliceLenGreater asserts that the length of the slice is greater than n.

func SliceLenGreaterEqual

func SliceLenGreaterEqual[T any](slice []T, n int) error

SliceLenGreaterEqual asserts that the length of the slice is greater than or equal to n.

func SliceLenLess

func SliceLenLess[T any](slice []T, n int) error

SliceLenLess asserts that the length of the slice is less than n.

func SliceLenLessEqual

func SliceLenLessEqual[T any](slice []T, n int) error

SliceLenLessEqual asserts that the length of the slice is less than or equal to n.

func SliceLenNotEqual

func SliceLenNotEqual[T any](slice []T, n int) error

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

func StrLenEqual(s string, n int) error

StrLenEqual asserts that the length of the string is equal to n.

func StrLenGreater

func StrLenGreater(s string, n int) error

StrLenGreater asserts that the length of the string is greater than n.

func StrLenGreaterEqual

func StrLenGreaterEqual(s string, n int) error

StrLenGreaterEqual asserts that the length of the string is greater than or equal to n.

func StrLenLess

func StrLenLess(s string, n int) error

StrLenLess asserts that the length of the string is less than n.

func StrLenLessEqual

func StrLenLessEqual(s string, n int) error

StrLenLessEqual asserts that the length of the string is less than or equal to n.

func StrLenNotEqual

func StrLenNotEqual(s string, n int) error

StrLenNotEqual asserts that the length of the string is not equal to n.

func Zero

func Zero[T any](a T) error

Zero is check what a is zero value.

Types

type Assert

type Assert struct {
	// contains filtered or unexported fields
}

Assert is a assertion list.

func Of

func Of(assertions ...error) Assert

Of is a constructor of Assert.

func (Assert) Result

func (a Assert) Result() error

Result return the assertions result.

Jump to

Keyboard shortcuts

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