assert

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package assert provides a collection of helper functions to simplify writing tests by offering expressive and readable assertions.

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 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 NotContains added in v0.0.4

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

NotContains checks if a container does not contain an item

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 NotPrefixString added in v0.0.5

func NotPrefixString(t testing.TB, str, prefix string)

NotPrefixString checks if a string does not start with a specific prefix

func NotStringContains added in v0.0.4

func NotStringContains(t testing.TB, str, substr string)

NotStringContains checks if a string does not contain a substring

func NotSuffixString added in v0.0.5

func NotSuffixString(t testing.TB, str, suffix string)

NotSuffixString checks if a string does not end with a specific suffix

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 PrefixString added in v0.0.5

func PrefixString(t testing.TB, str, prefix string)

PrefixString checks if a string starts with a specific prefix

func Safe

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

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

func StringContains added in v0.0.3

func StringContains(t testing.TB, str, substr string)

StringContains checks if a string contains a substring

func SuffixString added in v0.0.5

func SuffixString(t testing.TB, str, suffix string)

SuffixString checks if a string ends with a specific suffix

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) NotContains added in v0.0.4

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

NotContains checks if a slice does not contain a specific item

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) NotPrefixString added in v0.0.5

func (a *Assertion) NotPrefixString(s, prefix string)

NotPrefixString checks if a string does not start with a specific prefix

func (*Assertion) NotStringContains added in v0.0.4

func (a *Assertion) NotStringContains(s, substring string)

NotStringContains checks if a string does not contain a substring

func (*Assertion) NotSuffixString added in v0.0.5

func (a *Assertion) NotSuffixString(s, suffix string)

NotSuffixString checks if a string does not end with a specific suffix

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) PrefixString added in v0.0.5

func (a *Assertion) PrefixString(s, prefix string)

PrefixString checks if a string starts with a specific prefix

func (*Assertion) Safe

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

Safe checks if a function does not panic

func (*Assertion) StringContains added in v0.0.3

func (a *Assertion) StringContains(s, substring string)

StringContains checks if a string contains a substring

func (*Assertion) SuffixString added in v0.0.5

func (a *Assertion) SuffixString(s, suffix string)

SuffixString checks if a string ends with a specific suffix

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