Skip to content

Commit 510cee4

Browse files
authored
Sync BSON specification tests (#1555)
1 parent 1725e65 commit 510cee4

File tree

8 files changed

+214
-165
lines changed

8 files changed

+214
-165
lines changed

Diff for: bson/src/test/resources/bson/binary.json

+152-152
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,153 @@
11
{
2-
"description": "Binary type",
3-
"bson_type": "0x05",
4-
"test_key": "x",
5-
"valid": [
6-
{
7-
"description": "subtype 0x00 (Zero-length)",
8-
"canonical_bson": "0D000000057800000000000000",
9-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}"
10-
},
11-
{
12-
"description": "subtype 0x00 (Zero-length, keys reversed)",
13-
"canonical_bson": "0D000000057800000000000000",
14-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}",
15-
"degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}"
16-
},
17-
{
18-
"description": "subtype 0x00",
19-
"canonical_bson": "0F0000000578000200000000FFFF00",
20-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}"
21-
},
22-
{
23-
"description": "subtype 0x01",
24-
"canonical_bson": "0F0000000578000200000001FFFF00",
25-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}"
26-
},
27-
{
28-
"description": "subtype 0x02",
29-
"canonical_bson": "13000000057800060000000202000000FFFF00",
30-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}"
31-
},
32-
{
33-
"description": "subtype 0x03",
34-
"canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
35-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}"
36-
},
37-
{
38-
"description": "subtype 0x04",
39-
"canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
40-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
41-
},
42-
{
43-
"description": "subtype 0x04 UUID",
44-
"canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
45-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
46-
"degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
47-
},
48-
{
49-
"description": "subtype 0x05",
50-
"canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
51-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}"
52-
},
53-
{
54-
"description": "subtype 0x07",
55-
"canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
56-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
57-
},
58-
{
59-
"description": "subtype 0x08",
60-
"canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
61-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
62-
},
63-
{
64-
"description": "subtype 0x80",
65-
"canonical_bson": "0F0000000578000200000080FFFF00",
66-
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}"
67-
},
68-
{
69-
"description": "$type query operator (conflicts with legacy $binary form with $type field)",
70-
"canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000",
71-
"canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}"
72-
},
73-
{
74-
"description": "$type query operator (conflicts with legacy $binary form with $type field)",
75-
"canonical_bson": "180000000378001000000010247479706500020000000000",
76-
"canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}"
77-
},
78-
{
79-
"description": "subtype 0x09 Vector FLOAT32",
80-
"canonical_bson": "170000000578000A0000000927000000FE420000E04000",
81-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwAAAP5CAADgQA==\", \"subType\": \"09\"}}}"
82-
},
83-
{
84-
"description": "subtype 0x09 Vector INT8",
85-
"canonical_bson": "11000000057800040000000903007F0700",
86-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwB/Bw==\", \"subType\": \"09\"}}}"
87-
},
88-
{
89-
"description": "subtype 0x09 Vector PACKED_BIT",
90-
"canonical_bson": "11000000057800040000000910007F0700",
91-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAB/Bw==\", \"subType\": \"09\"}}}"
92-
},
93-
{
94-
"description": "subtype 0x09 Vector (Zero-length) FLOAT32",
95-
"canonical_bson": "0F0000000578000200000009270000",
96-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwA=\", \"subType\": \"09\"}}}"
97-
},
98-
{
99-
"description": "subtype 0x09 Vector (Zero-length) INT8",
100-
"canonical_bson": "0F0000000578000200000009030000",
101-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwA=\", \"subType\": \"09\"}}}"
102-
},
103-
{
104-
"description": "subtype 0x09 Vector (Zero-length) PACKED_BIT",
105-
"canonical_bson": "0F0000000578000200000009100000",
106-
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAA=\", \"subType\": \"09\"}}}"
107-
}
108-
],
109-
"decodeErrors": [
110-
{
111-
"description": "Length longer than document",
112-
"bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
113-
},
114-
{
115-
"description": "Negative length",
116-
"bson": "0D000000057800FFFFFFFF0000"
117-
},
118-
{
119-
"description": "subtype 0x02 length too long ",
120-
"bson": "13000000057800060000000203000000FFFF00"
121-
},
122-
{
123-
"description": "subtype 0x02 length too short",
124-
"bson": "13000000057800060000000201000000FFFF00"
125-
},
126-
{
127-
"description": "subtype 0x02 length negative one",
128-
"bson": "130000000578000600000002FFFFFFFFFFFF00"
129-
}
130-
],
131-
"parseErrors": [
132-
{
133-
"description": "$uuid wrong type",
134-
"string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
135-
},
136-
{
137-
"description": "$uuid invalid value--too short",
138-
"string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
139-
},
140-
{
141-
"description": "$uuid invalid value--too long",
142-
"string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}"
143-
},
144-
{
145-
"description": "$uuid invalid value--misplaced hyphens",
146-
"string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}"
147-
},
148-
{
149-
"description": "$uuid invalid value--too many hyphens",
150-
"string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}"
151-
}
152-
]
153-
}
2+
"description": "Binary type",
3+
"bson_type": "0x05",
4+
"test_key": "x",
5+
"valid": [
6+
{
7+
"description": "subtype 0x00 (Zero-length)",
8+
"canonical_bson": "0D000000057800000000000000",
9+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}"
10+
},
11+
{
12+
"description": "subtype 0x00 (Zero-length, keys reversed)",
13+
"canonical_bson": "0D000000057800000000000000",
14+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}",
15+
"degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}"
16+
},
17+
{
18+
"description": "subtype 0x00",
19+
"canonical_bson": "0F0000000578000200000000FFFF00",
20+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}"
21+
},
22+
{
23+
"description": "subtype 0x01",
24+
"canonical_bson": "0F0000000578000200000001FFFF00",
25+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}"
26+
},
27+
{
28+
"description": "subtype 0x02",
29+
"canonical_bson": "13000000057800060000000202000000FFFF00",
30+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}"
31+
},
32+
{
33+
"description": "subtype 0x03",
34+
"canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
35+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}"
36+
},
37+
{
38+
"description": "subtype 0x04",
39+
"canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
40+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
41+
},
42+
{
43+
"description": "subtype 0x04 UUID",
44+
"canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
45+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
46+
"degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
47+
},
48+
{
49+
"description": "subtype 0x05",
50+
"canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
51+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}"
52+
},
53+
{
54+
"description": "subtype 0x07",
55+
"canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
56+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
57+
},
58+
{
59+
"description": "subtype 0x08",
60+
"canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
61+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
62+
},
63+
{
64+
"description": "subtype 0x80",
65+
"canonical_bson": "0F0000000578000200000080FFFF00",
66+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}"
67+
},
68+
{
69+
"description": "$type query operator (conflicts with legacy $binary form with $type field)",
70+
"canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000",
71+
"canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}"
72+
},
73+
{
74+
"description": "$type query operator (conflicts with legacy $binary form with $type field)",
75+
"canonical_bson": "180000000378001000000010247479706500020000000000",
76+
"canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}"
77+
},
78+
{
79+
"description": "subtype 0x09 Vector FLOAT32",
80+
"canonical_bson": "170000000578000A0000000927000000FE420000E04000",
81+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwAAAP5CAADgQA==\", \"subType\": \"09\"}}}"
82+
},
83+
{
84+
"description": "subtype 0x09 Vector INT8",
85+
"canonical_bson": "11000000057800040000000903007F0700",
86+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwB/Bw==\", \"subType\": \"09\"}}}"
87+
},
88+
{
89+
"description": "subtype 0x09 Vector PACKED_BIT",
90+
"canonical_bson": "11000000057800040000000910007F0700",
91+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAB/Bw==\", \"subType\": \"09\"}}}"
92+
},
93+
{
94+
"description": "subtype 0x09 Vector (Zero-length) FLOAT32",
95+
"canonical_bson": "0F0000000578000200000009270000",
96+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwA=\", \"subType\": \"09\"}}}"
97+
},
98+
{
99+
"description": "subtype 0x09 Vector (Zero-length) INT8",
100+
"canonical_bson": "0F0000000578000200000009030000",
101+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwA=\", \"subType\": \"09\"}}}"
102+
},
103+
{
104+
"description": "subtype 0x09 Vector (Zero-length) PACKED_BIT",
105+
"canonical_bson": "0F0000000578000200000009100000",
106+
"canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAA=\", \"subType\": \"09\"}}}"
107+
}
108+
],
109+
"decodeErrors": [
110+
{
111+
"description": "Length longer than document",
112+
"bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
113+
},
114+
{
115+
"description": "Negative length",
116+
"bson": "0D000000057800FFFFFFFF0000"
117+
},
118+
{
119+
"description": "subtype 0x02 length too long ",
120+
"bson": "13000000057800060000000203000000FFFF00"
121+
},
122+
{
123+
"description": "subtype 0x02 length too short",
124+
"bson": "13000000057800060000000201000000FFFF00"
125+
},
126+
{
127+
"description": "subtype 0x02 length negative one",
128+
"bson": "130000000578000600000002FFFFFFFFFFFF00"
129+
}
130+
],
131+
"parseErrors": [
132+
{
133+
"description": "$uuid wrong type",
134+
"string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
135+
},
136+
{
137+
"description": "$uuid invalid value--too short",
138+
"string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
139+
},
140+
{
141+
"description": "$uuid invalid value--too long",
142+
"string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}"
143+
},
144+
{
145+
"description": "$uuid invalid value--misplaced hyphens",
146+
"string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}"
147+
},
148+
{
149+
"description": "$uuid invalid value--too many hyphens",
150+
"string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}"
151+
}
152+
]
153+
}

