@@ -34,9 +34,9 @@ import (
34
34
"errors"
35
35
"net/url"
36
36
"reflect"
37
+ "strings"
37
38
"testing"
38
39
"time"
39
- "strings"
40
40
41
41
"github.com/globalsign/mgo/bson"
42
42
. "gopkg.in/check.v1"
@@ -111,6 +111,10 @@ var sampleItems = []testItemType{
111
111
{bson.M {"BSON" : []interface {}{"awesome" , float64 (5.05 ), 1986 }},
112
112
"1\x00 \x00 \x00 \x04 BSON\x00 &\x00 \x00 \x00 \x02 0\x00 \x08 \x00 \x00 \x00 " +
113
113
"awesome\x00 \x01 1\x00 333333\x14 @\x10 2\x00 \xc2 \x07 \x00 \x00 \x00 \x00 " },
114
+ {bson.M {"slice" : []uint8 {1 , 2 }},
115
+ "\x13 \x00 \x00 \x00 \x05 slice\x00 \x02 \x00 \x00 \x00 \x00 \x01 \x02 \x00 " },
116
+ {bson.M {"slice" : []byte {1 , 2 }},
117
+ "\x13 \x00 \x00 \x00 \x05 slice\x00 \x02 \x00 \x00 \x00 \x00 \x01 \x02 \x00 " },
114
118
}
115
119
116
120
func (s * S ) TestMarshalSampleItems (c * C ) {
@@ -343,6 +347,27 @@ func (s *S) TestOneWayMarshalItems(c *C) {
343
347
}
344
348
}
345
349
350
+ // --------------------------------------------------------------------------
351
+ // Some ops marshaling operations which would encode []uint8 or []byte in array.
352
+
353
+ var arrayOpsMarshalItems = []testItemType {
354
+ {bson.M {"_" : bson.M {"$in" : []uint8 {1 , 2 }}},
355
+ "\x03 _\x00 \x1d \x00 \x00 \x00 \x04 $in\x00 \x13 \x00 \x00 \x00 \x10 0\x00 \x01 \x00 \x00 \x00 \x10 1\x00 \x02 \x00 \x00 \x00 \x00 \x00 " },
356
+ {bson.M {"_" : bson.M {"$nin" : []uint8 {1 , 2 }}},
357
+ "\x03 _\x00 \x1e \x00 \x00 \x00 \x04 $nin\x00 \x13 \x00 \x00 \x00 \x10 0\x00 \x01 \x00 \x00 \x00 \x10 1\x00 \x02 \x00 \x00 \x00 \x00 \x00 " },
358
+ {bson.M {"_" : bson.M {"$all" : []uint8 {1 , 2 }}},
359
+ "\x03 _\x00 \x1e \x00 \x00 \x00 \x04 $all\x00 \x13 \x00 \x00 \x00 \x10 0\x00 \x01 \x00 \x00 \x00 \x10 1\x00 \x02 \x00 \x00 \x00 \x00 \x00 " },
360
+ }
361
+
362
+ func (s * S ) TestArrayOpsMarshalItems (c * C ) {
363
+ for i , item := range arrayOpsMarshalItems {
364
+ data , err := bson .Marshal (item .obj )
365
+ c .Assert (err , IsNil )
366
+ c .Assert (string (data ), Equals , wrapInDoc (item .data ),
367
+ Commentf ("Failed on item %d" , i ))
368
+ }
369
+ }
370
+
346
371
// --------------------------------------------------------------------------
347
372
// Two-way tests for user-defined structures using the samples
348
373
// from bsonspec.org.
0 commit comments