@@ -44,7 +44,24 @@ type mapEntryInfo struct {
4444// value (which can be a [TestDeep] operator as well as a zero value.)
4545type MapEntries map [any ]any
4646
47- func newMap (model any , entries MapEntries , kind mapKind ) * tdMap {
47+ func mergeMapEntries (mes ... MapEntries ) MapEntries {
48+ switch len (mes ) {
49+ case 0 :
50+ return nil
51+ case 1 :
52+ return mes [0 ]
53+ }
54+
55+ ret := make (MapEntries , len (mes [0 ]))
56+ for _ , me := range mes {
57+ for k , v := range me {
58+ ret [k ] = v
59+ }
60+ }
61+ return ret
62+ }
63+
64+ func newMap (model any , kind mapKind , mes ... MapEntries ) * tdMap {
4865 vmodel := reflect .ValueOf (model )
4966
5067 m := tdMap {
@@ -64,7 +81,7 @@ func newMap(model any, entries MapEntries, kind mapKind) *tdMap {
6481
6582 if vmodel .IsNil () {
6683 m .expectedType = vmodel .Type ().Elem ()
67- m .populateExpectedEntries (entries , reflect.Value {})
84+ m .populateExpectedEntries (mergeMapEntries ( mes ... ) , reflect.Value {})
6885 return & m
6986 }
7087
@@ -73,7 +90,7 @@ func newMap(model any, entries MapEntries, kind mapKind) *tdMap {
7390
7491 case reflect .Map :
7592 m .expectedType = vmodel .Type ()
76- m .populateExpectedEntries (entries , vmodel )
93+ m .populateExpectedEntries (mergeMapEntries ( mes ... ) , vmodel )
7794 return & m
7895 }
7996
@@ -160,8 +177,9 @@ func (m *tdMap) populateExpectedEntries(entries MapEntries, expectedModel reflec
160177//
161178// model must be the same type as compared data.
162179//
163- // expectedEntries can be nil, if no zero entries are expected and
164- // no [TestDeep] operators are involved.
180+ // expectedEntries can be omitted, if no [TestDeep] operators are
181+ // involved. If expectedEntries contains more than one item, all items
182+ // are merged before their use, from left to right.
165183//
166184// During a match, all expected entries must be found and all data
167185// entries must be expected to succeed.
@@ -184,8 +202,8 @@ func (m *tdMap) populateExpectedEntries(entries MapEntries, expectedModel reflec
184202// TypeBehind method returns the [reflect.Type] of model.
185203//
186204// See also [SubMapOf] and [SuperMapOf].
187- func Map (model any , expectedEntries MapEntries ) TestDeep {
188- return newMap (model , expectedEntries , allMap )
205+ func Map (model any , expectedEntries ... MapEntries ) TestDeep {
206+ return newMap (model , allMap , expectedEntries ... )
189207}
190208
191209// summary(SubMapOf): compares the contents of a map but with
@@ -197,8 +215,9 @@ func Map(model any, expectedEntries MapEntries) TestDeep {
197215//
198216// model must be the same type as compared data.
199217//
200- // expectedEntries can be nil, if no zero entries are expected and
201- // no [TestDeep] operators are involved.
218+ // expectedEntries can be omitted, if no [TestDeep] operators are
219+ // involved. If expectedEntries contains more than one item, all items
220+ // are merged before their use, from left to right.
202221//
203222// During a match, each map entry should be matched by an expected
204223// entry to succeed. But some expected entries can be missing from the
@@ -230,8 +249,8 @@ func Map(model any, expectedEntries MapEntries) TestDeep {
230249// TypeBehind method returns the [reflect.Type] of model.
231250//
232251// See also [Map] and [SuperMapOf].
233- func SubMapOf (model any , expectedEntries MapEntries ) TestDeep {
234- return newMap (model , expectedEntries , subMap )
252+ func SubMapOf (model any , expectedEntries ... MapEntries ) TestDeep {
253+ return newMap (model , subMap , expectedEntries ... )
235254}
236255
237256// summary(SuperMapOf): compares the contents of a map but with
@@ -243,8 +262,9 @@ func SubMapOf(model any, expectedEntries MapEntries) TestDeep {
243262//
244263// model must be the same type as compared data.
245264//
246- // expectedEntries can be nil, if no zero entries are expected and
247- // no [TestDeep] operators are involved.
265+ // expectedEntries can be omitted, if no [TestDeep] operators are
266+ // involved. If expectedEntries contains more than one item, all items
267+ // are merged before their use, from left to right.
248268//
249269// During a match, each expected entry should match in the compared
250270// map. But some entries in the compared map may not be expected.
@@ -275,8 +295,8 @@ func SubMapOf(model any, expectedEntries MapEntries) TestDeep {
275295// TypeBehind method returns the [reflect.Type] of model.
276296//
277297// See also [SuperMapOf] and [SubMapOf].
278- func SuperMapOf (model any , expectedEntries MapEntries ) TestDeep {
279- return newMap (model , expectedEntries , superMap )
298+ func SuperMapOf (model any , expectedEntries ... MapEntries ) TestDeep {
299+ return newMap (model , superMap , expectedEntries ... )
280300}
281301
282302func (m * tdMap ) Match (ctx ctxerr.Context , got reflect.Value ) (err * ctxerr.Error ) {
0 commit comments