Documentation
¶
Index ¶
- func Expect[A any](t testing.TB, actual A, matchers ...Matcher[A])
- func ExpectPanic[A any](t testing.TB, f func(), matchers ...Matcher[A])
- func NewComparedMatcher[Actual any, Expect any](name string, matcher ComparableMatchFunc[Actual, Expect]) internal.MatcherNewer[Actual, Expect]
- type ComparableMatchFunc
- type MatchFunc
- type Matcher
- func AsError[T any](expect *T) Matcher[error]
- func AsErrorType[T error]() Matcher[error]
- func Be[T any](expect T) Matcher[T]
- func BeAssignableTo[T any]() Matcher[any]
- func BeConvertibleTo[T any]() Matcher[any]
- func BeFalse() Matcher[bool]
- func BeGt[T cmp.Ordered](expect T) Matcher[T]
- func BeGte[T cmp.Ordered](expect T) Matcher[T]
- func BeLt[T cmp.Ordered](expect T) Matcher[T]
- func BeLte[T cmp.Ordered](expect T) Matcher[T]
- func BeNil[Actual any]() Matcher[Actual]
- func BeTrue() Matcher[bool]
- func ConsistOfSlice[E comparable, S ~[]E](expect S) Matcher[S]
- func Contains[E comparable, S ~[]E](v E) Matcher[S]
- func ContainsSubString(sub string) Matcher[string]
- func Equal[T any](expect T) Matcher[T]
- func EquivalentSlice[E comparable, S ~[]E](expect S) Matcher[S]
- func ErrorContains(sub string) Matcher[error]
- func ErrorEqual(expect string) Matcher[error]
- func Failed() Matcher[error]
- func HaveCap[T any](cap int) Matcher[T]
- func HaveKey[K comparable, V any, M ~map[K]V](key K) Matcher[M]
- func HaveLen[T any](len int) Matcher[T]
- func HavePrefix(prefix string) Matcher[string]
- func HaveSuffix(suffix string) Matcher[string]
- func IsCodeError[Code codex.Code](expect Code) Matcher[error]
- func IsError(expect error) Matcher[error]
- func IsNotZero[Actual any]() Matcher[Actual]
- func IsType[T any]() Matcher[any]
- func IsZero[Actual any]() Matcher[Actual]
- func MatchRegexp(pattern string) Matcher[string]
- func NewMatcher[Actual any](name string, matcher MatchFunc[Actual]) Matcher[Actual]
- func Not[Actual any](matcher Matcher[Actual]) Matcher[Actual]
- func NotBe[T any](expect T) Matcher[T]
- func NotBeNil[Actual any]() Matcher[Actual]
- func NotEqual[T any](expect T) Matcher[T]
- func Succeed() Matcher[error]
- type NormalizedExpectedMatcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpectPanic ¶ added in v0.2.0
Example ¶
package main
import (
"fmt"
. "github.com/xoctopus/x/testx"
"github.com/xoctopus/x/testx/testutil"
)
type MockCodeErr int
func (MockCodeErr) Message() string { return "mock" }
func crash(i int) {
switch i {
case 0:
return
case 1:
panic(fmt.Errorf("any"))
}
}
func main() {
t := &testutil.MockTB{}
t.Reset()
ExpectPanic[error](t, func() {
panic("any")
})
fmt.Println(t.Output2())
t.Reset()
ExpectPanic[string](t, func() {
crash(1)
})
fmt.Println(t.Output2())
t.Reset()
ExpectPanic[string](t, func() {})
fmt.Println(t.Output2())
}
Output: expect a panic of `error`, but got string expect a panic of `string`, but got *errors.errorString expect a panic of `string`, but f returned normally
func NewComparedMatcher ¶ added in v0.2.0
func NewComparedMatcher[Actual any, Expect any](name string, matcher ComparableMatchFunc[Actual, Expect]) internal.MatcherNewer[Actual, Expect]
Types ¶
type ComparableMatchFunc ¶ added in v0.5.0
type Matcher ¶ added in v0.2.0
func AsErrorType ¶ added in v0.5.0
func BeAssignableTo ¶ added in v0.2.0
func BeConvertibleTo ¶ added in v0.2.0
func ConsistOfSlice ¶ added in v0.5.0
func ConsistOfSlice[E comparable, S ~[]E](expect S) Matcher[S]
func Contains ¶ added in v0.2.0
func Contains[E comparable, S ~[]E](v E) Matcher[S]
func ContainsSubString ¶ added in v0.2.0
func EquivalentSlice ¶ added in v0.2.1
func EquivalentSlice[E comparable, S ~[]E](expect S) Matcher[S]
func ErrorContains ¶ added in v0.2.0
func ErrorEqual ¶ added in v0.2.0
func HaveKey ¶ added in v0.5.0
func HaveKey[K comparable, V any, M ~map[K]V](key K) Matcher[M]
func HavePrefix ¶ added in v0.2.0
func HaveSuffix ¶ added in v0.2.0
func MatchRegexp ¶ added in v0.5.0
func NewMatcher ¶ added in v0.2.0
type NormalizedExpectedMatcher ¶ added in v0.2.0
type NormalizedExpectedMatcher = internal.NormalizedExpectedMatcher
Click to show internal directories.
Click to hide internal directories.