assert

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(cond bool, msg string)

Assert panics if cond is false. It is intended to be used for debugging.

Parameters:

  • cond: the condition to check.
  • msg: the message to print if the condition is false.

Example:

foo := "foo"
Assert(foo == "bar", "foo is not \"bar\"") // panics: "[ASSERT FAILED]: foo is not \"bar\""

func AssertConv added in v0.1.2

func AssertConv[T any](elem any, target string) T

AssertConv tries to convert an element to the expected type and panics if it is not possible.

Parameters:

  • elem: the element to check.
  • var_name: the name of the variable.

Returns:

  • T: the converted element.

func AssertDeref added in v0.1.2

func AssertDeref[T any](elem *T, is_param bool, name string) T

AssertDeref tries to dereference an element and panics if it is nil.

Parameters:

  • elem: the element to dereference.
  • param_name: the name of the parameter.

Returns:

  • T: the dereferenced element.

func AssertErr

func AssertErr(err error, format string, args ...any)

AssertErr panics if err is not nil. It is intended to be used for debugging.

Parameters:

  • err: the error to check.
  • format: the format of the message.
  • args: the arguments of the format.

Example:

foo := "foo"
err := my_function(foo, "bar")
AssertErr(err, "my_function(%s, %q)", foo, "bar")
// panics: "[ASSERT FAILED]: my_function(foo, \"bar\"") = <err>"

func AssertF

func AssertF(cond bool, format string, args ...any)

AssertF panics if cond is false. It is intended to be used for debugging.

Parameters:

  • cond: the condition to check.
  • format: the format of the message.
  • args: the arguments of the format.

Example:

foo := "foo"
bar := "bar"
AssertF(foo == bar, "%q is not %q", foo, bar) // panics: "[ASSERT FAILED]: \"foo\"" is not \"bar\""

func AssertNotNil added in v0.1.2

func AssertNotNil(v any, name string)

AssertNotNil panics if v is nil. It is intended to be used for debugging.

Parameters:

  • v: the value to check.
  • name: the name of the value.

func AssertNotOk added in v0.1.7

func AssertNotOk(ok bool, format string, args ...any)

AssertOk panics if v is true. It is intended to be used for debugging.

Parameters:

  • ok: the value to check.
  • format: the format of the message.
  • args: the arguments of the format.

Example:

foo := "foo"
ok := my_function(foo, "bar")
AssertNotOk(!ok, "my_function(%s, %q)", foo, "bar")
// panics: "[ASSERT FAILED]: my_function(foo, \"bar\"") = true"

func AssertOk

func AssertOk(ok bool, format string, args ...any)

AssertOk panics if v is false. It is intended to be used for debugging.

Parameters:

  • ok: the value to check.
  • format: the format of the message.
  • args: the arguments of the format.

Example:

foo := "foo"
ok := my_function(foo, "bar")
AssertOk(ok, "my_function(%s, %q)", foo, "bar")
// panics: "[ASSERT FAILED]: my_function(foo, \"bar\"") = false"

func AssertTypeOf added in v0.1.2

func AssertTypeOf[T any](elem any, target string, allow_nil bool)

AssertTypeOf panics if the element is not of the expected type.

Parameters:

  • elem: the element to check.
  • var_name: the name of the variable.
  • allow_nil: if the element can be nil.

func TODO added in v0.1.8

func TODO()

TODO writes a panic message indicating that a case has not been handled yet.

This function is intended to be used as a placeholder until the case is handled.

Types

type ErrAssertFailed added in v0.1.7

type ErrAssertFailed struct {
	// Msg is the error message
	Msg string
}

ErrAssertFailed is an error returned when an assertion fails.

func NewErrAssertFailed added in v0.1.7

func NewErrAssertFailed(msg string) *ErrAssertFailed

NewErrAssertFailed creates a new ErrAssertFailed error.

Parameters:

  • msg: the error message.

Returns:

  • *ErrAssertFailed: the new error.

func (ErrAssertFailed) Error added in v0.1.7

func (e ErrAssertFailed) Error() string

Error implements the error interface.

Message:

"[ASSERT FAILED]: <msg>"

Jump to

Keyboard shortcuts

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