assert

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

assert provides a set of assertion functions for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](t testing.TB, container []T, item T)

Contains checks if a container (string or slice) contains an item

func Equal

func Equal[T comparable](t testing.TB, actual, expected T)

Equal checks if two values are equal

func False

func False(t testing.TB, condition bool)

False checks if a condition is false

func Greater

func Greater[T ordered](t testing.TB, actual, expected T)

Greater checks if one value is greater than another

func GreaterOrEqual

func GreaterOrEqual[T ordered](t testing.TB, actual, expected T)

GreaterOrEqual checks if one value is greater than or equal to another

func IsClose

func IsClose(t testing.TB, actual, expected, tolerance float64)

IsClose checks if a value is close to another value within a tolerance

func Length

func Length[T container](t testing.TB, collection T, expectedLength int)

Length checks if a collection has the expected length

func Less

func Less[T ordered](t testing.TB, actual, expected T)

Less checks if one value is less than another

func LessOrEqual

func LessOrEqual[T ordered](t testing.TB, actual, expected T)

LessOrEqual checks if one value is less than or equal to another

func Nil

func Nil(t testing.TB, value any)

Nil checks if a value is nil

func NotEqual

func NotEqual[T comparable](t testing.TB, actual, unexpected T)

NotEqual checks if two values are not equal

func NotNil

func NotNil(t testing.TB, value any)

NotNil checks if a value is not nil

func NotZero

func NotZero[T numeric](t testing.TB, v T)

NotZero checks if a numeric value is not zero

func Panic

func Panic(t testing.TB, f func())

Panic checks if a function call results in a panic

func Safe

func Safe(t testing.TB, f func())

Safe checks if a function call does not result in a panic

func True

func True(t testing.TB, condition bool)

True checks if a condition is true

func Zero

func Zero[T numeric](t testing.TB, v T)

Zero checks if a numeric value is zero

Types

type Assertion

type Assertion struct {
	T testing.TB
}

Assertion is a struct that holds a reference to the testing.T object

func That

func That(t testing.TB) *Assertion

That creates a new Assertion instance for use in tests.

func (*Assertion) Contains

func (a *Assertion) Contains(slice []any, item any)

Contains checks if a slice contains a specific item

func (*Assertion) Equal

func (a *Assertion) Equal(actual, expected any)

Equal checks if two values are equal

func (*Assertion) False

func (a *Assertion) False(condition bool)

False checks if a condition is false

func (*Assertion) Greater

func (a *Assertion) Greater(actual, expected any)

Greater checks if one value is greater than another

func (*Assertion) GreaterOrEqual

func (a *Assertion) GreaterOrEqual(actual, expected any)

GreaterOrEqual checks if one value is greater than or equal to another

func (*Assertion) IsClose

func (a *Assertion) IsClose(actual, expected any, tolerance float64)

IsClose checks if two floating-point numbers are close to each other

func (*Assertion) Length

func (a *Assertion) Length(collection []any, expectedLength int)

Length checks the length of a collection

func (*Assertion) Less

func (a *Assertion) Less(actual, expected any)

Less checks if one value is less than another

func (*Assertion) LessOrEqual

func (a *Assertion) LessOrEqual(actual, expected any)

LessOrEqual checks if one value is less than or equal to another

func (*Assertion) Nil

func (a *Assertion) Nil(value any)

Nil checks if a value is nil

func (*Assertion) NotEqual

func (a *Assertion) NotEqual(actual, unexpected any)

NotEqual checks if two values are not equal

func (*Assertion) NotNil

func (a *Assertion) NotNil(value any)

NotNil checks if a value is not nil

func (*Assertion) NotZero

func (a *Assertion) NotZero(value any)

NotZero checks if a numeric value is not zero

func (*Assertion) Panic

func (a *Assertion) Panic(fn func())

Panic checks if a function panics

func (*Assertion) Safe

func (a *Assertion) Safe(fn func())

Safe checks if a function does not panic

func (*Assertion) True

func (a *Assertion) True(condition bool)

True checks if a condition is true

func (*Assertion) Zero

func (a *Assertion) Zero(value any)

Zero checks if a numeric value is zero

Jump to

Keyboard shortcuts

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