SuperSliceOf

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

SuperSliceOf operator compares the contents of an array, a pointer on an array, a slice or a pointer on a slice against the non-zero values of model (if any) and the values of expectedEntries. So entries with zero value of model are always ignored. If a zero value check is needed, this zero value has to be set in expectedEntries. An entry cannot be present in both model and expectedEntries, except if it is a zero-value in model. At the end, only entries present in expectedEntries and non-zero ones present in model are checked. To check all entries of an array see Array operator. To check all entries of a slice see Slice operator.

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.

Works with slices:

got := []int{12, 14, 17}
td.Cmp(t, got, td.SuperSliceOf([]int{12}, nil))                                // succeeds
td.Cmp(t, got, td.SuperSliceOf([]int{12}, td.ArrayEntries{2: 17}))             // succeeds
td.Cmp(t, &got, td.SuperSliceOf(&[]int{0, 14}, td.ArrayEntries{2: td.Gt(16)})) // succeeds

and arrays:

got := [5]int{12, 14, 17, 26, 56}
td.Cmp(t, got, td.SuperSliceOf([5]int{12}, nil))                                // succeeds
td.Cmp(t, got, td.SuperSliceOf([5]int{12}, td.ArrayEntries{2: 17}))             // succeeds
td.Cmp(t, &got, td.SuperSliceOf(&[5]int{0, 14}, td.ArrayEntries{2: td.Gt(16)})) // succeeds

See also SuperSliceOf godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example

CmpSuperSliceOf shortcut

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

CmpSuperSliceOf is a shortcut for:

td.Cmp(t, got, td.SuperSliceOf(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 CmpSuperSliceOf godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example

T.SuperSliceOf shortcut

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

SuperSliceOf is a shortcut for:

t.Cmp(got, td.SuperSliceOf(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.SuperSliceOf godoc.

Examples

Array example
TypedArray example
Slice example
TypedSlice example