Skip to content

Commit 75c61d6

Browse files
authored
GODRIVER-1985 resync bson-corpus tests (#685)
1 parent dae2dee commit 75c61d6

File tree

10 files changed

+55
-42
lines changed

10 files changed

+55
-42
lines changed

bson/bson_corpus_spec_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,6 @@ func runTest(t *testing.T, file string) {
347347
t.Run("parse error", func(t *testing.T) {
348348
for _, p := range test.ParseErrors {
349349
t.Run(p.Description, func(t *testing.T) {
350-
// skip DBRef tests
351-
if strings.Contains(p.Description, "Bad DBRef") {
352-
t.Skip("skipping DBRef test")
353-
}
354-
355350
s := unescapeUnicode(p.String, test.BsonType)
356351
if test.BsonType == "0x13" {
357352
s = fmt.Sprintf(`{"decimal128": {"$numberDecimal": "%s"}}`, s)

bson/bsonrw/extjson_wrappers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ func wrapperKeyBSONType(key string) bsontype.Type {
4646
return bsontype.DBPointer
4747
case "$date":
4848
return bsontype.DateTime
49-
case "$ref":
50-
fallthrough
51-
case "$id":
52-
fallthrough
53-
case "$db":
54-
return bsontype.EmbeddedDocument // dbrefs aren't bson types
5549
case "$minKey":
5650
return bsontype.MinKey
5751
case "$maxKey":

data/bson-corpus/array.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
1515
},
1616
{
17-
"description": "Single Element Array with index set incorrectly",
17+
"description": "Single Element Array with index set incorrectly to empty string",
1818
"degenerate_bson": "130000000461000B00000010000A0000000000",
1919
"canonical_bson": "140000000461000C0000001030000A0000000000",
2020
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
2121
},
2222
{
23-
"description": "Single Element Array with index set incorrectly",
23+
"description": "Single Element Array with index set incorrectly to ab",
2424
"degenerate_bson": "150000000461000D000000106162000A0000000000",
2525
"canonical_bson": "140000000461000C0000001030000A0000000000",
2626
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
27+
},
28+
{
29+
"description": "Multi Element Array with duplicate indexes",
30+
"degenerate_bson": "1b000000046100130000001030000a000000103000140000000000",
31+
"canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
32+
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}"
2733
}
2834
],
2935
"decodeErrors": [

data/bson-corpus/datetime.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"description" : "Y10K",
2626
"canonical_bson" : "1000000009610000DC1FD277E6000000",
2727
"canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}"
28+
},
29+
{
30+
"description": "leading zero ms",
31+
"canonical_bson": "10000000096100D1D6D6CC3B01000000",
32+
"relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}",
33+
"canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}"
2834
}
2935
],
3036
"decodeErrors": [

data/bson-corpus/dbref.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
11
{
2-
"description": "DBRef",
2+
"description": "Document type (DBRef sub-documents)",
33
"bson_type": "0x03",
44
"valid": [
55
{
66
"description": "DBRef",
7-
"canonical_bson": "37000000036462726566002B0000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E0000",
7+
"canonical_bson": "37000000036462726566002b0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0000",
88
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
99
},
1010
{
1111
"description": "DBRef with database",
12-
"canonical_bson": "4300000003646272656600370000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E0224646200030000006462000000",
12+
"canonical_bson": "4300000003646272656600370000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0224646200030000006462000000",
1313
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": \"db\"}}"
1414
},
1515
{
1616
"description": "DBRef with database and additional fields",
17-
"canonical_bson": "48000000036462726566003C0000000224726566000B000000636F6C6C656374696F6E0010246964002A00000002246462000300000064620002666F6F0004000000626172000000",
17+
"canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e0010246964002a00000002246462000300000064620002666f6f0004000000626172000000",
1818
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$numberInt\": \"42\"}, \"$db\": \"db\", \"foo\": \"bar\"}}"
1919
},
2020
{
2121
"description": "DBRef with additional fields",
22-
"canonical_bson": "4400000003646272656600380000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E02666F6F0004000000626172000000",
22+
"canonical_bson": "4400000003646272656600380000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e02666f6f0004000000626172000000",
2323
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"foo\": \"bar\"}}"
2424
},
2525
{
2626
"description": "Document with key names similar to those of a DBRef",
27-
"canonical_bson": "3E0000000224726566000C0000006E6F742D612D646272656600072469640058921B3E6E32AB156A22B59E022462616E616E6100050000007065656C0000",
27+
"canonical_bson": "3e0000000224726566000c0000006e6f742d612d646272656600072469640058921b3e6e32ab156a22b59e022462616e616e6100050000007065656c0000",
2828
"canonical_extjson": "{\"$ref\": \"not-a-dbref\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$banana\": \"peel\"}"
29+
},
30+
{
31+
"description": "DBRef with additional dollar-prefixed and dotted fields",
32+
"canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000",
33+
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"a.b\": {\"$numberInt\": \"1\"}, \"$c\": {\"$numberInt\": \"1\"}}}"
34+
},
35+
{
36+
"description": "Sub-document resembles DBRef but $id is missing",
37+
"canonical_bson": "26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000",
38+
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\"}}"
39+
},
40+
{
41+
"description": "Sub-document resembles DBRef but $ref is not a string",
42+
"canonical_bson": "2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000",
43+
"canonical_extjson": "{\"dbref\": {\"$ref\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
44+
},
45+
{
46+
"description": "Sub-document resembles DBRef but $db is not a string",
47+
"canonical_bson": "4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000",
48+
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": {\"$numberInt\": \"1\"}}}"
2949
}
3050
]
3151
}

data/bson-corpus/decimal128-1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@
303303
},
304304
{
305305
"description": "Clamped",
306-
"canonical_bson": "180000001364000A00000000000000000000000000FE5F00",
306+
"canonical_bson": "180000001364000a00000000000000000000000000fe5f00",
307307
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E6112\"}}",
308308
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6112\"}}"
309309
},
310310
{
311311
"description": "Exact rounding",
312-
"canonical_bson": "18000000136400000000000A5BC138938D44C64D31CC3700",
312+
"canonical_bson": "18000000136400000000000a5bc138938d44c64d31cc3700",
313313
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}}",
314314
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+999\"}}"
315315
}

data/bson-corpus/double.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
"relaxed_extjson": "{\"d\" : -1.0001220703125}"
2929
},
3030
{
31-
"description": "1.23456789012345677E+18",
32-
"canonical_bson": "1000000001640081E97DF41022B14300",
33-
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.23456789012345677E+18\"}}",
34-
"relaxed_extjson": "{\"d\" : 1.23456789012345677E+18}"
31+
"description": "1.2345678921232E+18",
32+
"canonical_bson": "100000000164002a1bf5f41022b14300",
33+
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.2345678921232E+18\"}}",
34+
"relaxed_extjson": "{\"d\" : 1.2345678921232E+18}"
3535
},
3636
{
37-
"description": "-1.23456789012345677E+18",
38-
"canonical_bson": "1000000001640081E97DF41022B1C300",
39-
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.23456789012345677E+18\"}}",
40-
"relaxed_extjson": "{\"d\" : -1.23456789012345677E+18}"
37+
"description": "-1.2345678921232E+18",
38+
"canonical_bson": "100000000164002a1bf5f41022b1c300",
39+
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.2345678921232E+18\"}}",
40+
"relaxed_extjson": "{\"d\" : -1.2345678921232E+18}"
4141
},
4242
{
4343
"description": "0.0",

data/bson-corpus/string.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
"canonical_bson": "190000000261000D000000E29886E29886E29886E298860000",
2929
"canonical_extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}"
3030
},
31-
{
32-
"description": "four-byte UTF-8 (𝄞)",
33-
"canonical_bson": "1100000002610005000000F09D849E0000",
34-
"canonical_extjson": "{\"a\" : \"𝄞\"}"
35-
},
3631
{
3732
"description": "Embedded nulls",
3833
"canonical_bson": "190000000261000D0000006162006261620062616261620000",

data/bson-corpus/timestamp.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"description": "Timestamp with high-order bit set on both seconds and increment",
1919
"canonical_bson": "10000000116100FFFFFFFFFFFFFFFF00",
2020
"canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4294967295, \"i\" : 4294967295} } }"
21+
},
22+
{
23+
"description": "Timestamp with high-order bit set on both seconds and increment (not UINT32_MAX)",
24+
"canonical_bson": "1000000011610000286BEE00286BEE00",
25+
"canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4000000000, \"i\" : 4000000000} } }"
2126
}
2227
],
2328
"decodeErrors": [

data/bson-corpus/top.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@
214214
"description": "Bad $date (extra field)",
215215
"string": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}, \"unrelated\": true}}"
216216
},
217-
{
218-
"description": "Bad DBRef (ref is number, not string)",
219-
"string": "{\"x\" : {\"$ref\" : 42, \"$id\" : \"abc\"}}"
220-
},
221-
{
222-
"description": "Bad DBRef (db is number, not string)",
223-
"string": "{\"x\" : {\"$ref\" : \"a\", \"$id\" : \"abc\", \"$db\" : 42}}"
224-
},
225217
{
226218
"description": "Bad $minKey (boolean, not integer)",
227219
"string": "{\"a\" : {\"$minKey\" : true}}"

0 commit comments

Comments
 (0)