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 values.
func FloatDelta ¶ added in v0.14.0
func FloatDelta(d float64) AboutOption
FloatDelta sets the maximum allowed absolute difference for float32 and float64 values. NaN never matches, as in ToBe.
func IntDelta ¶ added in v0.14.0
func IntDelta(d int64) AboutOption
IntDelta sets the maximum allowed absolute difference for integers of every size: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32 and uint64. Named integer types such as enums get the delta too: with IntDelta(5), time.June matches time.January. The exceptions are time.Duration, which uses DurationDelta, and uintptr, which is compared exactly since it holds addresses and handles.
func TimeDelta ¶ added in v0.14.0
func TimeDelta(d time.Duration) AboutOption
TimeDelta sets the maximum allowed absolute difference for time.Time values. Times are then compared by instant (a.Sub(b)), so location and monotonic clock reading are ignored, even with a delta of 0. Without it, times are compared like ToBe does.
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, exactly like ToBe, except that values of a type given as an option only need to be within its delta. Deltas apply to the value itself, to exported fields and to the elements of slices, arrays and maps, at any depth and through pointers and interfaces. Only a value held by an unexported field is 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.