match

package
v0.0.0-...-b9e5ada Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher[T any] interface {
	Explain() string
	Match(actual T) error
}

func Any

func Any[T comparable]() Matcher[T]

func Eq

func Eq[T comparable](expected T) Matcher[T]
Example
c := NewMockContext() // Would normally be NewContext(t)
Assert(c, 10, Eq(10))
Assert(c, "hello", Eq("hello"))

func Eventually

func Eventually[T any](expectation Matcher[T]) Matcher[T]
Example (Chan)
c := NewMockContext() // Would normally be NewContext(t)

ch := make(chan string)
go func() {
	time.Sleep(500 * time.Millisecond)
	ch <- "hello"
}()

Assert(c, ch, Eventually(Produces(Eq("hello"))))
Example (Func)
c := NewMockContext() // Would normally be NewContext(t)

var value int64
go func() {
	for i := 0; i < 5; i++ {
		time.Sleep(200 * time.Millisecond)
		atomic.AddInt64(&value, 1)
	}
}()

Assert(c, func() int64 {
	return atomic.LoadInt64(&value)
}, Eventually(Returns(Eq(int64(5)))))

func NewMatcher

func NewMatcher[T any](opts ...MatcherOption[T]) Matcher[T]

func Produces

func Produces[T any, C <-chan T](expectation Matcher[T]) Matcher[C]

func Returns

func Returns[T any, F func() T](expectation Matcher[T]) Matcher[F]

type MatcherOption

type MatcherOption[T any] func(m *matcher[T])

func WithExplanation

func WithExplanation[T any](explanation string) MatcherOption[T]

func WithMatchFunc

func WithMatchFunc[T any](fn func(actual T) error) MatcherOption[T]

Jump to

Keyboard shortcuts

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