Documentation
¶
Index ¶
- Variables
- type AboutOption
- type Expect
- type Option
- type Test
- type Val
- func (e Val) First() Val
- func (e Val) Last() Val
- func (e Val) Message() Val
- func (e Val) NotToBe(unExpected interface{}) Val
- func (e Val) ToBe(expected interface{}) Val
- func (e Val) ToBeAbout(expected interface{}, opts ...AboutOption) Val
- func (e Val) ToBeSnapshot(path string) Val
- func (e Val) ToBeSnapshotImage(path string, opts ...Option) Val
- func (e Val) ToBeType(t any) Val
- func (e Val) ToContain(expected interface{}) Val
- func (e Val) ToCount(c int) Val
- func (e Val) ToHavePrefix(prefix string) Val
- func (e Val) ToHaveSuffix(suffix string) Val
Constants ¶
This section is empty.
Variables ¶
var ( PlainOutput = output("plain") ColoredDiffOutput = output("coloredDiffOutput") )
var Default = &Expect{ Output: PlainOutput, }
Functions ¶
This section is empty.
Types ¶
type AboutOption ¶ added in v0.14.0
type AboutOption func(*aboutConfig)
AboutOption configures the per-type tolerances used by ToBeAbout.
func DurationDelta ¶ added in v0.14.0
func DurationDelta(d time.Duration) AboutOption
DurationDelta sets the maximum allowed absolute difference for time.Duration leaves.
func FloatDelta ¶ added in v0.14.0
func FloatDelta(d float64) AboutOption
FloatDelta sets the maximum allowed absolute difference for float32/float64 leaves.
func IntDelta ¶ added in v0.14.0
func IntDelta(d int64) AboutOption
IntDelta sets the maximum allowed absolute difference for signed and unsigned integer leaves.
func TimeDelta ¶ added in v0.14.0
func TimeDelta(d time.Duration) AboutOption
TimeDelta sets the maximum allowed absolute difference for time.Time leaves. Times are compared by instant (a.Sub(b)), not field by field.
type Expect ¶
type Expect struct {
Output output
}
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithMatchTolerance ¶
WithMatchTolerance sets the maximum fraction of pixels that may differ while still accepting the image. 0 means no mismatches allowed. 1 means all mismatches allowed.
func WithPixelTolerance ¶
WithPixelTolerance sets the maximum allowed color difference for a pixel to be considered a match. 0 means exact match only. 1 means all pixels matched.
type Test ¶
type Test interface {
Fatalf(f string, i ...interface{})
Errorf(f string, i ...interface{})
Error(p ...interface{})
Helper()
}
Test implements testing.T methods used by expect. Necessary to: - allow usage of testing.T and testing.B instances - for running tests
type Val ¶
type Val struct {
// contains filtered or unexported fields
}
Val to call expectations on.
func Error ¶
Error wraps an error and provides expectations for this value. It delegates to the default instance `Default`.
func Value ¶
Value wraps a value and provides expectations for this value. It delegates to the default instance `Default`.
func (Val) Message ¶
Message creates a new value from the given errors message. If the error is nil the message wil be the empty string.
func (Val) ToBeAbout ¶
func (e Val) ToBeAbout(expected interface{}, opts ...AboutOption) Val
ToBeAbout asserts that the value deeply equals expected, like ToBe, except that numeric, time.Time and time.Duration leaves only need to be within the deltas given by the options. Every other leaf and the structural shape must still match exactly. Without options it behaves like an exact match.
Tolerances apply to top-level values and to values reachable through exported fields, slices, arrays and maps. Unexported leaves are compared exactly.
func (Val) ToBeSnapshot ¶
func (Val) ToBeSnapshotImage ¶
ToBeSnapshotImage saves the image in the first run, in later runs, compares the image to the saved one. If they are not the same it will write a .current.pn and .diff.png version of the image. The images match by default when 99% of the pixels colors are by less than 10% off. The Parameter SnapshotImageOptionExact forces the images to be exactly the same.
func (Val) ToContain ¶
ToContain checks if the expected value is in the expected slice or if the string contains a substring or not. Does a deep equal for slices.
func (Val) ToCount ¶
ToCount asserts that the list/map/chan/string has c elements. Strings use the number of unicode chars.
func (Val) ToHavePrefix ¶
ToHavePrefix asserts that the string value starts with the provided prefix.
func (Val) ToHaveSuffix ¶
ToHaveSuffix asserts that the string value ends with the provided sufix.