Documentation ¶
Index ¶
- func ConvertibleTo[T any](t testers.Tester) (c testers.Check[any])
- func DescendingSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
- func Empty(t testers.Tester) (c testers.Check[any])
- func EndsWith(t testers.Tester, expected any) (c testers.Check[any])
- func Epsilon[T utils.NumConstraint](t testers.Tester, expected, epsilon T) (c testers.Check[T])
- func Equal[T any](t testers.Tester, expected T) (c testers.Check[T])
- func EqualElems(t testers.Tester, expected any) (c testers.Check[any])
- func ErrorHas[T any](t testers.Tester) (c testers.Check[error])
- func Excludes(t testers.Tester, unexpected any) (c testers.Check[any])
- func False(t testers.Tester) (c testers.Check[bool])
- func GreaterEq[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func GreaterThan[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func HasKeys[M ~map[TKey]TValue, TKey comparable, TValue any](t testers.Tester, expected ...TKey) (c testers.Check[M])
- func HasValues[M ~map[TKey]TValue, TKey, TValue comparable](t testers.Tester, expected ...TValue) (c testers.Check[M])
- func Implements[T any](t testers.Tester) (c testers.Check[any])
- func InRange[T any](t testers.Tester, minValue, maxValue T, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func Includes(t testers.Tester, expected any) (c testers.Check[any])
- func Intersects(t testers.Tester, expected any) (c testers.Check[any])
- func Is[T any](t testers.Tester, p collections.Predicate[T]) (c testers.Check[T])
- func IsNot[T any](t testers.Tester, p collections.Predicate[T]) (c testers.Check[T])
- func Length(t testers.Tester, expected int) (c testers.Check[any])
- func LessEq[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func LessThan[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func LongerThan(t testers.Tester, expected int) (c testers.Check[any])
- func Match(t testers.Tester, regex any) (c testers.Check[any])
- func MatchError(t testers.Tester, regex any) (c testers.Check[error])
- func Negative[T any](t testers.Tester, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func Nil(t testers.Tester) (c testers.Check[any])
- func NoError(t testers.Tester) (c testers.Check[error])
- func NotDescendingSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
- func NotEmpty(t testers.Tester) (c testers.Check[any])
- func NotEpsilon[T utils.NumConstraint](t testers.Tester, unexpected, epsilon T) (c testers.Check[T])
- func NotEqual[T any](t testers.Tester, unexpected T) (c testers.Check[T])
- func NotNil(t testers.Tester) (c testers.Check[any])
- func NotSame[T comparable](t testers.Tester, expected T) (c testers.Check[T])
- func NotSameType(t testers.Tester, unexpected any) (c testers.Check[any])
- func NotSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
- func NotType[T any](t testers.Tester) (c testers.Check[any])
- func NotUnique[TElem comparable](t testers.Tester) (c testers.Check[any])
- func NotZero(t testers.Tester) (c testers.Check[any])
- func OneOf(t testers.Tester, expected any) (c testers.Check[any])
- func Positive[T any](t testers.Tester, comparer ...comp.Comparer[T]) (c testers.Check[T])
- func Same[T comparable](t testers.Tester, expected T) (c testers.Check[T])
- func SameElems(t testers.Tester, expected any) (c testers.Check[any])
- func SameType(t testers.Tester, expected any) (c testers.Check[any])
- func ShorterThan(t testers.Tester, expected int) (c testers.Check[any])
- func Single(t testers.Tester) (c testers.Check[any])
- func Sorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
- func StartsWith(t testers.Tester, expected any) (c testers.Check[any])
- func String(t testers.Tester, expected string) (c testers.Check[any])
- func StringAndReset(t testers.Tester, expected string) (c testers.Check[any])
- func True(t testers.Tester) (c testers.Check[bool])
- func Type[T any](t testers.Tester) (c testers.Check[any])
- func Unique[TElem comparable](t testers.Tester) (c testers.Check[any])
- func Zero(t testers.Tester) (c testers.Check[any])
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertibleTo ¶
ConvertibleTo creates a check that the actual value is conversable to the given expected type.
Example: check.ConvertibleTo[int](t).Assert(actual)
func DescendingSorted ¶
func DescendingSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
DescendingSorted creates a check that the actual collection of values is sorted on descending order.
This may take an optional comparer. The given type parameter is the type of elements in the actual value that are being compared.
Example: check.DescendingSorted(t).Assert(actual)
func Empty ¶
Empty creates a check that the length of the actual value is zero.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.IsEmpty(t).Assert(actual)
func EndsWith ¶
EndsWith creates a check that the given expected string or array is the suffix for the actual object.
Example: `check.EndsWith(t, "foo").Assert(actual)` Example: `check.EndsWith(t, []int{3, 4, 5}).Assert(actual)`
func Epsilon ¶
Epsilon creates a check that the actual value is equal to the given expected value or very close to the given expected value. The value must be within the given epsilon to be considered equal.
The given epsilon must be greater than zero. An epsilon comparator should be used when comparing calculated floating point numbers since calculations may accrue small errors and make the actual value very close to the expected value but not exactly equal.
Example: check.Epsilon(t, 14.0, 1.0e-9).Assert(actual)
func Equal ¶
Equal creates a check that the given expected value is equal to an actual value.
This uses `utils.Equal` for the comparison.
Example: `check.Equal(t, 42).Assert(actual)`
func EqualElems ¶
EqualElems creates a check that the actual slice contains all of the given expected elements and no others in any order while ignoring repeats.
This doesn't check number of occurrences in the actual slice meaning that multiple expected elements has no effect and will simply match the same value in the slice.
If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.EqualElems(t, []int{3, 7, 10}).Assert(actual)
func ErrorHas ¶
ErrorHas creates a check that the given error type is contained within the error tree of the actual error.
This uses errors `As` method to find the contained type.
Example: check.ErrorHas[Stacked](t).Assert(actual)
func Excludes ¶
Excludes creates a check that the actual collection of values does not contain any of the given unexpected values.
There must be at least one unexpected element. If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.Excludes(t, []int{3, 7, 10}).Assert(actual)
func False ¶
False creates a check that the actual boolean value is false.
Example: check.False(t).Assert(actual)
func GreaterEq ¶
func GreaterEq[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
GreaterEq creates a check that the actual value is greater than or equal to the given expected value.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.GreaterEq(t, 14).Assert(actual)
func GreaterThan ¶
func GreaterThan[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
GreaterThan creates a check that the actual value is greater than the given expected value.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.GreaterThan(t, 14).Assert(actual)
func HasKeys ¶
func HasKeys[M ~map[TKey]TValue, TKey comparable, TValue any](t testers.Tester, expected ...TKey) (c testers.Check[M])
HasKeys creates a check that the actual map contains all of the given expected keys.
There must be at least one expected key.
Example: check.HasKeys[map[string]int](t, `Name`, `Pet`, `Car`).Assert(actual)
func HasValues ¶
func HasValues[M ~map[TKey]TValue, TKey, TValue comparable](t testers.Tester, expected ...TValue) (c testers.Check[M])
HasValues creates a check that the actual map contains all of the given expected values.
There must be at least one expected key. This doesn't check number of occurrences in the actual map meaning that multiple expected values has no effect and will simply match the same value in the map.
Example: check.HasValues[map[string]int](t, 4, 5, 6).Assert(actual)
func Implements ¶
Implements creates a check that the actual value implements the given type.
The given target type must be an interface.
Example: check.Implements[Stringer](t).Assert(actual)
func InRange ¶
func InRange[T any](t testers.Tester, minValue, maxValue T, comparer ...comp.Comparer[T]) (c testers.Check[T])
InRange creates a check that the actual value is between the given min and maximum inclusively.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: InRange.LessEq(t, 0, 359).Assert(actual)
func Includes ¶
Includes creates a check that the actual collection of values contains all of the given expected values.
There must be at least one expected element. This doesn't check number of occurrences in the actual slice meaning that multiple expected elements has no effect and will simply match the same value in the slice.
If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.Contains(t, []int{3, 7, 10}).Assert(actual)
func Intersects ¶
Intersects creates a check that the actual collection of values contains at least one of the given expected values.
There must be at least one expected element. If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.Intersects(t, []int{3, 7, 10}).Assert(actual)
func Is ¶
Is creates a check that the actual value causes the given predicate to return true.
Example: check.Is(t, func(x thing) bool { return thing.Valid() }).Assert(actual)
func IsNot ¶
IsNot creates a check that the actual value causes the given predicate to return false.
Example: check.IsNot(t, func(x thing) bool { return thing.Valid() }).Assert(actual)
func Length ¶
Length creates a check that the length of the actual value is equal to the given expected length.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.Length(t, 5).Assert(actual)
func LessEq ¶
LessEq creates a check that the actual value is less than or equal to the given expected value.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.LessEq(t, 14).Assert(actual)
func LessThan ¶
func LessThan[T any](t testers.Tester, expected T, comparer ...comp.Comparer[T]) (c testers.Check[T])
LessThan creates a check that the actual value is less than the given expected value.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.LessThan(t, 14).Assert(actual)
func LongerThan ¶
LongerThan creates a check that the length of the actual value is longer than the given expected length.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.LongerThan(t, 5).Assert(actual)
func Match ¶
Match creates a check that the given expected regular expression matches the actual string.
The given pattern must be a string or a `*regexp.Regexp` instance. This uses `utils.String` to get the string from the actual value.
Example: `check.Match(t, "^\w+$").Assert(actual)`
func MatchError ¶
MatchError creates a check that the given expected regular expression matches the actual error's Error() string.
Example: check.MatchError(t, `^\w+$`).Assert(actual)
func Negative ¶
Negative creates a check that the actual value is less than zero.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.Negative(t).Assert(actual)
func Nil ¶
Nil creates a check that the actual type is nil.
The actual value must a type which can be nil.
Example: check.Nil(t).Assert(actual)
func NoError ¶
NoError creates a check that the actual error is not nil.
Example: check.NoError(t).Assert(actual)
func NotDescendingSorted ¶
func NotDescendingSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
NotDescendingSorted creates a check that the actual collection of values is not sorted in descending order.
This may take an optional comparer. The given type parameter is the type of elements in the actual value that are being compared.
Example: check.NotDescendingSorted(t).Assert(actual)
func NotEmpty ¶
NotEmpty creates a check that the length of the actual value is not zero.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.IsNotEmpty(t).Assert(actual)
func NotEpsilon ¶
func NotEpsilon[T utils.NumConstraint](t testers.Tester, unexpected, epsilon T) (c testers.Check[T])
NotEpsilon creates a check that the actual value is not equal to the given unexpected value and not very close to the given unexpected value. The value must not be within the given epsilon to be considered not equal.
The given epsilon must be greater than zero. An epsilon comparator should be used when comparing calculated floating point numbers since calculations may accrue small errors and make the actual value very close to the expected value but not exactly equal.
Example: check.NotEpsilon(t, 14.0, 1.0e-9).Assert(actual)
func NotEqual ¶
NotEqual creates a check that the given expected value is not equal to an actual value.
This uses `utils.Equal` for the comparison.
Example: `check.NotEqual(t, 42).Assert(actual)`
func NotNil ¶
NotNil creates a check that the actual type is not nil.
The actual value must a type which can be nil.
Example: check.NotNil(t).Assert(actual)
func NotSame ¶
func NotSame[T comparable](t testers.Tester, expected T) (c testers.Check[T])
NotSame creates a check that the given expected type is not equal to the actual type using the `==` comparison. This can be used to ensure that two pointers point to different objects.
Example: check.NotSame(t, expected).Assert(actual)
func NotSameType ¶
NotSameType creates a check that the actual value is not the same type as the unexpected type.
Example: check.NotSameType(t, 3.2).Assert(actual)
func NotSorted ¶
func NotSorted[TElem any](t testers.Tester, comparer ...comp.Comparer[TElem]) (c testers.Check[any])
NotSorted creates a check that the actual collection of values is not sorted.
This may take an optional comparer. The given type parameter is the type of elements in the actual value that are being compared.
Example: check.NotSorted(t).Assert(actual)
func NotType ¶
NotType creates a check that the actual value is not the given type.
Example: check.Type[int](t).Assert(actual)
func NotUnique ¶
NotUnique creates a check that the actual collection does not have all unique values.
Example: check.NotUnique(t).Assert(actual)
func NotZero ¶
NotZero creates a check that the actual value is not the zero value of that type.
Example: check.NotZero(t).Assert(actual)
func OneOf ¶
OneOf creates a check that the actual value is one of the values in the given expected values.
There must be at least one expected element. If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.OneOf(t, []int{3, 7, 10}).Assert(actual)
func Positive ¶
Positive creates a check that the actual value is greater than zero.
May provide one optional comparer to use for this check. If the type being checked does not have a default comparer, then a comparer for that type must be provided.
Example: check.Positive[int](t).Assert(actual)
func Same ¶
func Same[T comparable](t testers.Tester, expected T) (c testers.Check[T])
Same creates a check that the given expected type is equal to the actual type using the `==` comparison. This can be used to ensure that two pointers point to the same object.
Example: check.Same(t, expected).Assert(actual)
func SameElems ¶
SameElems creates a check that the actual slice contains all of the given expected elements and no others in any order and in the same number. The types being compared to not need to match but the elements do.
There must be at least one expected element. This doesn't check number of occurrences in the actual slice meaning that multiple expected elements has no effect and will simply match the same value in the slice.
If a map is given to either the expected or actual values. The values being matched will be key/value tuples.
Example: check.HasElems(t, []int{3, 7, 10}).Assert(actual)
func SameType ¶
SameType creates a check that the actual value is the same type as the expected type.
Example: check.SameType(t, 3.2).Assert(actual)
func ShorterThan ¶
ShorterThan creates a check that the length of the actual value is shorter than the given expected length.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.ShorterThan(t, 5).Assert(actual)
func Single ¶
Single creates a check that the length of the actual value is one.
This requires that the actual value is a string, slice, array, map, or anything that has a Len, Length, or Count method.
Example: check.Single(t).Assert(actual)
func Sorted ¶
Sorted creates a check that the actual collection of values is sorted.
This may take an optional comparer. The given type parameter is the type of elements in the actual value that are being compared.
Example: check.Sorted(t).Assert(actual)
func StartsWith ¶
StartsWith creates a check that the given expected string or array is the prefix for the actual object.
Example: `check.StartsWith(t, "foo").Assert(actual)` Example: `check.StartsWith(t, []int{3, 4, 5}).Assert(actual)`
func String ¶
String creates a check that the given expected string is the same of the string from the actual object.
This uses `utils.String` to get the string.
Example: `check.String(t, "foo").Assert(actual)`
func StringAndReset ¶
StringAndReset creates a check that the given expected string is the same of the string from the actual object then calls `Reset` on the actual object if it exists.
This uses `utils.String` to get the string. This is designed to work with `bytes.Buffer` so that a buffer can be used to collect changes, event, calls, etc then checked that those occurred. Resetting the buffer prepares it for the next collection of changes, etc.
Example: `check.StringAndReset(t, "foo").Assert(actual)`
func True ¶
True creates a check that the actual boolean value is true.
Example: check.True(t).Assert(actual)
func Type ¶
Type creates a check that the actual value is the given type.
Example: check.Type[int](t).Assert(actual)
Types ¶
This section is empty.