Slice

func Slice(model interface{}, expectedEntries ArrayEntries) TestDeep

Slice operator compares the contents of a slice or a pointer on a slice against the non-zero values of model (if any) and the values of expectedEntries.

model must be the same type as compared data.

expectedEntries can be nil, if no zero entries are expected and no TestDeep operator are involved.

got := []int{12, 14, 17}
td.Cmp(t, got, td.Slice([]int{0, 14}, td.ArrayEntries{0: 12, 2: 17})) // succeeds
td.Cmp(t, got,
  td.Slice([]int{0, 14}, td.ArrayEntries{0: td.Gt(10), 2: td.Gt(15)})) // succeeds

TypeBehind method returns the reflect.Type of model.

See also Slice godoc.

Examples

Slice example
TypedSlice example

CmpSlice shortcut

func CmpSlice(t TestingT, got interface{}, model interface{}, expectedEntries ArrayEntries, args ...interface{}) bool

CmpSlice is a shortcut for:

td.Cmp(t, got, td.Slice(model, expectedEntries), 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 CmpSlice godoc.

Examples

Slice example
TypedSlice example

T.Slice shortcut

func (t *T) Slice(got interface{}, model interface{}, expectedEntries ArrayEntries, args ...interface{}) bool

Slice is a shortcut for:

t.Cmp(got, td.Slice(model, expectedEntries), 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.Slice godoc.

Examples

Slice example
TypedSlice example