Skip to content

Commit

Permalink
GODRIVER-1985 resync bson-corpus tests (mongodb#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwysiu committed Jun 22, 2021
1 parent dae2dee commit 75c61d6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 42 deletions.
5 changes: 0 additions & 5 deletions bson/bson_corpus_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ func runTest(t *testing.T, file string) {
t.Run("parse error", func(t *testing.T) {
for _, p := range test.ParseErrors {
t.Run(p.Description, func(t *testing.T) {
// skip DBRef tests
if strings.Contains(p.Description, "Bad DBRef") {
t.Skip("skipping DBRef test")
}

s := unescapeUnicode(p.String, test.BsonType)
if test.BsonType == "0x13" {
s = fmt.Sprintf(`{"decimal128": {"$numberDecimal": "%s"}}`, s)
Expand Down
6 changes: 0 additions & 6 deletions bson/bsonrw/extjson_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ func wrapperKeyBSONType(key string) bsontype.Type {
return bsontype.DBPointer
case "$date":
return bsontype.DateTime
case "$ref":
fallthrough
case "$id":
fallthrough
case "$db":
return bsontype.EmbeddedDocument // dbrefs aren't bson types
case "$minKey":
return bsontype.MinKey
case "$maxKey":
Expand Down
10 changes: 8 additions & 2 deletions data/bson-corpus/array.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Single Element Array with index set incorrectly",
"description": "Single Element Array with index set incorrectly to empty string",
"degenerate_bson": "130000000461000B00000010000A0000000000",
"canonical_bson": "140000000461000C0000001030000A0000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Single Element Array with index set incorrectly",
"description": "Single Element Array with index set incorrectly to ab",
"degenerate_bson": "150000000461000D000000106162000A0000000000",
"canonical_bson": "140000000461000C0000001030000A0000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
},
{
"description": "Multi Element Array with duplicate indexes",
"degenerate_bson": "1b000000046100130000001030000a000000103000140000000000",
"canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
"canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}"
}
],
"decodeErrors": [
Expand Down
6 changes: 6 additions & 0 deletions data/bson-corpus/datetime.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"description" : "Y10K",
"canonical_bson" : "1000000009610000DC1FD277E6000000",
"canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}"
},
{
"description": "leading zero ms",
"canonical_bson": "10000000096100D1D6D6CC3B01000000",
"relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}",
"canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}"
}
],
"decodeErrors": [
Expand Down
32 changes: 26 additions & 6 deletions data/bson-corpus/dbref.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
{
"description": "DBRef",
"description": "Document type (DBRef sub-documents)",
"bson_type": "0x03",
"valid": [
{
"description": "DBRef",
"canonical_bson": "37000000036462726566002B0000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E0000",
"canonical_bson": "37000000036462726566002b0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
},
{
"description": "DBRef with database",
"canonical_bson": "4300000003646272656600370000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E0224646200030000006462000000",
"canonical_bson": "4300000003646272656600370000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0224646200030000006462000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": \"db\"}}"
},
{
"description": "DBRef with database and additional fields",
"canonical_bson": "48000000036462726566003C0000000224726566000B000000636F6C6C656374696F6E0010246964002A00000002246462000300000064620002666F6F0004000000626172000000",
"canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e0010246964002a00000002246462000300000064620002666f6f0004000000626172000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$numberInt\": \"42\"}, \"$db\": \"db\", \"foo\": \"bar\"}}"
},
{
"description": "DBRef with additional fields",
"canonical_bson": "4400000003646272656600380000000224726566000B000000636F6C6C656374696F6E00072469640058921B3E6E32AB156A22B59E02666F6F0004000000626172000000",
"canonical_bson": "4400000003646272656600380000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e02666f6f0004000000626172000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"foo\": \"bar\"}}"
},
{
"description": "Document with key names similar to those of a DBRef",
"canonical_bson": "3E0000000224726566000C0000006E6F742D612D646272656600072469640058921B3E6E32AB156A22B59E022462616E616E6100050000007065656C0000",
"canonical_bson": "3e0000000224726566000c0000006e6f742d612d646272656600072469640058921b3e6e32ab156a22b59e022462616e616e6100050000007065656c0000",
"canonical_extjson": "{\"$ref\": \"not-a-dbref\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$banana\": \"peel\"}"
},
{
"description": "DBRef with additional dollar-prefixed and dotted fields",
"canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"a.b\": {\"$numberInt\": \"1\"}, \"$c\": {\"$numberInt\": \"1\"}}}"
},
{
"description": "Sub-document resembles DBRef but $id is missing",
"canonical_bson": "26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\"}}"
},
{
"description": "Sub-document resembles DBRef but $ref is not a string",
"canonical_bson": "2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000",
"canonical_extjson": "{\"dbref\": {\"$ref\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
},
{
"description": "Sub-document resembles DBRef but $db is not a string",
"canonical_bson": "4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000",
"canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": {\"$numberInt\": \"1\"}}}"
}
]
}
4 changes: 2 additions & 2 deletions data/bson-corpus/decimal128-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@
},
{
"description": "Clamped",
"canonical_bson": "180000001364000A00000000000000000000000000FE5F00",
"canonical_bson": "180000001364000a00000000000000000000000000fe5f00",
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E6112\"}}",
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6112\"}}"
},
{
"description": "Exact rounding",
"canonical_bson": "18000000136400000000000A5BC138938D44C64D31CC3700",
"canonical_bson": "18000000136400000000000a5bc138938d44c64d31cc3700",
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}}",
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+999\"}}"
}
Expand Down
16 changes: 8 additions & 8 deletions data/bson-corpus/double.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
"relaxed_extjson": "{\"d\" : -1.0001220703125}"
},
{
"description": "1.23456789012345677E+18",
"canonical_bson": "1000000001640081E97DF41022B14300",
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.23456789012345677E+18\"}}",
"relaxed_extjson": "{\"d\" : 1.23456789012345677E+18}"
"description": "1.2345678921232E+18",
"canonical_bson": "100000000164002a1bf5f41022b14300",
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.2345678921232E+18\"}}",
"relaxed_extjson": "{\"d\" : 1.2345678921232E+18}"
},
{
"description": "-1.23456789012345677E+18",
"canonical_bson": "1000000001640081E97DF41022B1C300",
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.23456789012345677E+18\"}}",
"relaxed_extjson": "{\"d\" : -1.23456789012345677E+18}"
"description": "-1.2345678921232E+18",
"canonical_bson": "100000000164002a1bf5f41022b1c300",
"canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.2345678921232E+18\"}}",
"relaxed_extjson": "{\"d\" : -1.2345678921232E+18}"
},
{
"description": "0.0",
Expand Down
5 changes: 0 additions & 5 deletions data/bson-corpus/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
"canonical_bson": "190000000261000D000000E29886E29886E29886E298860000",
"canonical_extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}"
},
{
"description": "four-byte UTF-8 (𝄞)",
"canonical_bson": "1100000002610005000000F09D849E0000",
"canonical_extjson": "{\"a\" : \"𝄞\"}"
},
{
"description": "Embedded nulls",
"canonical_bson": "190000000261000D0000006162006261620062616261620000",
Expand Down
5 changes: 5 additions & 0 deletions data/bson-corpus/timestamp.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"description": "Timestamp with high-order bit set on both seconds and increment",
"canonical_bson": "10000000116100FFFFFFFFFFFFFFFF00",
"canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4294967295, \"i\" : 4294967295} } }"
},
{
"description": "Timestamp with high-order bit set on both seconds and increment (not UINT32_MAX)",
"canonical_bson": "1000000011610000286BEE00286BEE00",
"canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4000000000, \"i\" : 4000000000} } }"
}
],
"decodeErrors": [
Expand Down
8 changes: 0 additions & 8 deletions data/bson-corpus/top.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@
"description": "Bad $date (extra field)",
"string": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}, \"unrelated\": true}}"
},
{
"description": "Bad DBRef (ref is number, not string)",
"string": "{\"x\" : {\"$ref\" : 42, \"$id\" : \"abc\"}}"
},
{
"description": "Bad DBRef (db is number, not string)",
"string": "{\"x\" : {\"$ref\" : \"a\", \"$id\" : \"abc\", \"$db\" : 42}}"
},
{
"description": "Bad $minKey (boolean, not integer)",
"string": "{\"a\" : {\"$minKey\" : true}}"
Expand Down

0 comments on commit 75c61d6

Please sign in to comment.