Documentation ¶
Index ¶
- Variables
- func C[T any](t testing.TB, v any) T
- func Cast[T any](t testing.TB, v any) T
- func Equal[T any](t testing.TB, actual T, expected T)
- func ErrorAs[T any](t testing.TB, actual error, callback func(expect *T))
- func NotEqual[T any](t testing.TB, actual T, expected T)
- type ArrayTest
- func (x ArrayTest[T]) All(f func(v T) bool) ArrayTest[T]
- func (x ArrayTest[T]) Any(f func(v T) bool) ArrayTest[T]
- func (x ArrayTest[T]) At(idx int, f func(t testing.TB, v T)) ArrayTest[T]
- func (x ArrayTest[T]) Contain(expect []T) ArrayTest[T]
- func (x ArrayTest[T]) Distinct() ArrayTest[T]
- func (x ArrayTest[T]) Equal(expect []T) ArrayTest[T]
- func (x ArrayTest[T]) EqualAt(idx int, expect T) ArrayTest[T]
- func (x ArrayTest[T]) Have(expect T) ArrayTest[T]
- func (x ArrayTest[T]) Length(expect int) ArrayTest[T]
- func (x ArrayTest[T]) Less(expect int) ArrayTest[T]
- func (x ArrayTest[T]) Longer(expect int) ArrayTest[T]
- func (x ArrayTest[T]) MatchThen(match func(v T) bool, then func(t testing.TB, v T)) ArrayTest[T]
- func (x ArrayTest[T]) Must() ArrayTest[T]
- func (x ArrayTest[T]) NotContain(expect []T) ArrayTest[T]
- func (x ArrayTest[T]) NotEqual(expect []T) ArrayTest[T]
- func (x ArrayTest[T]) NotEqualAt(idx int, expect T) ArrayTest[T]
- func (x ArrayTest[T]) NotHave(expect T) ArrayTest[T]
- type BoolTest
- type ErrorTest
- type MapTest
- func (x MapTest[K, V]) At(key K, f func(t testing.TB, v V)) MapTest[K, V]
- func (x MapTest[K, V]) Equal(expect map[K]V) MapTest[K, V]
- func (x MapTest[K, V]) EqualAt(key K, expect V) MapTest[K, V]
- func (x MapTest[K, V]) HaveKey(expect K) MapTest[K, V]
- func (x MapTest[K, V]) HaveKeyValue(expectKey K, expectValue V) MapTest[K, V]
- func (x MapTest[K, V]) HaveValue(expect V) MapTest[K, V]
- func (x MapTest[K, V]) Length(expect int) MapTest[K, V]
- func (x MapTest[K, V]) Must() MapTest[K, V]
- func (x MapTest[K, V]) NotEqual(expect map[K]V) MapTest[K, V]
- func (x MapTest[K, V]) NotEqualAt(key K, expect V) MapTest[K, V]
- func (x MapTest[K, V]) NotHaveKey(expect K) MapTest[K, V]
- func (x MapTest[K, V]) NotHaveKeyValue(expectKey K, expectValue V) MapTest[K, V]
- func (x MapTest[K, V]) NotHaveValue(expect V) MapTest[K, V]
- type NoErrorTest
- type NumberTest
- func (x NumberTest[T]) Equal(expect T) NumberTest[T]
- func (x NumberTest[T]) Greater(expect T) NumberTest[T]
- func (x NumberTest[T]) GreaterOrEqual(expect T) NumberTest[T]
- func (x NumberTest[T]) Less(expect T) NumberTest[T]
- func (x NumberTest[T]) LessOrEqual(expect T) NumberTest[T]
- func (x NumberTest[T]) Must() NumberTest[T]
- func (x NumberTest[T]) NotEqual(expect T) NumberTest[T]
- type Return1Test
- type Return2Test
- type Return3Test
- type StringTest
- func (x StringTest) Contains(sub string) StringTest
- func (x StringTest) Equal(expect string) StringTest
- func (x StringTest) HasPrefix(prefix string) StringTest
- func (x StringTest) HasSuffix(suffix string) StringTest
- func (x StringTest) IsEmpty() StringTest
- func (x StringTest) IsNotEmpty() StringTest
- func (x StringTest) Match(pattern string) StringTest
- func (x StringTest) Must() StringTest
- func (x StringTest) NotContains(sub string) StringTest
- func (x StringTest) NotEqual(expect string) StringTest
- func (x StringTest) NotHasPrefix(prefix string) StringTest
- func (x StringTest) NotHasSuffix(suffix string) StringTest
- func (x StringTest) NotMatch(pattern string) StringTest
- type ValueTest
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Diff = func(expect, actual any) string { switch reflect.ValueOf(actual).Kind() { case reflect.Pointer, reflect.UnsafePointer, reflect.Array, reflect.Slice, reflect.Struct, reflect.Map: return "diff:\n" + cmp.Diff(expect, actual, cmp.Exporter(func(t reflect.Type) bool { return true })) default: return strings.Join([]string{ fmt.Sprintf("actual: %+v", actual), fmt.Sprintf("expect: %+v", expect), }, "\n") } }
var DumpError = func(err error) string {
return err.Error()
}
var EvalCompare = func(a, b any) bool { return reflect.DeepEqual(a, b) }
EvalCompare is a function to check if actual value equals with expected value. A developer can replace EvalCompare with own evaluation function if needed.
EvalCompare(1, 2) == false EvalCompare("abc", "axc") == false EvalCompare([]int{1, 2, 3}, []int{1, 2, 3}) == true
var EvalIsNil = func(v any) bool { value := reflect.ValueOf(v) switch value.Kind() { case reflect.Invalid: return true case reflect.Array, reflect.Slice: return value.Len() == 0 case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Uintptr, reflect.UnsafePointer: return value.IsNil() default: return false } }
EvalIsNil is a function to check if actual value is nil. A developer can replace EvalIsNil with own nil check function if needed.
EvalIsNil(1) == false EvalIsNil("abc") == false EvalIsNil(nil) == true EvalIsNil([]int{}) == true
Functions ¶
func Cast ¶
Cast tries type assertion and will error and stop test if type assertion fails
var a any = "hello" b := gt.Cast[string](a) // <- Pass and set "hello" to b c := gt.Cast[int](a) // <- Fail and stop test
Types ¶
type ArrayTest ¶
type ArrayTest[T any] struct { // contains filtered or unexported fields }
func Array ¶
Array provides ArrayTest that has not only Value test methods but also array (slice) comparison methods
Example ¶
t := newRecorder() a := []int{2, 3, 4} b := []int{2, 3, 5} gt.Value(t, a).Equal(b) fmt.Println(t.msgs[0])
Output:
func (ArrayTest[T]) All ¶ added in v0.0.6
All calls f with testing.TB and each elements in the array. If f returns false, All returns immediately and test will trigger error. If f returns true for all elements, All will pass.
v := []int{1, 2, 3, 5} gt.Array(t, v).All(func(v int) bool { return v < 6 }) // Pass gt.Array(t, v).All(func(v int) bool { return v < 4 }) // Fail
func (ArrayTest[T]) Any ¶ added in v0.0.6
Any calls f with testing.TB and each elements in the array. If f returns true, Any returns immediately and test will pass. If f returns false for all elements, Any will trigger error.
v := []int{1, 2, 3, 5} gt.Array(t, v).Any(func(v int) bool { return v == 3 }) // Pass gt.Array(t, v).Any(func(v int) bool { return v == 4 }) // Fail
func (ArrayTest[T]) At ¶ added in v0.0.5
At calls f with testing.TB and idx th elements in the array. If idx is out of range, f is not called and test will trigger error.
v := []int{1, 2, 3, 5} gt.Array(t, v).At(2, func(t testing.TB, v int) { gt.Value(t, v).Equal(3) // Pass })
func (ArrayTest[T]) Contain ¶
Contain check if actual has expect as sub sequence.
v := []int{1, 2, 3, 5} gt.Array(t, v).Contain([]int{1, 2, 3})) // Pass gt.Array(t, v).Contain([]int{1, 2, 5})) // Fail
func (ArrayTest[T]) Distinct ¶ added in v0.0.7
Distinct checks if all elements in the array are distinct. If not, test will trigger error.
gt.Array(t, []int{1, 2, 3, 5}).Distinct() // Pass gt.Array(t, []int{1, 2, 3, 2}).Distinct() // Fail
func (ArrayTest[T]) Equal ¶
Equal check if actual does not equals with expect. Default evaluation function uses reflect.DeepEqual.
v := []int{1, 2, 3, 5} gt.Array(t, v).Equal([]int{1, 2, 3, 5}) // Pass gt.Array(t, v).Equal([]int{1, 2, 3, 4}) // Fail
func (ArrayTest[T]) EqualAt ¶ added in v0.0.4
EqualAt checks if actual[idx] equals expect. If idx is out of range, f is not called and test will trigger error.
v := []int{1, 2, 3, 5} gt.Array(t, v).EqualAt(2, 3) // Pass gt.Array(t, v).EqualAt(2, 1) // Fail gt.Array(t, v).EqualAt(2, 5) // Fail by out of range
func (ArrayTest[T]) Have ¶
Have check if actual has an expect element
v := []int{1, 2, 3, 5} gt.Array(t, v).Have(5)) // Pass gt.Array(t, v).Have(4)) // Fail
func (ArrayTest[T]) Length ¶
Length checks if element number of actual array is expect.
v := []int{1, 2, 3, 5} gt.Array(t, v).Length(4) // Pass
func (ArrayTest[T]) Less ¶ added in v0.0.10
Less checks if array length is shorter than expect.
v := []int{1, 2, 3, 5} gt.Array(t, v).Less(5) // Pass gt.Array(t, v).Less(4) // Fail
func (ArrayTest[T]) Longer ¶ added in v0.0.2
Longer checks if array length is longer than expect.
v := []int{1, 2, 3, 5} gt.Array(t, v).Longer(3) // Pass gt.Array(t, v).Longer(4) // Fail
func (ArrayTest[T]) MatchThen ¶ added in v0.0.8
MatchThen calls then function with testing.TB and first element in the array that match with match. If no element matches, MatchThen will trigger error.
v := []struct{ Name string Age int }{ {"Alice", 20}, {"Bob", 21}, {"Carol", 22}, } gt.Array(t, v).MatchThen(func(v struct{Name string, Age int}) bool { return v.Name == "Bob" }, func(t testing.TB, v struct{Name string, Age int}) { gt.Value(t, v.Age).Equal(21) // Pass }) gt.Array(t, v).MatchThen(func(v struct{Name string, Age int}) bool { return v.Name == "Dave" }, func(t testing.TB, v struct{Name string, Age int}) { gt.Value(t, v.Age).Equal(21) // Fail })
func (ArrayTest[T]) Must ¶
Must check if error has occurred in previous test. If errors will occur in following test, it immediately stop test by t.FailNow().
func (ArrayTest[T]) NotContain ¶
NotContain check if actual does not have expect as sub sequence.
v := []int{1, 2, 3, 5} gt.Array(t, v).NotContain([]int{1, 2, 3})) // Fail gt.Array(t, v).NotContain([]int{1, 2, 5})) // Pass
func (ArrayTest[T]) NotEqual ¶
NotEqual check if actual does not equals with expect. Default evaluation function uses reflect.DeepEqual.
v := []int{1, 2, 3, 5} gt.Array(t, v).NotEqual([]int{1, 2, 3, 5}) // Fail gt.Array(t, v).NotEqual([]int{1, 2, 3, 4}) // Pass
func (ArrayTest[T]) NotEqualAt ¶ added in v0.0.4
NotEqualAt checks if actual[idx] equals expect. If idx is out of range, f is not called and test will trigger error.
v := []int{1, 2, 3, 5} gt.Array(t, v).NotEqualAt(2, 1) // Pass gt.Array(t, v).NotEqualAt(2, 3) // Fail gt.Array(t, v).NotEqualAt(2, 5) // Fail by out of range
type ErrorTest ¶
type ErrorTest struct {
// contains filtered or unexported fields
}
type MapTest ¶
type MapTest[K comparable, V any] struct { // contains filtered or unexported fields }
func M ¶
func M[K comparable, V any](t testing.TB, actual map[K]V) MapTest[K, V]
M is sugar syntax of Map
m := map[string]int{ "blue": 5, } gt.M(t, m).HaveKey("blue").HaveValue(5)
func Map ¶
func Map[K comparable, V any](t testing.TB, actual map[K]V) MapTest[K, V]
Map provides MapTest that has not only Value test methods but also key-value test
m := map[string]int{ "blue": 5, } gt.Map(t, m).HaveKey("blue").HaveValue(5)
Example ¶
t := newRecorder() type user struct { ID int Name string } a := &user{ID: 1, Name: "Alice"} b := &user{ID: 2, Name: "Bob"} gt.Value(t, a).Equal(b) fmt.Println(t.msgs[0])
Output:
Example (Nil) ¶
t := newRecorder() type user struct { ID int Name string } a := &user{ID: 1, Name: "Alice"} gt.Value(t, a).Equal(nil) fmt.Println(t.msgs[0])
Output:
func (MapTest[K, V]) At ¶ added in v0.0.5
At calls f with testing.TB and idx th elements in the array. If idx is out of range, f is not called and test will trigger error.
m := map[string]int{ "blue": 5, } gt.Map(t, m).At("blue", func(t testing.TB, v int) { gt.Value(t, v).Equal(5) // <- pass })
func (MapTest[K, V]) Equal ¶
Equal checks if expect completely equals given actual map.
m := map[string]int{ "blue": 5, } gt.Map(t, m).Equal(map[string]int{"blue": 5}) // <- Pass gt.Map(t, m).Equal(map[string]int{"blue": 0}) // <- Fail
func (MapTest[K, V]) EqualAt ¶ added in v0.0.4
EqualAt checks if actual[key] equals expect. If key is not found, test will fail.
m := map[string]int{ "blue": 5, } gt.Map(t, m).NotEqualAt("blue", 5) // Pass gt.Map(t, m).NotEqualAt("blue", 1) // Fail gt.Map(t, m).NotEqualAt("orange", 5) // Fail by key not found
func (MapTest[K, V]) HaveKey ¶
HaveKey checks if the map has expect key.
m := map[string]int{ "blue": 5, } gt.Map(t, m).HaveKey("blue") // <- pass gt.Map(t, m).HaveKey("orange") // <- fail
func (MapTest[K, V]) HaveKeyValue ¶
HaveKeyValue checks if the map has expect a pair of key and value.
m := map[string]int{ "blue": 5, } gt.Map(t, m).HaveKeyValue("blue", 5) // <- pass gt.Map(t, m).HaveKeyValue("blue", 0) // <- fail gt.Map(t, m).HaveKeyValue("orange", 5) // <- fail
func (MapTest[K, V]) HaveValue ¶
HaveValue checks if the map has expect key.
m := map[string]int{ "blue": 5, } gt.Map(t, m).HaveValue(5) // <- pass gt.Map(t, m).HaveValue(7) // <- fail
func (MapTest[K, V]) Length ¶
Length checks number of a pair of keys.
m := map[string]int{ "blue": 5, "orange: 0, } gt.Map(t, m).Length(2) // <- pass gt.Map(t, m).Length(0) // <- pass
func (MapTest[K, V]) Must ¶
Must check if error has occurred in previous test. If errors will occur in following test, it immediately stop test by t.Failed().
m := map[string]int{ "blue": 5, } gt.Must().Map(t, m). HaveKey("blue", 0). // <- fail HaveKey("blue", 5). // <- will not be tested gt.Map(t, m).HaveKey("blue") // <- will not be tested
func (MapTest[K, V]) NotEqual ¶
NotEqual checks if expect does not equal given actual map.
m := map[string]int{ "blue": 5, } gt.Map(t, m).Equal(map[string]int{ // <- Pass "blue": 0, }) gt.Map(t, m).Equal(map[string]int{ // <- Pass "blue": 5, "orange": 9, })
func (MapTest[K, V]) NotEqualAt ¶ added in v0.0.4
NotEqualAt checks if actual[key] equals expect. If key is not found, test will fail.
m := map[string]int{ "blue": 5, } gt.Map(t, m).NotEqualAt("blue", 1) // Pass gt.Map(t, m).NotEqualAt("blue", 5) // Fail gt.Map(t, m).NotEqualAt("orange", 5) // Fail by key not found
func (MapTest[K, V]) NotHaveKey ¶
NotHaveKey checks if the map does not have expect key.
m := map[string]int{ "blue": 5, } gt.Map(t, m).NotHaveKey("orange") // <- pass gt.Map(t, m).NotHaveKey("blue") // <- fail
func (MapTest[K, V]) NotHaveKeyValue ¶
NotHaveKeyValue checks if the map does not have expect a pair of key and value.
m := map[string]int{ "blue": 5, } gt.Map(t, m).NotHaveKeyValue("blue", 5) // <- fail gt.Map(t, m).NotHaveKeyValue("blue", 0) // <- pass gt.Map(t, m).NotHaveKeyValue("orange", 5) // <- pass
func (MapTest[K, V]) NotHaveValue ¶
NotHaveValue checks if the map has expect key.
m := map[string]int{ "blue": 5, } gt.Map(t, m).NotHaveValue(5) // <- fail gt.Map(t, m).NotHaveValue(7) // <- pass
type NoErrorTest ¶ added in v0.0.3
type NoErrorTest struct {
// contains filtered or unexported fields
}
func NoError ¶ added in v0.0.3
func NoError(t testing.TB, actual error) NoErrorTest
NoError checks if error does not occur.
func (NoErrorTest) Must ¶ added in v0.0.3
func (x NoErrorTest) Must()
type NumberTest ¶
type NumberTest[T number] struct {
// contains filtered or unexported fields
}
func Number ¶
func Number[T number](t testing.TB, actual T) NumberTest[T]
Number provides NumberTest that has not only Value test methods but also large-small comparison methods
func (NumberTest[T]) Equal ¶
func (x NumberTest[T]) Equal(expect T) NumberTest[T]
Equal checks if expect equals given actual value.
n := 2 gt.Number(t, n).Equal(2)
func (NumberTest[T]) Greater ¶
func (x NumberTest[T]) Greater(expect T) NumberTest[T]
Greater checks if actual value is greater than expect
n := 5 gt.Number(t, n).Greater(3) // Pass gt.Number(t, n).Greater(5) // Fail
func (NumberTest[T]) GreaterOrEqual ¶
func (x NumberTest[T]) GreaterOrEqual(expect T) NumberTest[T]
GreaterOrEqual checks if actual value is expect or greater
n := 5 gt.Number(t, n).GreaterOrEqual(3) // Pass gt.Number(t, n).GreaterOrEqual(5) // Pass gt.Number(t, n).GreaterOrEqual(6) // Fail
func (NumberTest[T]) Less ¶
func (x NumberTest[T]) Less(expect T) NumberTest[T]
Less checks if actual value is less than expect
n := 5 gt.Number(t, n).Less(6) // Pass gt.Number(t, n).Less(5) // Fail
func (NumberTest[T]) LessOrEqual ¶
func (x NumberTest[T]) LessOrEqual(expect T) NumberTest[T]
LessOrEqual checks if actual value is expect or Less
n := 5 gt.Number(t, n).LessOrEqual(6) // Pass gt.Number(t, n).LessOrEqual(5) // Pass gt.Number(t, n).LessOrEqual(3) // Fail
func (NumberTest[T]) Must ¶
func (x NumberTest[T]) Must() NumberTest[T]
Must check if error has occurred in previous test. If errors will occur in following test, it immediately stop test by t.FailNow().
func (NumberTest[T]) NotEqual ¶
func (x NumberTest[T]) NotEqual(expect T) NumberTest[T]
NotEqual checks if expect does not equal given actual value.
n := 5 gt.Number(t, n).NotEqual(1) // Pass gt.number(t, n).Equal(5) // Fail
type Return1Test ¶ added in v0.0.3
type Return1Test[T1 any] struct { // contains filtered or unexported fields }
func R1 ¶ added in v0.0.3
func R1[T1 any](r1 T1, err error) Return1Test[T1]
func Return1 ¶ added in v0.0.3
func Return1[T1 any](r1 T1, err error) Return1Test[T1]
Return1 creates a test for returned variables (one value and one error)
f := func() (string, error) { return "ok", nil } gt.Return1(f()).Error() // Fail gt.Return1(f()).NoError().Equal("ok") // Pass
func (Return1Test[T1]) Error ¶ added in v0.0.3
func (x Return1Test[T1]) Error(t testing.TB) ErrorTest
Error check if the function returned error. If error is nil, it will fail. If error is not nil, it provides ErrorTest
func (Return1Test[T1]) NoError ¶ added in v0.0.3
func (x Return1Test[T1]) NoError(t testing.TB) T1
NoError check if the function returned no error. If error is not nil, it will fail. If error is nil, it provides 1st returned value.
type Return2Test ¶ added in v0.0.3
type Return2Test[T1, T2 any] struct { // contains filtered or unexported fields }
func R2 ¶ added in v0.0.3
func R2[T1, T2 any](r1 T1, r2 T2, err error) Return2Test[T1, T2]
func Return2 ¶ added in v0.0.3
func Return2[T1, T2 any](r1 T1, r2 T2, err error) Return2Test[T1, T2]
Return2 creates a test for returned variables (two values and one error)
f := func() (string, int, error) { return "ok", 1, nil } gt.Return2(f()).Error() // Fail s, i := gt.Return1(f()).NoError() // Pass s.Equal("ok") // Pass i.Equal(1) // Pass
func (Return2Test[T1, T2]) Error ¶ added in v0.0.3
func (x Return2Test[T1, T2]) Error(t testing.TB) ErrorTest
Error check if the function returned error. If error is nil, it will fail. If error is not nil, it provides ErrorTest
func (Return2Test[T1, T2]) NoError ¶ added in v0.0.3
func (x Return2Test[T1, T2]) NoError(t testing.TB) (T1, T2)
NoError check if the function returned no error. If error is not nil, it will fail. If error is nil, it provides 1st and 2nd returned value.
type Return3Test ¶ added in v0.0.3
type Return3Test[T1, T2, T3 any] struct { // contains filtered or unexported fields }
func R3 ¶ added in v0.0.3
func R3[T1, T2, T3 any](r1 T1, r2 T2, r3 T3, err error) Return3Test[T1, T2, T3]
func Return3 ¶ added in v0.0.3
func Return3[T1, T2, T3 any](r1 T1, r2 T2, r3 T3, err error) Return3Test[T1, T2, T3]
Return3 creates a test for returned variables (three values and one error)
f := func() (string, int, bool, error) { return "ok", 1, true, nil } gt.Return3(f()).Error() // Fail s, i, b := gt.Return1(f()).NoError() // Pass s.Equal("ok") // Pass i.Equal(1) // Pass b.Equal(true) // Pass
func (Return3Test[T1, T2, T3]) Error ¶ added in v0.0.3
func (x Return3Test[T1, T2, T3]) Error(t testing.TB) ErrorTest
Error check if the function returned error. If error is nil, it will fail. If error is not nil, it provides ErrorTest
func (Return3Test[T1, T2, T3]) NoError ¶ added in v0.0.3
func (x Return3Test[T1, T2, T3]) NoError(t testing.TB) (T1, T2, T3)
NoError check if the function returned no error. If error is not nil, it will fail. If error is nil, it provides 1st, 2nd and 3rd returned value.
type StringTest ¶ added in v0.0.5
type StringTest struct {
// contains filtered or unexported fields
}
func String ¶ added in v0.0.5
func String(t testing.TB, actual string) StringTest
String provides StringTest that has basic comparison methods
func (StringTest) Contains ¶ added in v0.0.5
func (x StringTest) Contains(sub string) StringTest
Contains check if actual contains expected.
func (StringTest) Equal ¶ added in v0.0.5
func (x StringTest) Equal(expect string) StringTest
Equal check if actual equals with expect. Default evaluation function uses reflect.DeepEqual.
func (StringTest) HasPrefix ¶ added in v0.0.5
func (x StringTest) HasPrefix(prefix string) StringTest
HasPrefix check if actual has prefix expected.
func (StringTest) HasSuffix ¶ added in v0.0.5
func (x StringTest) HasSuffix(suffix string) StringTest
HasSuffix check if actual has suffix expected.
func (StringTest) IsEmpty ¶ added in v0.0.5
func (x StringTest) IsEmpty() StringTest
IsEmpty check if actual is empty.
func (StringTest) IsNotEmpty ¶ added in v0.0.5
func (x StringTest) IsNotEmpty() StringTest
IsNotEmpty check if actual is not empty.
func (StringTest) Match ¶ added in v0.0.5
func (x StringTest) Match(pattern string) StringTest
Match check if actual matches with expected regular expression.
func (StringTest) Must ¶ added in v0.0.5
func (x StringTest) Must() StringTest
Must check if error has occurred in previous test. If errors will occur in following test, it immediately stop test by t.FailNow().
func (StringTest) NotContains ¶ added in v0.0.5
func (x StringTest) NotContains(sub string) StringTest
NotContains check if actual does not contain expected.
func (StringTest) NotEqual ¶ added in v0.0.5
func (x StringTest) NotEqual(expect string) StringTest
NotEqual check if actual does not equals with expect. Default evaluation function uses reflect.DeepEqual.
func (StringTest) NotHasPrefix ¶ added in v0.0.5
func (x StringTest) NotHasPrefix(prefix string) StringTest
NotHasPrefix check if actual does not have prefix expected.
func (StringTest) NotHasSuffix ¶ added in v0.0.5
func (x StringTest) NotHasSuffix(suffix string) StringTest
NotHasSuffix check if actual does not have suffix expected.
func (StringTest) NotMatch ¶ added in v0.0.5
func (x StringTest) NotMatch(pattern string) StringTest
NotMatch check if actual matches with expected regular expression.
type ValueTest ¶
type ValueTest[T any] struct { // contains filtered or unexported fields }
func Value ¶
Value provides ValueTest that has basic comparison methods
Example (Nil) ¶
nolint
t := newRecorder() a := "test" gt.Value(t, &a).Nil() fmt.Println(t.msgs[0])
Output:
func (ValueTest[T]) Equal ¶
Equal check if actual equals with expect. Default evaluation function uses reflect.DeepEqual.
type user struct { Name string } u1 := user{Name: "blue"} gt.Value(t, u1).Equal(user{Name: "blue"}) // Pass gt.Value(t, u1).Equal(user{Name: "orange"}) // Fail
func (ValueTest[T]) In ¶ added in v0.0.6
In checks actual is in expects. Default evaluation function uses reflect.DeepEqual.
func (ValueTest[T]) Must ¶
Must check if error has occurred in previous test. If errors will occur in following test, it immediately stop test by t.Failed().
name := "Alice" gt.Value(name).Equal("Bob").Must() // Test will stop here
func (ValueTest[T]) Nil ¶
Nil checks if actual is nil.
var u *User gt.Value(t, u).Nil() // Pass u = &User{} gt.Value(t, u).Nil() // Fail
func (ValueTest[T]) NotEqual ¶
NotEqual check if actual does not equals with expect. Default evaluation function uses reflect.DeepEqual.
type user struct { Name string } u1 := user{Name: "blue"} gt.Value(t, u1).NotEqual(user{Name: "blue"}) // Fail gt.Value(t, u1).NotEqual(user{Name: "orange"}) // Pass