Documentation
¶
Index ¶
- Variables
- type Context1
- func (ctx *Context1[A]) Capture() A
- func (ctx *Context1[A]) Diff(t testing.TB, other A, opts ...Opt)
- func (ctx *Context1[A]) Equal(t testing.TB, other A, opts ...Opt)
- func (ctx *Context1[A]) NotEqual(t testing.TB, other A, opts ...Opt)
- func (ctx *Context1[A]) Validate(t testing.TB, cb func(testing.TB, A))
- type Context1E
- func (ctx *Context1E) Capture() error
- func (ctx *Context1E) Error(t testing.TB, opts ...Opt)
- func (ctx *Context1E) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt)
- func (ctx *Context1E) MatchesError(t testing.TB, expected string, opts ...Opt)
- func (ctx *Context1E) NoError(t testing.TB, opts ...Opt)
- func (ctx *Context1E) Validate(t testing.TB, cb func(error))
- type Context2
- func (ctx *Context2[A, B]) Capture() (B, *Context1[A])
- func (ctx *Context2[A, B]) Diff(t testing.TB, other B, opts ...Opt) *Context1[A]
- func (ctx *Context2[A, B]) Equal(t testing.TB, other B, opts ...Opt) *Context1[A]
- func (ctx *Context2[A, B]) NotEqual(t testing.TB, other B, opts ...Opt) *Context1[A]
- func (ctx *Context2[A, B]) Validate(t testing.TB, cb func(B)) *Context1[A]
- type Context2E
- func (ctx *Context2E[A]) Capture() (error, *Context1[A])
- func (ctx *Context2E[A]) Error(t testing.TB, opts ...Opt) *Context1[A]
- func (ctx *Context2E[A]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context1[A]
- func (ctx *Context2E[A]) MatchesError(t testing.TB, expected string, opts ...Opt) *Context1[A]
- func (ctx *Context2E[A]) NoError(t testing.TB, opts ...Opt) *Context1[A]
- func (ctx *Context2E[A]) Validate(t testing.TB, cb func(error)) *Context1[A]
- type Context3
- func (ctx *Context3[A, B, C]) Capture() (C, *Context2[A, B])
- func (ctx *Context3[A, B, C]) Diff(t testing.TB, other C, opts ...Opt) *Context2[A, B]
- func (ctx *Context3[A, B, C]) Equal(t testing.TB, other C, opts ...Opt) *Context2[A, B]
- func (ctx *Context3[A, B, C]) NotEqual(t testing.TB, other C, opts ...Opt) *Context2[A, B]
- func (ctx *Context3[A, B, C]) Validate(t testing.TB, cb func(C)) *Context2[A, B]
- type Context3E
- func (ctx *Context3E[A, B]) Capture() (error, *Context2[A, B])
- func (ctx *Context3E[A, B]) Error(t testing.TB, opts ...Opt) *Context2[A, B]
- func (ctx *Context3E[A, B]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context2[A, B]
- func (ctx *Context3E[A, B]) MatchesError(t testing.TB, expected string, opts ...Opt) *Context2[A, B]
- func (ctx *Context3E[A, B]) NoError(t testing.TB, opts ...Opt) *Context2[A, B]
- func (ctx *Context3E[A, B]) Validate(t testing.TB, cb func(error)) *Context2[A, B]
- type DiffInterface
- type EqualityInterface
- type Opt
Constants ¶
This section is empty.
Variables ¶
var (
// Fatal is an option that means if the test fails, the test will be stopped.
Fatal = &opt{
fn: func(context *validator) *validator {
context.Fatal()
return context
},
}
)
Functions ¶
This section is empty.
Types ¶
type Context1 ¶ added in v0.2.0
type Context1[A any] struct { // contains filtered or unexported fields }
Context1 is a test context that allows for easy testing of values. This context contains only a single value and provides methods to test equality and differences.
func Execute ¶ added in v0.2.0
Execute creates a new context with the given value. Ideally, you'd just call the function you are testing directly: tests.Execute(struct.function()). This allows you to use the context methods to test the result: tests.Execute(struct.function()).Equal(t, expected).
func (*Context1[A]) Capture ¶ added in v0.2.0
func (ctx *Context1[A]) Capture() A
Capture returns the value.
func (*Context1[A]) Diff ¶ added in v0.2.0
Diff checks that the value is different from the given value.
func (*Context1[A]) Equal ¶ added in v0.2.0
Equal checks that the value is equal to the given value.
type Context1E ¶ added in v0.2.0
type Context1E struct {
// contains filtered or unexported fields
}
Context1E is a test context that allows for easy testing of errors. This context contains only a single error and provides methods to test for errors.
func ExecuteE ¶ added in v0.2.0
ExecuteE creates a new context with the given error. Ideally, you'd just call the function you are testing directly: tests.ExecuteE(struct.function()). This allows you to use the context methods to test the result: tests.ExecuteE(struct.function()).NoError(t).
func (*Context1E) ErrorCode ¶ added in v0.2.2
ErrorCode checks that the value is an error and has the expected error code.
func (*Context1E) MatchesError ¶ added in v0.2.0
MatchesError checks that the value is an error and matches the expected error.
type Context2 ¶ added in v0.2.0
type Context2[A, B any] struct { // contains filtered or unexported fields }
Context2 is a test context that allows for easy testing of two values. This context contains two values and provides methods to test equality and differences.
func Execute2 ¶ added in v0.2.0
Execute2 creates a new context with two values. Ideally, you'd just call the function you are testing directly: tests.Execute2(struct.function()). This allows you to use the context methods to test the result: tests.Execute2(struct.function()).Equal(t, expected).Equal(t, otherExpected).
This context contains two values and provides methods to test equality and differences.
Every method returns a new context with the same first value, allowing validates to be chained together.
func (*Context2[A, B]) Diff ¶ added in v0.2.0
Diff checks that the value is different from the given value.
func (*Context2[A, B]) Equal ¶ added in v0.2.0
Equal checks that the value is equal to the given value.
type Context2E ¶ added in v0.2.0
type Context2E[A any] struct { // contains filtered or unexported fields }
Context2E is a test context that allows for easy testing of a value and an error. This context contains a value and an error and provides methods to test equality and differences.
func Execute2E ¶ added in v0.2.0
Execute2E is a helper function that returns a new context with a value and an error. Ideally, you'd just call the function you are testing directly: tests.Execute2E(struct.function()). This allows you to use the context methods to test the result: tests.Execute2E(struct.function()).NoError(t).Equal(t, expected).
func (*Context2E[A]) ErrorCode ¶ added in v0.2.2
func (ctx *Context2E[A]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context1[A]
ErrorCode checks that the value is an error and has the expected error code.
func (*Context2E[A]) MatchesError ¶ added in v0.2.0
MatchesError checks that the value is an error and matches the expected error.
type Context3 ¶ added in v0.2.1
type Context3[A, B, C any] struct { // contains filtered or unexported fields }
Context3 is a test context that allows for easy testing of three values. This context contains three values and provides methods to test equality and differences.
func Execute3 ¶ added in v0.2.1
Execute3 creates a new context with the given values. Ideally, you'd just call the function you are testing directly: tests.Execute3(struct.function()). This allows you to use the context methods to test the result: tests.Execute3(struct.function()).Equal(t, expected).Equal(t, otherExpected).Equal(t, anotherExpected).
This context contains three values and provides methods to test equality and differences.
Every method returns a new context with the same first two values, allowing validates to be chained together.
func (*Context3[A, B, C]) Diff ¶ added in v0.2.1
Diff checks that the value is different from the given value.
func (*Context3[A, B, C]) Equal ¶ added in v0.2.1
Equal checks that the value is equal to the given value.
type Context3E ¶ added in v0.2.1
Context3E is a test context that allows for easy testing of two values and an error. This context contains two values and an error and provides methods to test equality and differences.
func Execute3E ¶ added in v0.2.1
Execute3E is a helper function that returns a new context with two values and an error. Ideally, you'd just call the function you are testing directly: tests.Execute3A(struct.function()). This allows you to use the context methods to test the result: tests.Execute3A(struct.function()).NoError(t).Equal(t, expected).Equal(t, expected).
func (*Context3E[A, B]) ErrorCode ¶ added in v0.2.2
func (ctx *Context3E[A, B]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context2[A, B]
ErrorCode checks that the value is an error and has the expected error code.
func (*Context3E[A, B]) MatchesError ¶ added in v0.2.1
func (ctx *Context3E[A, B]) MatchesError(t testing.TB, expected string, opts ...Opt) *Context2[A, B]
MatchesError checks that the value is an error and matches the expected error.
type DiffInterface ¶ added in v0.2.0
DiffInterface is an interface that allows for custom diff checks.
type EqualityInterface ¶ added in v0.2.0
EqualityInterface is an interface that allows for custom equality checks.