Documentation
¶
Index ¶
- type Result
- func BeDeepZero(t assert.Test, value any, msg ...any) Result
- func BeEmpty[T any](t assert.Test, slice []T, msg ...any) Result
- func BeEmptyString[T ~string](t assert.Test, value T, msg ...any) Result
- func BeError(t assert.Test, err, targetErr error, msg ...any) Result
- func BeErrorContaining(t assert.Test, err error, value string, msg ...any) Result
- func BeErrorNotContaining(t assert.Test, err error, value string, msg ...any) Result
- func BeFalse(t assert.Test, value bool, msg ...any) Result
- func BeGreater[T assert.Ordered](t assert.Test, value, other T, msg ...any) Result
- func BeGreaterBytes(t assert.Test, value, other []byte, msg ...any) Result
- func BeGreaterOrEqual[T assert.Ordered](t assert.Test, value, other T, msg ...any) Result
- func BeGreaterOrEqualBytes(t assert.Test, itemA, itemB []byte, msg ...any) Result
- func BeInArray(t assert.Test, array, item any, msg ...any) Result
- func BeInRange[T assert.Ordered](t assert.Test, item, min, max T, msg ...any) Result
- func BeLesser[T assert.Ordered](t assert.Test, value, other T, msg ...any) Result
- func BeLesserBytes(t assert.Test, value, other []byte, msg ...any) Result
- func BeLesserOrEqual[T assert.Ordered](t assert.Test, value, other T, msg ...any) Result
- func BeLesserOrEqualBytes(t assert.Test, itemA, itemB []byte, msg ...any) Result
- func BeLonger[T any](t assert.Test, slice, other []T, msg ...any) Result
- func BeLongerString[T ~string](t assert.Test, slice, other T, msg ...any) Result
- func BeNil(t assert.Test, value any, msg ...any) Result
- func BeNilError(t assert.Test, err error, msg ...any) Result
- func BeOfGreaterLen[T any](t assert.Test, slice []T, thresholdLen int, msg ...any) Result
- func BeOfGreaterOrEqualLen[T any](t assert.Test, slice []T, thresholdLen int, msg ...any) Result
- func BeOfLen[T any](t assert.Test, slice []T, targetLen int, msg ...any) Result
- func BeOfLesserLen[T any](t assert.Test, slice []T, thresholdLen int, msg ...any) Result
- func BeOfLesserOrEqualLen[T any](t assert.Test, slice []T, thresholdLen int, msg ...any) Result
- func BeOfSameLength[T any](t assert.Test, slice, other []T, msg ...any) Result
- func BeShorter[T any](t assert.Test, slice, other []T, msg ...any) Result
- func BeShorterString[T ~string](t assert.Test, value, other T, msg ...any) Result
- func BeStringOfGreaterOrEqualLen[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
- func BeStringOfLen[T ~string](t assert.Test, value T, targetLen int, msg ...any) Result
- func BeStringOfLenGreaterThan[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
- func BeStringOfLesserLen[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
- func BeStringOfLesserOrEqualLen[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
- func BeStringOfSameLength[T ~string](t assert.Test, value, other T, msg ...any) Result
- func BeTrue(t assert.Test, value bool, msg ...any) Result
- func BeZero[T comparable](t assert.Test, item T, msg ...any) Result
- func Contain[T comparable](t assert.Test, slice []T, item T, msg ...any) Result
- func ContainKey[K comparable, V any](t assert.Test, m map[K]V, key K, msg ...any) Result
- func ContainString[T ~string](t assert.Test, value, substr T, msg ...any) Result
- func DeepContain[T any](t assert.Test, slice []T, value T, msg ...any) Result
- func DeepEqual[T any](t assert.Test, value, other T, msg ...any) Result
- func Equal[T comparable](t assert.Test, value, other T, msg ...any) Result
- func EqualError(t assert.Test, err error, value string, msg ...any) Result
- func EqualWithinTolerance[T assert.Float](t assert.Test, value, other, tolerance T, msg ...any) Result
- func NewResult(t assert.Test, isPassing bool) Result
- func NotBeDeepZero(t assert.Test, value any, msg ...any) Result
- func NotBeEmpty[T any](t assert.Test, slice []T, msg ...any) Result
- func NotBeEmptyString[T ~string](t assert.Test, value T, msg ...any) Result
- func NotBeError(t assert.Test, err, targetErr error, msg ...any) Result
- func NotBeInArray(t assert.Test, array, item any, msg ...any) Result
- func NotBeInRange[T assert.Ordered](t assert.Test, item, min, max T, msg ...any) Result
- func NotBeNil(t assert.Test, value any, msg ...any) Result
- func NotBeNilError(t assert.Test, err error, msg ...any) Result
- func NotBeOfLen[T any](t assert.Test, slice []T, targetLen int, msg ...any) Result
- func NotBeOfSameLength[T any](t assert.Test, slice, other []T, msg ...any) Result
- func NotBeSameLengthString[T ~string](t assert.Test, value, other T, msg ...any) Result
- func NotBeStringOfLen[T ~string](t assert.Test, value T, targetLen int, msg ...any) Result
- func NotBeZero[T comparable](t assert.Test, item T, msg ...any) Result
- func NotContain[T comparable](t assert.Test, slice []T, item T, msg ...any) Result
- func NotContainKey[K comparable, V any](t assert.Test, m map[K]V, key K, msg ...any) Result
- func NotContainString[T ~string](t assert.Test, value, substr T, msg ...any) Result
- func NotDeepContain[T any](t assert.Test, slice []T, item T, msg ...any) Result
- func NotDeepEqual[T any](t assert.Test, value, other T, msg ...any) Result
- func NotEqual[T comparable](t assert.Test, value, other T, msg ...any) Result
- func NotEqualError(t assert.Test, err error, value string, msg ...any) Result
- func NotPanic(t assert.Test, closure func(), msg ...any) (result Result)
- func Panic(t assert.Test, closure func(), msg ...any) (result Result)
- func PanicWith(t assert.Test, closure func(), value any, msg ...any) (result Result)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result holds the result of a test condition.
func BeDeepZero ¶
BeDeepZero is asserting that a given value is the zero value for its kind.
It uses reflection to determine whether the value is zero. For comparable values it is preferable to use the should.BeZero, as it performs simple comparison using the '==' operator.
Example: var err error should.BeDeepZero(t, err, "err should be zero value")
func BeEmpty ¶
BeEmpty is asserting that the given slice holds no items.
Nil value is considered empty.
Example:
should.BeEmpty(t, []string{}, "should have 0 items")
func BeEmptyString ¶
BeEmptyString is asserting that the given string holds no characters.
Example: should.BeEmptyString(t, "", "should have 0 characters")
func BeError ¶
BeError is asserting that the given error is a target error.
The errors are compared using errors.Is, so any wrapped errors will work just fine. Example: should.BeError(t, baba(), ErrBabaIsNotYou, "operation baba should have failed with error 'ErrBabaIsNotYou'")
func BeErrorContaining ¶
BeErrorContaining is asserting that the given error is not a nil error and its value contains the provided value.
Example: should.BeErrorContaining(t, baba(), "baba", "operation baba should have failed with an error containing 'baba'")
func BeErrorNotContaining ¶
BeErrorNotContaining is asserting that the given error is not nil and its value does not contain the provided value.
Example: should.BeErrorNotContaining(t, baba(), "flag", "operation baba should have failed with an error not containing 'flag'")
func BeFalse ¶
BeFalse is asserting that the given value is not true.
Example: should.BeFalse(t, isActive, "user should not be active")
func BeGreater ¶
BeGreater is asserting that a given value is greater than another value.
Example: should.BeGreater(t, 10, 5, "10 should be greater than 5")
func BeGreaterBytes ¶
BeGreaterBytes is asserting that a given slice of bytes is greater lexicographically than another slice of bytes.
Example:
should.BeGreaterBytes(t, []byte("abc"), []byte("abb"), "first array should be greater lexicographically")
func BeGreaterOrEqual ¶
BeGreaterOrEqual is asserting that a given value is greater than or equal to another value.
Example: should.BeGreaterOrEqual(t, 5, 4, "5 should be greater or equal to 4")
func BeGreaterOrEqualBytes ¶
BeGreaterOrEqualBytes is asserting that a given slice of bytes is greater or equal lexicographically to another slice of bytes.
Example:
should.BeGreaterOrEqualBytes(t, []byte("abc"), []byte("abb"), "first should be greater or equal lexicographically")
func BeInArray ¶
BeInArray is asserting that the given array of items is containing an item.
Items are being compared using reflection by calling reflect.DeepEqual. array must be an array or a pointer to an array, otherwise the function panics.
Example:
should.BeInArray(t, [...]string{"baba", "is", "you"}, "is", "should contain 'is'")
func BeInRange ¶
BeInRange is asserting that a given value fits inclusively within a certain range.
Example: should.BeInRange(t, value, 0, 100, "value should be within range 0-100")
func BeLesser ¶
BeLesser is asserting that a given value is lesser than another value.
Example: should.BeLesser(t, 5, 10, "5 should be lesser than 10")
func BeLesserBytes ¶
BeLesserBytes is asserting that a given slice of bytes is lesser lexicographically than another slice of bytes.
Example:
should.BeLesserBytes(t, []byte("abb"), []byte("abc"), "first should be lesser lexicographically")
func BeLesserOrEqual ¶
BeLesserOrEqual is asserting that a given value is lesser or equal to another value.
Example: should.BeLesserOrEqual(t, 5, 7, "5 should be lesser than or equal to 7")
func BeLesserOrEqualBytes ¶
BeLesserOrEqualBytes is asserting that a given slice of bytes is lesser or equal lexicographically to another slice of bytes.
Example: should.BeLesserOrEqualBytes(t, babaData, otherData, "babaData should be lesser or equal lexicographically")
func BeLonger ¶
BeLonger is asserting that the given slice is of greater len than another slice.
Example:
should.BeLonger(t, []string{"baba", "is", "you"}, []string{"flag", "is"}, "should have more items")
func BeLongerString ¶
BeLongerString is asserting that the given string is of greater len than another string.
Example: should.BeLongerString(t, "baba is you", "flag is", "should have more characters")
func BeNil ¶
BeNil is asserting that a given value is nil.
Example: should.BeNil(t, value, "value should be nil")
func BeNilError ¶
BeNilError is asserting that the given error is nil.
Example: should.BeNilError(t, baba(), "operation baba should have passing without an error")
func BeOfGreaterLen ¶
BeOfGreaterLen is asserting that the given slice is of greater len than a certain threshold.
Example:
should.BeOfGreaterLen(t, []string{"baba", "is", "you"}, 2, "should have at least 3 items")
func BeOfGreaterOrEqualLen ¶
BeOfGreaterOrEqualLen is asserting that the given slice is of greater or equal len to a certain threshold.
Example:
should.BeOfGreaterOrEqualLen(t, []string{"baba", "is", "you"}, 3, "should have 3 or more items")
func BeOfLen ¶
BeOfLen is asserting that the given slice is of certain length.
Example:
should.BeOfLen(t, []string{"baba", "is", "you"}, 3, "should have 3 items")
func BeOfLesserLen ¶
BeOfLesserLen is asserting that the given slice is of lesser len than a certain threshold.
Example:
should.BeOfLesserLen(t, []string{"baba", "is", "you"}, 5, "should have less than 5 items")
func BeOfLesserOrEqualLen ¶
BeOfLesserOrEqualLen is asserting that the given slice is of lesser or equal len to a certain threshold.
Example:
should.BeOfLesserOrEqualLen(t, []string{"baba", "is", "you"}, 5, "should have less or equal to 5 items")
func BeOfSameLength ¶
BeOfSameLength is asserting that the given slice is of equal len to another slice.
Example:
should.BeOfSameLength(t, []string{"baba", "is", "you"}, []string{"flag", "is", "win"}, "should have equal len")
func BeShorter ¶
BeShorter is asserting that the given slice is of lesser len than another slice.
Example:
should.BeShorter(t, []string{"baba", "is"}, []string{"flag", "is", "win"}, "should have fewer items")
func BeShorterString ¶
BeShorterString is asserting that the given string is of lesser len than another string.
Example: should.BeShorterString(t, "baba is", "flag is win", "should have fewer characters")
func BeStringOfGreaterOrEqualLen ¶
func BeStringOfGreaterOrEqualLen[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
BeStringOfGreaterOrEqualLen is asserting that the given string is of greater or equal len to a certain threshold.
Example: should.BeStringOfGreaterOrEqualLen(t, "baba", 4, "should have 4 or more characters")
func BeStringOfLen ¶
BeStringOfLen is asserting that the given string is of certain length.
Example: should.BeStringOfLen(t, "baba is you", 11, "should have 11 characters")
func BeStringOfLenGreaterThan ¶
func BeStringOfLenGreaterThan[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
BeStringOfLenGreaterThan is asserting that the given string is of greater len than a certain threshold.
Example: should.BeStringOfLenGreaterThan(t, "baba", 3, "should have at least 4 characters")
func BeStringOfLesserLen ¶
BeStringOfLesserLen is asserting that the given string is of lesser len than a certain threshold.
Example: should.BeStringOfLesserLen(t, "baba is you", 12, "should have less than 12 characters")
func BeStringOfLesserOrEqualLen ¶
func BeStringOfLesserOrEqualLen[T ~string](t assert.Test, value T, thresholdLen int, msg ...any) Result
BeStringOfLesserOrEqualLen is asserting that the given string is of lesser or equal len to a certain threshold.
Example: should.BeStringOfLesserOrEqualLen(t, "baba is you", 11, "should have at most 11 characters")
func BeStringOfSameLength ¶
BeStringOfSameLength is asserting that the given string is of equal len to another string.
Example: should.BeOfSameLength(t, "baba is you", "flag is win", "should have equal len")
func BeTrue ¶
BeTrue is asserting that the given value is true.
Example: should.BeTrue(t, isActive, "user should be active")
func BeZero ¶
func BeZero[T comparable](t assert.Test, item T, msg ...any) Result
BeZero is asserting that a given value is the zero value for its kind.
Example: var num int should.BeZero(t, num, "num should be zero")
func Contain ¶
func Contain[T comparable](t assert.Test, slice []T, item T, msg ...any) Result
Contain is asserting that the given slice is containing an item.
Items are being compared using the '==' operator. For slices of non-comparable items use should.DeepContain. It relies on reflection to perform comparison on the items' values using reflect.DeepEqual.
Example:
should.Contain(t, []string{"baba", "is", "you"}, "is", "should contain 'is'")
func ContainKey ¶
ContainKey is asserting that the given map contains a certain key.
Example:
should.ContainKey(t, map[string]any{"baba": "is you"}, "baba", "should contain key 'baba'")
func ContainString ¶
ContainString is asserting that the given value is containing a substring.
Example: should.ContainString(t, "baba is you", "baba", "should contain 'baba'")
func DeepContain ¶
DeepContain is asserting that the given slice contains a deeply equal value.
Items are being compared using reflection by calling reflect.DeepEqual. For checking slices of items that are comparable it is preferable to use should.Contain which performs simple equality check using the '==' operator.
Example:
should.DeepContain(t, []any{"baba", "is", 5}, "is", "should contain 'is'")
func DeepEqual ¶
DeepEqual is asserting that the given values are deeply equal.
Items are being compared using reflect.DeepEqual. For items that are comparable is it preferable to use should.Equal, as it uses simple comparison with the '==' operator.
Example:
should.DeepEqual(t, nums, []any{"1", 2, 3}, "nums should be deeply equal to ["1", 2, 3]")
func Equal ¶
func Equal[T comparable](t assert.Test, value, other T, msg ...any) Result
Equal is asserting that the given values are equal.
Items are being compared using the '==' operator. For non-comparable values use should.DeepEqual, which uses reflection to compare the values of the items.
Example: should.Equal(t, sentence, "baba is you", "sentence should be equal to 'baba is you'")
func EqualError ¶
EqualError is asserting that the given error is not nil and its value is equal to the provided value.
Example: should.EqualError(t, baba(), "baba is not you", "operation baba should have failed with an error 'baba is not you'")
func EqualWithinTolerance ¶
func EqualWithinTolerance[T assert.Float](t assert.Test, value, other, tolerance T, msg ...any) Result
EqualWithinTolerance is asserting that a given float value is equal to another float value within a certain tolerance.
Example: should.EqualWithinTolerance(t, value, 5.2, 0.001, "value should be equal to 5.2 with tolerance of 0.001")
func NotBeDeepZero ¶
NotBeDeepZero is asserting that a given value is not the zero value for its kind.
It uses reflection to determine whether the value is zero. For comparable values it is
preferable to use the should.NotBeZero, as it performs simple comparison using the '==' operator.
Example:
err := errors,New("baba")
should.NotBeDeepZero(t, err, "err should not be zero value")
func NotBeEmpty ¶
NotBeEmpty is asserting that the given slice holds at least one item.
Example:
should.NotBeEmpty(t, []string{"baba"}, "should have at least 1 item")
func NotBeEmptyString ¶
NotBeEmptyString is asserting that the given string holds at least one character.
Example: should.NotBeEmptyString(t, "baba", "should have at least 1 character")
func NotBeError ¶
NotBeError is asserting that the given error is not a target error.
The errors are compared using errors.Is, so any wrapped errors will work just fine. Example: should.NotBeError(t, baba(), ErrBabaIsNotYou, "operation baba should have failed with error other than 'ErrBabaIsNotYou'")
func NotBeInArray ¶
NotBeInArray is asserting that the given array of items is not containing an item.
Items are being compared using reflection by calling reflect.DeepEqual. array must be an array or a pointer to an array, otherwise the function panics.
Example:
should.NotBeInArray(t, [...]string{"baba", "is", "you"}, "flag", "should not contain 'flag'")
func NotBeInRange ¶
NotBeInRange is asserting that a given value falls non-inclusively outside a certain range.
Example: should.NotBeInRange(t, value, 0, 100, "value should be outside of range 0-100")
func NotBeNil ¶
NotBeNil is asserting that a given value is not nil.
Example: should.NotBeNil(t, value, "value should not be nil")
func NotBeNilError ¶
NotBeNilError is asserting that the given error is not nil.
Example: should.NotBeNilError(t, baba(), "operation baba should have failed with an error")
func NotBeOfLen ¶
NotBeOfLen is asserting that the given slice is not of certain length.
Example:
should.NotBeOfLen(t, []string{"baba", "is", "you"}, 5, "should not have 5 items")
func NotBeOfSameLength ¶
NotBeOfSameLength is asserting that the given slice is not of equal len to another slice.
Example:
should.NotBeOfSameLength(t, []string{"baba", "is", "you"}, []string{"flag", "is"}, "should have different lengths")
func NotBeSameLengthString ¶
NotBeSameLengthString is asserting that the given string is not of equal len to another string.
Example: should.NotBeSameLengthString(t, "baba is you", "flag is", "should have different lengths")
func NotBeStringOfLen ¶
NotBeStringOfLen is asserting that the given string is not of certain length.
Example: should.NotBeStringOfLen(t, "baba is you", 5, "should not have 5 characters")
func NotBeZero ¶
func NotBeZero[T comparable](t assert.Test, item T, msg ...any) Result
NotBeZero is asserting that a given value is not the zero value for its kind.
Example: num := 5 should.NotBeZero(t, num, "num should not be zero")
func NotContain ¶
func NotContain[T comparable](t assert.Test, slice []T, item T, msg ...any) Result
NotContain is asserting that the given slice is not containing an item.
Items are being compared using the '==' operator. For slices of non-comparable items use should.NotDeepContain. It relies on reflection to perform comparison on the items' values using reflect.DeepEqual.
Example:
should.NotContain(t, []string{"baba", "is", "you"}, "flag", "should not contain 'flag'")
func NotContainKey ¶
NotContainKey is asserting that the given map does not contain a certain key.
Example:
should.NotContainKey(t, map[string]any{"baba": "is you"}, "flag", "should not contain key 'flag'")
func NotContainString ¶
NotContainString is asserting that the given value is not containing a substring.
Example: should.NotContainString(t, "baba is you", "flag", "should not contain 'baba'")
func NotDeepContain ¶
NotDeepContain is asserting that the given slice is not containing a deeply equal item.
Items are being compared using reflection by calling reflect.DeepEqual. For checking slices of items that are comparable it is preferable to use should.NotContain which performs simple equality check using the '==' operator.
Example:
should.NotDeepContain(t, []any{"baba", "is", 5}, "flag", "should not contain 'flag'")
func NotDeepEqual ¶
NotDeepEqual is asserting that the given values are not deeply equal.
Items are being compared using reflect.DeepEqual. For items that are comparable is it preferable to use should.NotEqual, as it uses simple comparison with the '==' operator.
Example:
should.NotDeepEqual(t, nums, []any{"1", 2, 3}, "nums should not be deeply equal to ["1", 2, 3]")
func NotEqual ¶
func NotEqual[T comparable](t assert.Test, value, other T, msg ...any) Result
NotEqual is asserting that the given values are not equal.
Items are being compared using the '==' operator. For non-comparable values use should.NotDeepEqual, which uses reflection to compare the values of the items.
Example: should.NotEqual(t, sentence, "baba is you", "sentence should not be equal to 'baba is you'")
func NotEqualError ¶
NotEqualError is asserting that the given error is not nil and its value is not equal to the provided value.
Example: should.NotEqualError(t, baba(), "baba is not you", "operation baba should have failed with error different from 'baba is not you'")
func NotPanic ¶
NotPanic is asserting that a given closure function will not panic.
Example:
closure := func () {}
should.NotPanic(t, closure, "closure function should not panic")
func Panic ¶
Panic is asserting that a given closure function will panic.
Example:
closure := func () {
panic("kaboom")
}
should.Panic(t, closure, "closure function should panic")
func PanicWith ¶
PanicWith is asserting that a given closure function will panic with specific value.
Example:
closure := func () {
panic("kaboom")
}
should.PanicWith(t, closure, "kaboom", "closure function should panic with 'kaboom'")
func (Result) IsPassing ¶
IsPassing returns a boolean stating whether the test condition was successful or not.
func (Result) OtherwiseBail ¶
func (r Result) OtherwiseBail()
OtherwiseBail will cause the current test to fail immediately and will prevent any later test conditions from executing.