Documentation
¶
Index ¶
- func JustPanic()
- func Panic(msg string, a ...any)
- type Condition
- func MustBe(v any, kinds ...reflect.Kind) Condition
- func MustBeElemType(a any) Condition
- func MustBeLenghtType(a any) Condition
- func MustContainA(a any, e any) Condition
- func MustContainM[kt comparable, vt any](m map[kt]vt, k kt) Condition
- func MustEmpty(a any) Condition
- func MustEqual(a, b any) Condition
- func MustFalse(b bool) Condition
- func MustNil(a any) Condition
- func MustNotBe(v any, kinds ...reflect.Kind) Condition
- func MustNotContainA(a any, e any) Condition
- func MustNotContainM[kt comparable, vt any](m map[kt]vt, k kt) Condition
- func MustNotEmpty(a any) Condition
- func MustNotEqual(a, b any) Condition
- func MustNotNil(a any) Condition
- func MustNotPanic(f func()) (c Condition)
- func MustNotZero[T number](a T) Condition
- func MustPanic(f func()) (c Condition)
- func MustReadableChan(c any) Condition
- func MustSameType(v ...any) Condition
- func MustTrue(b bool) Condition
- func MustWritableChan(c any) Condition
- func MustZero[T number](a T) Condition
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Condition ¶
type Condition bool
Condition is a type of bool which later you must call JustAssert or Assert. If the condition is false, the program will be panicked.
Example ¶
package main import ( "github.com/xybor/xyplatform/xycond" ) func main() { // Assert 1 == 2 xycond.MustFalse(1 == 2).Assert("weird") // Assert x is 0 var x int xycond.MustZero(x).Assert("%d is not initialized with zero", x) // Assert string is empty, panic without any message if the condition fails. xycond.MustEmpty("").JustAssert() }
Output:
func MustBeElemType ¶ added in v0.0.2
MustBeElemType returns true if a is LengthType or Pointer.
func MustBeLenghtType ¶ added in v0.0.2
MustBeLengthType returns true if a is a string, slice, array, or chan.
func MustContainA ¶ added in v0.0.2
MustContainA returns true if array or slice contains the element.
func MustContainM ¶ added in v0.0.2
func MustContainM[kt comparable, vt any](m map[kt]vt, k kt) Condition
MustContainM returns true if map contains the key.
func MustEmpty ¶ added in v0.0.2
MustEmpty returns true if a is an empty string, slice, array, or channel.
func MustNotBe ¶ added in v0.0.2
MustNotBe returns true if value doesn't belong to all of basic types.
func MustNotContainA ¶ added in v0.0.2
MustNotContainA returns true if array doesn't contains the element.
func MustNotContainM ¶ added in v0.0.2
func MustNotContainM[kt comparable, vt any](m map[kt]vt, k kt) Condition
MustNotContainM returns true if map doesn't contain the key.
func MustNotEmpty ¶ added in v0.0.2
MustNotEmpty returns true if a is a not empty string, slice, array, or channel.
func MustNotEqual ¶ added in v0.0.2
MustNotEqual returns true if two values are not the same.
func MustNotNil ¶ added in v0.0.2
MustNotNil returns true if a is not nil.
func MustNotPanic ¶ added in v0.0.2
func MustNotPanic(f func()) (c Condition)
func MustNotZero ¶ added in v0.0.2
func MustNotZero[T number](a T) Condition
MustNotZero returns true if a is not zero. MustNotZero only accepts number parameter.
func MustReadableChan ¶ added in v0.0.2
MustReadableChan returns true if channel is readable.
func MustSameType ¶ added in v0.0.2
MustSameType returns true if values are the same type.
func MustWritableChan ¶ added in v0.0.2
MustWritableChan returns true if channel is writable.
func MustZero ¶ added in v0.0.2
func MustZero[T number](a T) Condition
MustZero returns true if a is zero. MustZero only accepts number parameter.
func (Condition) Assert ¶
Assert prints a formatted message and panics the program if the condition fails.
func (Condition) JustAssert ¶
func (c Condition) JustAssert()
JustAssert panics the program without a message if condition fails.