Diff for: bson/src/test/resources/bson/datetime.json

+6
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": [

Diff for: bson/src/test/resources/bson/dbref.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "DBRef",
2+
"description": "Document type (DBRef sub-documents)",
33
"bson_type": "0x03",
44
"valid": [
55
{
@@ -26,6 +26,26 @@
2626
"description": "Document with key names similar to those of a DBRef",
2727
"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
}

Diff for: bson/src/test/resources/bson/decimal128-1.json

+24
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,30 @@
312312
"canonical_bson": "18000000136400000000000a5bc138938d44c64d31cc3700",
313313
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}}",
314314
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+999\"}}"
315+
},
316+
{
317+
"description": "Clamped zeros with a large positive exponent",
318+
"canonical_bson": "180000001364000000000000000000000000000000FE5F00",
319+
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+2147483647\"}}",
320+
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}"
321+
},
322+
{
323+
"description": "Clamped zeros with a large negative exponent",
324+
"canonical_bson": "180000001364000000000000000000000000000000000000",
325+
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-2147483647\"}}",
326+
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}"
327+
},
328+
{
329+
"description": "Clamped negative zeros with a large positive exponent",
330+
"canonical_bson": "180000001364000000000000000000000000000000FEDF00",
331+
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+2147483647\"}}",
332+
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}"
333+
},
334+
{
335+
"description": "Clamped negative zeros with a large negative exponent",
336+
"canonical_bson": "180000001364000000000000000000000000000000008000",
337+
"degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-2147483647\"}}",
338+
"canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}"
315339
}
316340
]
317341
}

0 commit comments

Comments
 (0)