assert

package module
v0.0.0-...-eb772cc Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 4 Imported by: 8

README

assert

Provides invariant checking in Golang code.

How to use

package main

import assert "github.com/ymz-ncnk/assert/panic"

// Turns on assertions.
func init() {
  assert.On = true
}

func main(){
  assert.Equal(1, 1)
}

There are also two packages testing_error and testing_fatal that can be used in tests:

package main

import assert "github.com/ymz-ncnk/assert/testing_error"

func TestSome(t *testing.T) {
  assert.Equal(1, 1, t)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bigger

func Bigger[T constraints.Ordered](a, b T, callback Callback) bool

Bigger invariant will call callback if a is lesser than b.

func BiggerFn

func BiggerFn[T constraints.Ordered](fn func() T, r T,
	callback Callback) bool

BiggerFn invariant will call callback if fn result is lesser than r.

func Equal

func Equal[T comparable](a, b T, callback Callback) bool

Equal invariant will call callback if two compared variables are not equal.

func EqualBytes

func EqualBytes(a, b []byte, callback Callback) bool

EqualBytes invariant will call callback if two byte slices are not equal.

func EqualBytesFn

func EqualBytesFn(fn func() []byte, r []byte, callback Callback) bool

EqualBytesFn invariant will call callback if fn result is not equal to r.

func EqualDeep

func EqualDeep(a, b interface{}, callback Callback) bool

EqualDeep invariant will call callback if two variables are not deep equal.

func EqualDeepFn

func EqualDeepFn(fn func() interface{}, r interface{},
	callback Callback) bool

EqualDeepFn invariant will call callback if fn result is not deep equal to r.

func EqualError

func EqualError(a, b error, callback Callback) bool

EqualError invariant will call callback if two errors are not equal.

func EqualErrorFn

func EqualErrorFn(fn func() error, r error, callback Callback) bool

EqualErrorFn invariant will call callback if fn result error is not equal to r.

func EqualFn

func EqualFn[T comparable](fn func() T, r T, callback Callback) bool

EqualFn invariant will call callback if fn compared result is not equal to r.

func Lesser

func Lesser[T constraints.Ordered](a, b T, callback Callback) bool

Lesser invariant will call callback if a is bigger than b.

func LesserFn

func LesserFn[T constraints.Ordered](fn func() T, r T,
	callback Callback) bool

LesserFn invariant will call callback if fn result is bigger than r.

Types

type Callback

type Callback func(msg string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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