Len

func Len(expectedLen interface{}) TestDeep

Len is a smuggler operator. It takes data, applies len() function on it and compares its result to expectedLen. Of course, the compared value must be an array, a channel, a map, a slice or a string.

expectedLen can be an int value:

td.Cmp(t, gotSlice, td.Len(12))

as well as an other operator:

td.Cmp(t, gotSlice, td.Len(td.Between(3, 4)))

See also Len godoc.

Examples

Slice example
Map example
OperatorSlice example
OperatorMap example

CmpLen shortcut

func CmpLen(t TestingT, got interface{}, expectedLen interface{}, args ...interface{}) bool

CmpLen is a shortcut for:

td.Cmp(t, got, td.Len(expectedLen), 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 CmpLen godoc.

Examples

Slice example
Map example
OperatorSlice example
OperatorMap example

T.Len shortcut

func (t *T) Len(got interface{}, expectedLen interface{}, args ...interface{}) bool

Len is a shortcut for:

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

Examples

Slice example
Map example
OperatorSlice example
OperatorMap example