Documentation ¶
Overview ¶
Example ¶
package main import ( "testing" "github.com/thara/ggassert" ) func main() { t := new(testing.T) ggassert.Equal(t, 2, 2, "failed") // pass ggassert.Equal(t, 1, 2, "failed") // failed // ggassert.Equal(t, 1, "aaa", "failed") // compile error: default type string of "aaa" does not match inferred type int for T ggassert.LessThan(t, 1, 2, "failed") // pass ggassert.LessThan(t, 2, 2, "failed") // failed ggassert.LessThanOrEqual(t, 2, 2, "failed") // pass // ggassert.LessThanOrEqual(t, 2, 2.0, "failed") // compile error: default type float64 of 2.0 does not match inferred type int for T ggassert.GreaterThan(t, 2, 1, "failed") // pass ggassert.GreaterThan(t, 2, 2, "failed") // failed ggassert.GreaterThanOrEqual(t, 2, 2, "failed") // pass // ggassert.GreaterThanOrEqual(t, 2, 2.0, "failed") // compile error: default type float64 of 2.0 does not match inferred type int for T ggassert.ContainsSlice(t, []int{1, 2, 3}, 2, "failed") // pass ggassert.ContainsSlice(t, []int{1, 2, 3}, 4, "failed") // failed // ggassert.ContainsSlice(t, []int{1, 2, 3}, "aaa", "failed") // compile error: cannot use "aaa" (untyped string constant) as int value in argument to ggassert.ContainsSlice m := map[string]int{ "aaa": 111, "bbb": 222, "ccc": 333, } ggassert.ContainsMapKey(t, m, "aaa", "failed") // pass ggassert.ContainsMapKey(t, m, "ddd", "failed") // failed ggassert.ContainsMapValue(t, m, 111, "failed") // pass ggassert.ContainsMapValue(t, m, 444, "failed") // failed // ggassert.ContainsMapKey(t, m, 111, "failed") // compile error: cannot use 111 (untyped int constant) as string value in argument to ggassert.ContainsMapKey // ggassert.ContainsMapValue(t, m, "aaa", "failed") // compile error: cannot use "aaa" (untyped string constant) as int value in argument to ggassert.ContainsMapValue }
Output:
Index ¶
- func ContainsMapKey[K comparable, V any](t testing.TB, target map[K]V, expectedKey K, format string, args ...any)
- func ContainsMapValue[K, V comparable](t testing.TB, target map[K]V, expectedValue V, format string, args ...any)
- func ContainsSlice[T comparable](t testing.TB, s []T, expected T, format string, args ...any)
- func Equal[T any](t testing.TB, expected, actual T, format string, args ...any)
- func GreaterThan[T constraints.Ordered](t testing.TB, a, b T, format string, args ...any)
- func GreaterThanOrEqual[T constraints.Ordered](t testing.TB, a, b T, format string, args ...any)
- func LessThan[T constraints.Ordered](t testing.TB, a, b T, format string, args ...any)
- func LessThanOrEqual[T constraints.Ordered](t testing.TB, a, b T, format string, args ...any)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsMapKey ¶
func ContainsMapKey[K comparable, V any](t testing.TB, target map[K]V, expectedKey K, format string, args ...any)
ContainsMapKey asserts that the map contains the specified key.
func ContainsMapValue ¶
func ContainsMapValue[K, V comparable](t testing.TB, target map[K]V, expectedValue V, format string, args ...any)
ContainsMapValue asserts that the map contains the specified value.
func ContainsSlice ¶
func ContainsSlice[T comparable](t testing.TB, s []T, expected T, format string, args ...any)
ContainsSlice asserts that the slice contains the specified value.
func GreaterThan ¶
GreaterThan asserts that the first operand is greater than the second one
func GreaterThanOrEqual ¶
GreaterThanOrEqual asserts that the first operand is greater than or equal the second one
func LessThanOrEqual ¶
LessThanOrEqual asserts that the first operand is less than or equal the second one
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.