Documentation
¶
Index ¶
- func Assert(cond bool, msg string)
- func AssertConv[T any](elem any, target string) T
- func AssertDeref[T any](elem *T, is_param bool, name string) T
- func AssertErr(err error, format string, args ...any)
- func AssertF(cond bool, format string, args ...any)
- func AssertNotNil(v any, name string)
- func AssertNotOk(ok bool, format string, args ...any)
- func AssertOk(ok bool, format string, args ...any)
- func AssertTypeOf[T any](elem any, target string, allow_nil bool)
- func TODO()
- type ErrAssertFailed
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
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
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
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 ¶
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 ¶
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
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
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 ¶
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
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.
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>"