Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefaultTheme ¶
func InitDefaultTheme(t Theme)
InitDefaultTheme sets the default theme, typically during init(). Calls to this function outside of init() are unsupported and may panic or produce unexpected results.
If this is not called, the default theme uses:
- actual:
- when failed: red
- when passed: green
- expected: green - desc: default fmt.Sprint - extra: yellow, prefixed with '\nDetail: '
Types ¶
type Comparison ¶
type Comparison struct {
// contains filtered or unexported fields
}
Comparison is a result comparing two values. This is the most common type of result.
func Compare ¶
func Compare(matched bool, actual any, comparison string, expected any) Comparison
Compare returns a Comparison, comparing an actual to an expected.
The comparison param should be a human-readable description of how the values were compared. For example, Compare(true, "foo", "==", "foo") to show that "foo" successfully equaled "foo".
func (Comparison) Describe ¶
func (c Comparison) Describe(ctx context.Context, passed bool) string
Describe returns a description of c. The passed param describes whether or not the top-level assertion passed.
func (Comparison) Matched ¶
func (c Comparison) Matched() bool
Matched returns whether or not c describes a failure.
type CondSprinter ¶
CondSprinter is a type which can conditionally print using either a failed printer or a passed printer. This is useful for outputting results during passing tests, to make it clear that the value did _not_ fail.
type DescribedResult ¶
type DescribedResult struct {
// contains filtered or unexported fields
}
DescribedResult adds extra information to a Result.
func Describe ¶
func Describe(r Result, desc string) DescribedResult
Describe returns a DescribedResult with extra context describing the assertion result.
func (DescribedResult) Describe ¶
func (r DescribedResult) Describe(ctx context.Context, passed bool) string
Describe describes the result, passing the wrapped
func (DescribedResult) Matched ¶
func (r DescribedResult) Matched() bool
Matched returns the original Result's matched status.
type ManyOption ¶ added in v0.0.5
type ManyOption func(ManyResult) ManyResult
ManyOption is an option type for customizing a ManyResult.
func ChildPrefix ¶ added in v0.0.5
func ChildPrefix(pfx string) ManyOption
ChildPrefix returns an option to use pfx as a prefix for each child's description.
type ManyResult ¶ added in v0.0.5
type ManyResult struct {
// contains filtered or unexported fields
}
ManyResult wraps multiple child results.
func Many ¶ added in v0.0.5
func Many(name string, results []Result, opts ...ManyOption) ManyResult
Many returns a ManyResult wrapping up multiple results.
func (ManyResult) Describe ¶ added in v0.0.5
func (r ManyResult) Describe(ctx context.Context, passed bool) string
Describe returns a description of the child results.
When passed == false and any of r's children return Matched() == false, Describe will only describe failing matches.
Otherwise (i.e. all of r's children return Matched() == true or passed == true), Describe will include every child description.
func (ManyResult) Matched ¶ added in v0.0.5
func (r ManyResult) Matched() bool
Matched returns true if all of r's children also return true. It returns false if any of them returned false.
type PrefixSprinter ¶
PrefixSprinter wraps up a Sprinter with a prefix that needs to be printed first.
type SimpleResult ¶
type SimpleResult struct {
// contains filtered or unexported fields
}
SimpleResult is a simple result, wrapping up a matched boolean, an actual value, and a description.
func Simple ¶
func Simple(matched bool, actual any, desc string) SimpleResult
Simple returns a SimpleResult wrapping matched and desc.
func Simplef ¶
func Simplef(matched bool, actual any, desc string, args ...any) SimpleResult
Simplef returns a SimpleResult wrapping matched and a fmt.Sprintf of the desc and args.
func (SimpleResult) Describe ¶
func (r SimpleResult) Describe(ctx context.Context, passed bool) string
Describe returns a description of this result.
func (SimpleResult) Matched ¶
func (r SimpleResult) Matched() bool
Matched returns whether or not r is marked as matched.
type SimpleSprinter ¶
SimpleSprinter wraps a simple Sprint-style function to use for printing values.
type Sprinter ¶
Sprinter is a type which can take the failure status of a result and a value value and return a string that should be printed.
type Theme ¶
type Theme struct { // Actual will be used to print out the Actual value for results which have // access to the actual. Actual Sprinter // Desc will be used to print out the description of the result. Desc Sprinter // Expected will be used to print out what the value was expected to be for // results which have access to an expected value. Expected Sprinter // Extra will be used to print out any extra information, like additional // context added to the assertion via output options. Extra Sprinter }
Theme is used when describing assertions in output.
func CtxTheme ¶
CtxTheme returns the Theme attached to ctx. If no Theme is attached, CtxTheme returns DefaultTheme.
func DefaultTheme ¶ added in v0.0.4
func DefaultTheme() Theme
DefaultTheme returns a copy of the current default theme. Since this is a copy, it's safe to change fields without directly changing the default theme.
type WrapOption ¶
type WrapOption func(WrappedResult) WrappedResult
WrapOption is an option function for wrapping up a child result.
func WrapDescribe ¶
WrapDescribe wraps up a child result with a describe function, to add extra detail to the child result's description.
func WrapMatched ¶
func WrapMatched(f func(bool) bool) WrapOption
WrapMatched wraps up a child result with a matched function, to conditionally change the failure.
type WrappedResult ¶
type WrappedResult struct {
// contains filtered or unexported fields
}
WrappedResult is a complex result that needs to wrap another result with extra context about how an actual value was compared. This is mostly used for wrapped matchers to describe how an actual was retrieved.
func Wrap ¶
func Wrap(r Result, opts ...WrapOption) WrappedResult
Wrap wraps up a result using opts to manipulate the final result.
func (WrappedResult) Describe ¶
func (r WrappedResult) Describe(ctx context.Context, passed bool) string
Describe returns a description of the result by passing the original result's description to the describe wrapper function. If there is no describe wrapper, it returns the original result's Describe().
func (WrappedResult) Matched ¶
func (r WrappedResult) Matched() bool
Matched returns the result of passing the original result's Matched() value to the matched wrapper function. If there is no matched wrapper, it returns the original result's Matched().