MapEach

func MapEach(expectedValue any) TestDeep

MapEach operator has to be applied on maps. It compares each value of data map against expectedValue. During a match, all values have to match to succeed.

got := map[string]string{"test": "foo", "buzz": "bar"}
td.Cmp(t, got, td.MapEach("bar"))     // fails, coz "foo" ≠ "bar"
td.Cmp(t, got, td.MapEach(td.Len(3))) // succeeds as values are 3 chars long

See also MapEach godoc.

Examples

Map example
TypedMap example

CmpMapEach shortcut

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

CmpMapEach is a shortcut for:

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

Examples

Map example
TypedMap example

T.MapEach shortcut

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

MapEach is a shortcut for:

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

Examples

Map example
TypedMap example