Documentation
¶
Overview ¶
Package musta provides assertions that fail the test immediately.
Index ¶
- func BeDeepEqual(tb TB, actual, expected any)
- func BeEqual[T cmp.Ordered](tb TB, actual, expected T)
- func BeFalse(tb TB, actual bool)
- func BeGreater[T cmp.Ordered](tb TB, actual, expected T)
- func BeLess[T cmp.Ordered](tb TB, actual, expected T)
- func BeNil(tb TB, actual any)
- func BeNilf(tb TB, actual any, msg string, args ...any)
- func BeTrue(tb TB, actual bool)
- func BeZero[T comparable](tb TB, actual T)
- func BeZerof[T comparable](tb TB, actual T, msg string, args ...any)
- func CompareEqual[T any](tb TB, actual, expected T, compare func(_, _ T) int)
- func CompareGreater[T any](tb TB, actual, expected T, compare func(_, _ T) int)
- func CompareLess[T any](tb TB, actual, expected T, compare func(_, _ T) int)
- func CompareWith[T any](tb TB, actual, expected T, order cmp.Order, compare func(_, _ T) int)
- func NotBeDeepEqual(tb TB, actual, expected any)
- func NotBeNil(tb TB, actual any)
- func NotBeNilf(tb TB, actual any, msg string, args ...any)
- func NotBeZero[T comparable](tb TB, actual T)
- func NotBeZerof[T comparable](tb TB, actual T, msg string, args ...any)
- func Satisfy[T any](tb TB, actual T, predicate func(_ T) bool)
- func SatisfyWith[T any](tb TB, actual, expected T, predicate func(_, _ T) bool)
- type TB
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeDeepEqual ¶
BeDeepEqual checks that actual and expected are equal according to reflect.DeepEqual.
Example ¶
BeDeepEqual(t, []int{13}, []int64{13})
Output: Values are not deep equal: actual: []int{13} expected: []int64{13} FAIL
func BeGreater ¶
BeGreater checks that actual is greater than expected according to cmp.Greater.
func BeZero ¶
func BeZero[T comparable](tb TB, actual T)
BeZero checks that actual is the zero value of its type.
func BeZerof ¶
func BeZerof[T comparable](tb TB, actual T, msg string, args ...any)
BeZerof checks that actual is the zero value of its type.
func CompareEqual ¶
CompareEqual checks that compare(actual, expected) returns 0 (cmp.OrderEqual).
func CompareGreater ¶
CompareGreater checks that compare(actual, expected) returns 1 (cmp.OrderGreater).
func CompareLess ¶
CompareLess checks that compare(actual, expected) returns -1 (cmp.OrderLess).
func CompareWith ¶
CompareWith checks that compare(actual, expected) returns order.
func NotBeDeepEqual ¶
NotBeDeepEqual checks that actual and expected are not equal according to reflect.DeepEqual.
Example ¶
ExampleNotBeDeepEqual demonstrates NotBeDeepEqual.
NotBeDeepEqual(t, []int{13}, []int{13})
Output: Values are deep equal: actual: []int{13} expected: []int{13} FAIL
func NotBeZero ¶
func NotBeZero[T comparable](tb TB, actual T)
NotBeZero checks that actual is not the zero value of its type.
func NotBeZerof ¶
func NotBeZerof[T comparable](tb TB, actual T, msg string, args ...any)
NotBeZerof checks that actual is not the zero value of its type.
func Satisfy ¶
Satisfy checks that predicate returns true for actual.
Example (Inline) ¶
Satisfy(t, 13, func(v int) bool { return v > 42 })
Output: predicate is not satisfied for actual: 13 FAIL
Example (MethodExpression) ¶
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC) Satisfy(t, actual, time.Time.IsZero)
Output: predicate is not satisfied for actual: 2026-04-09 17:32:42.000000123 +0000 UTC FAIL
Example (MethodValue) ¶
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC) Satisfy(t, actual, time.Now().Before)
Output: predicate is not satisfied for actual: 2026-04-09 17:32:42.000000123 +0000 UTC FAIL
func SatisfyWith ¶
SatisfyWith checks that predicate returns true for actual and expected.
Example (Function) ¶
SatisfyWith(t, 13, 42, cmp.Greater)
Output: predicate is not satisfied with actual: 13 expected: 42 FAIL
Example (Inline) ¶
SatisfyWith(t, 13, 42, func(x, y int) bool { return x > y })
Output: predicate is not satisfied with actual: 13 expected: 42 FAIL
Example (MethodExpression) ¶
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC)
expected := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.FixedZone("My", 4*int(time.Hour.Seconds())))
SatisfyWith(t, actual, expected, time.Time.Before)
Output: predicate is not satisfied with actual: 2026-04-09 17:32:42.000000123 +0000 UTC expected: 2026-04-09 17:32:42.000000123 +0400 My FAIL