@@ -271,6 +271,42 @@ func (s *S) TestMarshalBuffer(c *C) {
271271 c .Assert (data , DeepEquals , buf [:len (data )])
272272}
273273
274+ func (s * S ) TestPtrInline (c * C ) {
275+ cases := []struct {
276+ In interface {}
277+ Out bson.M
278+ }{
279+ {
280+ In : inlinePtrStruct {A : 1 , MStruct : & MStruct {M : 3 }},
281+ Out : bson.M {"a" : 1 , "m" : 3 },
282+ },
283+ { // go deeper
284+ In : inlinePtrPtrStruct {B : 10 , inlinePtrStruct : & inlinePtrStruct {A : 20 , MStruct : & MStruct {M : 30 }}},
285+ Out : bson.M {"b" : 10 , "a" : 20 , "m" : 30 },
286+ },
287+ {
288+ // nil embed struct
289+ In : & inlinePtrStruct {A : 3 },
290+ Out : bson.M {"a" : 3 },
291+ },
292+ {
293+ // nil embed struct
294+ In : & inlinePtrPtrStruct {B : 5 },
295+ Out : bson.M {"b" : 5 },
296+ },
297+ }
298+
299+ for _ , cs := range cases {
300+ data , err := bson .Marshal (cs .In )
301+ c .Assert (err , IsNil )
302+ var dataBSON bson.M
303+ err = bson .Unmarshal (data , & dataBSON )
304+ c .Assert (err , IsNil )
305+
306+ c .Assert (dataBSON , DeepEquals , cs .Out )
307+ }
308+ }
309+
274310// --------------------------------------------------------------------------
275311// Some one way marshaling operations which would unmarshal differently.
276312
@@ -713,8 +749,6 @@ var marshalErrorItems = []testItemType{
713749 "Attempted to marshal empty Raw document" },
714750 {bson.M {"w" : bson.Raw {Kind : 0x3 , Data : []byte {}}},
715751 "Attempted to marshal empty Raw document" },
716- {& inlineCantPtr {& struct { A , B int }{1 , 2 }},
717- "Option ,inline needs a struct value or map field" },
718752 {& inlineDupName {1 , struct { A , B int }{2 , 3 }},
719753 "Duplicated key 'a' in struct bson_test.inlineDupName" },
720754 {& inlineDupMap {},
@@ -1174,6 +1208,17 @@ type inlineUnexported struct {
11741208 M map [string ]interface {} `bson:",inline"`
11751209 unexported `bson:",inline"`
11761210}
1211+ type MStruct struct {
1212+ M int `bson:"m,omitempty"`
1213+ }
1214+ type inlinePtrStruct struct {
1215+ A int
1216+ * MStruct `bson:",inline"`
1217+ }
1218+ type inlinePtrPtrStruct struct {
1219+ B int
1220+ * inlinePtrStruct `bson:",inline"`
1221+ }
11771222type unexported struct {
11781223 A int
11791224}
0 commit comments