ArrayEach

func ArrayEach(expectedValue any) TestDeep

ArrayEach operator has to be applied on arrays or slices or on pointers on array/slice. It compares each item of data array/slice against expectedValue. During a match, all items have to match to succeed.

got := [3]string{"foo", "bar", "biz"}
td.Cmp(t, got, td.ArrayEach(td.Len(3)))         // succeeds
td.Cmp(t, got, td.ArrayEach(td.HasPrefix("b"))) // fails coz "foo"

Works on slices as well:

got := []Person{
  {Name: "Bob", Age: 42},
  {Name: "Alice", Age: 24},
}
td.Cmp(t, got, td.ArrayEach(
  td.Struct(Person{}, td.StructFields{
    Age: td.Between(20, 45),
  })),
) // succeeds, each Person has Age field between 20 and 45

See also ArrayEach godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example

CmpArrayEach shortcut

func CmpArrayEach(t TestingT, got, expectedValue any, args ...any) bool

CmpArrayEach is a shortcut for:

td.Cmp(t, got, td.ArrayEach(expectedValue), args...)

See above for details.

Returns true if the test is OK, false if it fails.

If t is a *T then its Config field is inherited.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also CmpArrayEach godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example

T.ArrayEach shortcut

func (t *T) ArrayEach(got, expectedValue any, args ...any) bool

ArrayEach is a shortcut for:

t.Cmp(got, td.ArrayEach(expectedValue), args...)

See above for details.

Returns true if the test is OK, false if it fails.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also T.ArrayEach godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example