Documentation
¶
Index ¶
- func DedentLines(s string) string
- func DeepEqualTo[T any](got, want T, opts ...DeepEqualOpt) expect.Expectation
- func EqualTo[T comparable](got, want T) expect.Expectation
- func EqualToStringByLines(got, want string, transformers ...func(string) string) expect.Expectation
- func Error(got, target error) expect.Expectation
- func MapContaining[T ~map[K]V, K, V comparable](got T, key K, val V) expect.Expectation
- func MapOfLen[T ~map[K]V, K comparable, V any](got T, want int) expect.Expectation
- func NoError(v error) expect.Expectation
- func SliceContaining[S ~[]T, T comparable](v S, wants ...T) expect.Expectation
- func SliceContainingInOrder[S ~[]T, T comparable](v S, wants ...T) expect.Expectation
- func SliceOfLen[T ~[]S, S any](v T, want int) expect.Expectation
- func StringContaining(got, want string) expect.Expectation
- func StringOfLen(got string, want int) expect.Expectation
- func StringWithPrefix(got, want string) expect.Expectation
- func StringWithSuffix(got, want string) expect.Expectation
- type DeepEqualOpt
- type ExcludeFields
- type ExcludeTypes
- type ExcludeUnexportedStructFields
- type FloatPrecision
- type NilMapsAreEmpty
- type NilSlicesAreEmpty
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DedentLines ¶ added in v0.6.0
Dedent is intended to be used as a transformer passed to EqualToStringByLines. It removes any prefix whitespace from s thus dedenting each line. This is especially usefull if the expected value for a test is written in code as an indented multiline raw string literal but the actual lines are not indented.
func DeepEqualTo ¶
func DeepEqualTo[T any](got, want T, opts ...DeepEqualOpt) expect.Expectation
IsDeepEqualTo asserts that given and wanted value are deeply equal by using reflection to inspect and dive into nested structures.
func EqualTo ¶
func EqualTo[T comparable](got, want T) expect.Expectation
EqualTo asserts that given and wanted are equal in terms of the go equality operator. Thus, it works only on types that satisfy comparable.
func EqualToStringByLines ¶ added in v0.4.0
func EqualToStringByLines(got, want string, transformers ...func(string) string) expect.Expectation
EqualToStringByLines compares got and want line by line and reports different lines one at a time. This makes it easiert to understand failed expectations when comparing large strings.
transformers are applied to all lines, both those obtained from got and want. transformers are applied in order (iteratively) and the final transformation result is used for comparison.
func Error ¶
func Error(got, target error) expect.Expectation
Error matches got to contain target in its chain. The check is performed using errors.Is. A special case happens when target is nil. In this case, Error behaves identical to NoError. This improves testing convenience when writing table based tests that test on both error and non error conditions.
func MapContaining ¶
func MapContaining[T ~map[K]V, K, V comparable](got T, key K, val V) expect.Expectation
MapContaining expects got to contain key with value val.
func MapOfLen ¶
func MapOfLen[T ~map[K]V, K comparable, V any](got T, want int) expect.Expectation
MapOfLen expects got to contain want elements.
func SliceContaining ¶
func SliceContaining[S ~[]T, T comparable](v S, wants ...T) expect.Expectation
SliceContaining expects got to be a slice of element type T contain all values given as wants in any order. Duplicates in wants are not considered to be contained multiple times in the given slice.
func SliceContainingInOrder ¶
func SliceContainingInOrder[S ~[]T, T comparable](v S, wants ...T) expect.Expectation
SliceContainingInOrder expects go to be a slice with element type T containing all values given as wants in the same order they are given as wants.
func SliceOfLen ¶
func SliceOfLen[T ~[]S, S any](v T, want int) expect.Expectation
SliceOfLen create an expect.Expectation that expects len(v) == want.
func StringContaining ¶
func StringContaining(got, want string) expect.Expectation
StringContaining expects got to be a string containing want as a substring.
func StringOfLen ¶
func StringOfLen(got string, want int) expect.Expectation
StringOfLen expects got to have byte length want.
func StringWithPrefix ¶
func StringWithPrefix(got, want string) expect.Expectation
StringWithPrefix expects got to be a string having prefix want.
func StringWithSuffix ¶
func StringWithSuffix(got, want string) expect.Expectation
StringWithSuffix expects got to be a string having suffix want.
Types ¶
type DeepEqualOpt ¶
type DeepEqualOpt interface {
// contains filtered or unexported methods
}
DeepEqualOpt defines an interface for types that can be used as options for the DeepEqual matcher.
type ExcludeFields ¶
type ExcludeFields []string
ExcludeFields is a DeepEqualOpt that lists field patterns that should be excluded from the comparison.
The field pattern format uses a dot notation and follows the format used in comparison output. The wildcard '*' can be used to match any value (i.e. for slice indexes).
type ExcludeTypes ¶
ExcludeTypes is a DeepEqualOpt that lists types to be ignored from the comparison. Each struct field with a type listed in ExcludeTypes will not be taken into account when calculating differences.
type ExcludeUnexportedStructFields ¶
type ExcludeUnexportedStructFields bool
ExcludeUnexportedStructFields is a DeepEqualOpt that defines whether unexported struct fields should be excluded from the equality check or not.
type FloatPrecision ¶
type FloatPrecision uint
FloatPrecision is a DeepEqualOpt that customizes the float comparison behavior. The number given defines the number of significant floating point digits.
type NilMapsAreEmpty ¶
type NilMapsAreEmpty bool
NilMapsAreEmpty is a DeepEqualOpt that defines whether nil maps are treated as empty ones or differently.
type NilSlicesAreEmpty ¶
type NilSlicesAreEmpty bool
NilSlicesAreEmpty is a DeepEqualOpt that defines whether nil slices are treated as empty ones or differently.