Debian Codegraph @

debian/patches/restore-tests.patch

raw
1 diff --git a/src/tests/binary_subtype.rs b/src/tests/binary_subtype.rs
2 new file mode 100644
3 index 0000000..71f2d71
4 --- /dev/null
5 +++ b/src/tests/binary_subtype.rs
6 @@ -0,0 +1,14 @@
7 +use crate::{spec::BinarySubtype, tests::LOCK};
8 +
9 +#[test]
10 +fn from_u8() {
11 + let _guard = LOCK.run_concurrently();
12 + // Check the endpoints of the defined, reserved, and user-defined subtype ranges.
13 + assert_eq!(BinarySubtype::from(0x00), BinarySubtype::Generic);
14 + assert_eq!(BinarySubtype::from(0x06), BinarySubtype::Encrypted);
15 + assert_eq!(BinarySubtype::from(0x07), BinarySubtype::Column);
16 + assert_eq!(BinarySubtype::from(0x08), BinarySubtype::Sensitive);
17 + assert_eq!(BinarySubtype::from(0x7F), BinarySubtype::Reserved(0x7F));
18 + assert_eq!(BinarySubtype::from(0x80), BinarySubtype::UserDefined(0x80));
19 + assert_eq!(BinarySubtype::from(0xFF), BinarySubtype::UserDefined(0xFF));
20 +}
21 diff --git a/src/tests/datetime.rs b/src/tests/datetime.rs
22 new file mode 100644
23 index 0000000..56bba31
24 --- /dev/null
25 +++ b/src/tests/datetime.rs
26 @@ -0,0 +1,61 @@
27 +use std::time::Duration;
28 +
29 +use crate::tests::LOCK;
30 +
31 +#[test]
32 +fn rfc3339_to_datetime() {
33 + let _guard = LOCK.run_concurrently();
34 +
35 + let rfc = "2020-06-09T10:58:07.095Z";
36 + let date =
37 + time::OffsetDateTime::parse(rfc, &time::format_description::well_known::Rfc3339).unwrap();
38 + let parsed = crate::DateTime::parse_rfc3339_str(rfc).unwrap();
39 + assert_eq!(parsed, crate::DateTime::from_time_0_3(date));
40 + assert_eq!(crate::DateTime::try_to_rfc3339_string(parsed).unwrap(), rfc);
41 +}
42 +
43 +#[test]
44 +fn invalid_rfc3339_to_datetime() {
45 + let _guard = LOCK.run_concurrently();
46 +
47 + let a = "2020-06-09T10:58:07-095Z";
48 + let b = "2020-06-09T10:58:07.095";
49 + let c = "2020-06-09T10:62:07.095Z";
50 + assert!(crate::DateTime::parse_rfc3339_str(a).is_err());
51 + assert!(crate::DateTime::parse_rfc3339_str(b).is_err());
52 + assert!(crate::DateTime::parse_rfc3339_str(c).is_err());
53 +}
54 +
55 +#[test]
56 +fn datetime_to_rfc3339() {
57 + assert_eq!(
58 + crate::DateTime::from_millis(0)
59 + .try_to_rfc3339_string()
60 + .unwrap(),
61 + "1970-01-01T00:00:00Z"
62 + );
63 +}
64 +
65 +#[test]
66 +fn invalid_datetime_to_rfc3339() {
67 + assert!(crate::DateTime::MAX.try_to_rfc3339_string().is_err());
68 +}
69 +
70 +#[test]
71 +fn duration_since() {
72 + let _guard = LOCK.run_concurrently();
73 +
74 + let date1 = crate::DateTime::from_millis(100);
75 + let date2 = crate::DateTime::from_millis(1000);
76 +
77 + assert_eq!(
78 + date2.checked_duration_since(date1),
79 + Some(Duration::from_millis(900))
80 + );
81 + assert_eq!(
82 + date2.saturating_duration_since(date1),
83 + Duration::from_millis(900)
84 + );
85 + assert!(date1.checked_duration_since(date2).is_none());
86 + assert_eq!(date1.saturating_duration_since(date2), Duration::ZERO);
87 +}
88 diff --git a/src/tests/mod.rs b/src/tests/mod.rs
89 new file mode 100644
90 index 0000000..23deeea
91 --- /dev/null
92 +++ b/src/tests/mod.rs
93 @@ -0,0 +1,10 @@
94 +mod binary_subtype;
95 +mod datetime;
96 +mod modules;
97 +mod serde;
98 +mod spec;
99 +
100 +use modules::TestLock;
101 +use once_cell::sync::Lazy;
102 +
103 +pub(crate) static LOCK: Lazy<TestLock> = Lazy::new(TestLock::new);
104 diff --git a/src/tests/modules/binary.rs b/src/tests/modules/binary.rs
105 new file mode 100644
106 index 0000000..d26c4d6
107 --- /dev/null
108 +++ b/src/tests/modules/binary.rs
109 @@ -0,0 +1,21 @@
110 +use crate::{spec::BinarySubtype, tests::LOCK, Binary};
111 +
112 +#[test]
113 +fn binary_from_base64() {
114 + let _guard = LOCK.run_concurrently();
115 +
116 + let input = base64::encode("hello");
117 + let produced = Binary::from_base64(input, None).unwrap();
118 + let expected = Binary {
119 + bytes: "hello".as_bytes().to_vec(),
120 + subtype: BinarySubtype::Generic,
121 + };
122 + assert_eq!(produced, expected);
123 +
124 + let produced = Binary::from_base64("", BinarySubtype::Uuid).unwrap();
125 + let expected = Binary {
126 + bytes: "".as_bytes().to_vec(),
127 + subtype: BinarySubtype::Uuid,
128 + };
129 + assert_eq!(produced, expected);
130 +}
131 diff --git a/src/tests/modules/bson.rs b/src/tests/modules/bson.rs
132 new file mode 100644
133 index 0000000..8bb66f8
134 --- /dev/null
135 +++ b/src/tests/modules/bson.rs
136 @@ -0,0 +1,488 @@
137 +use std::{
138 + convert::TryFrom,
139 + time::{Duration, SystemTime},
140 +};
141 +
142 +use crate::{
143 + doc,
144 + oid::ObjectId,
145 + spec::BinarySubtype,
146 + tests::LOCK,
147 + Binary,
148 + Bson,
149 + DateTime,
150 + Document,
151 + JavaScriptCodeWithScope,
152 + Regex,
153 + Timestamp,
154 +};
155 +
156 +use serde_json::{json, Value};
157 +
158 +#[test]
159 +fn to_json() {
160 + let _guard = LOCK.run_concurrently();
161 + let mut doc = Document::new();
162 + doc.insert(
163 + "_id",
164 + Bson::ObjectId(ObjectId::from_bytes(*b"abcdefghijkl")),
165 + );
166 + doc.insert("first", Bson::Int32(1));
167 + doc.insert("second", Bson::String("foo".to_owned()));
168 + doc.insert("alphanumeric", Bson::String("bar".to_owned()));
169 + let data: Value = Bson::Document(doc).into();
170 +
171 + assert!(data.is_object());
172 + let obj = data.as_object().unwrap();
173 +
174 + let id = obj.get("_id").unwrap();
175 + assert!(id.is_object());
176 + let id_val = id.get("$oid").unwrap();
177 + assert!(id_val.is_string());
178 + assert_eq!(id_val, "6162636465666768696a6b6c");
179 +
180 + let first = obj.get("first").unwrap();
181 + assert!(first.is_number());
182 + assert_eq!(first.as_i64().unwrap(), 1);
183 +
184 + let second = obj.get("second").unwrap();
185 + assert!(second.is_string());
186 + assert_eq!(second.as_str().unwrap(), "foo");
187 +
188 + let alphanumeric = obj.get("alphanumeric").unwrap();
189 + assert!(alphanumeric.is_string());
190 + assert_eq!(alphanumeric.as_str().unwrap(), "bar");
191 +}
192 +
193 +#[test]
194 +fn bson_default() {
195 + let _guard = LOCK.run_concurrently();
196 + let bson1 = Bson::default();
197 + assert_eq!(bson1, Bson::Null);
198 +}
199 +
200 +#[test]
201 +fn test_display_timestamp_type() {
202 + let x = Timestamp {
203 + time: 100,
204 + increment: 200,
205 + };
206 + let output = "Timestamp(100, 200)";
207 + assert_eq!(format!("{}", x), output);
208 + assert_eq!(format!("{}", Bson::from(x)), output);
209 +}
210 +
211 +#[test]
212 +fn test_display_regex_type() {
213 + let x = Regex {
214 + pattern: String::from("pattern"),
215 + options: String::from("options"),
216 + };
217 + let output = "/pattern/options";
218 + assert_eq!(format!("{}", x), output);
219 + assert_eq!(format!("{}", Bson::from(x)), output);
220 +}
221 +
222 +#[test]
223 +fn test_display_jscodewithcontext_type() {
224 + let x = JavaScriptCodeWithScope {
225 + code: String::from("code"),
226 + scope: doc! {"x": 2},
227 + };
228 + let output = "code";
229 + assert_eq!(format!("{}", x), output);
230 + assert_eq!(format!("{}", Bson::from(x)), output);
231 +}
232 +
233 +#[test]
234 +fn test_display_binary_type() {
235 + let encoded_bytes = "aGVsbG8gd29ybGQ=";
236 + let bytes = base64::decode(encoded_bytes).unwrap();
237 + let x = Binary {
238 + subtype: BinarySubtype::Generic,
239 + bytes,
240 + };
241 + let output = format!("Binary(0x0, {})", encoded_bytes);
242 + assert_eq!(format!("{}", x), output);
243 + assert_eq!(format!("{}", Bson::from(x)), output);
244 +}
245 +
246 +#[test]
247 +fn document_default() {
248 + let _guard = LOCK.run_concurrently();
249 + let doc1 = Document::default();
250 + assert_eq!(doc1.keys().count(), 0);
251 + assert_eq!(doc1, Document::new());
252 +}
253 +
254 +#[test]
255 +fn from_impls() {
256 + let _guard = LOCK.run_concurrently();
257 + assert_eq!(Bson::from(1.5f32), Bson::Double(1.5));
258 + assert_eq!(Bson::from(2.25f64), Bson::Double(2.25));
259 + assert_eq!(Bson::from("data"), Bson::String(String::from("data")));
260 + assert_eq!(
261 + Bson::from(String::from("data")),
262 + Bson::String(String::from("data"))
263 + );
264 + assert_eq!(Bson::from(doc! {}), Bson::Document(Document::new()));
265 + assert_eq!(Bson::from(false), Bson::Boolean(false));
266 + assert_eq!(
267 + Bson::from(Regex {
268 + pattern: String::from("\\s+$"),
269 + options: String::from("i")
270 + }),
271 + Bson::RegularExpression(Regex {
272 + pattern: String::from("\\s+$"),
273 + options: String::from("i")
274 + })
275 + );
276 + assert_eq!(
277 + Bson::from(JavaScriptCodeWithScope {
278 + code: String::from("alert(\"hi\");"),
279 + scope: doc! {}
280 + }),
281 + Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
282 + code: String::from("alert(\"hi\");"),
283 + scope: doc! {}
284 + })
285 + );
286 + //
287 + assert_eq!(
288 + Bson::from(Binary {
289 + subtype: BinarySubtype::Generic,
290 + bytes: vec![1, 2, 3]
291 + }),
292 + Bson::Binary(Binary {
293 + subtype: BinarySubtype::Generic,
294 + bytes: vec![1, 2, 3]
295 + })
296 + );
297 + assert_eq!(Bson::from(-48i32), Bson::Int32(-48));
298 + assert_eq!(Bson::from(-96i64), Bson::Int64(-96));
299 + assert_eq!(Bson::from(152u32), Bson::Int32(152));
300 +
301 + let oid = ObjectId::new();
302 + assert_eq!(
303 + Bson::from(b"abcdefghijkl"),
304 + Bson::ObjectId(ObjectId::from_bytes(*b"abcdefghijkl"))
305 + );
306 + assert_eq!(Bson::from(oid), Bson::ObjectId(oid));
307 + assert_eq!(
308 + Bson::from(vec![1, 2, 3]),
309 + Bson::Array(vec![Bson::Int32(1), Bson::Int32(2), Bson::Int32(3)])
310 + );
311 + assert_eq!(
312 + Bson::try_from(json!({"_id": {"$oid": oid.to_hex()}, "name": ["bson-rs"]})).unwrap(),
313 + Bson::Document(doc! {"_id": &oid, "name": ["bson-rs"]})
314 + );
315 +
316 + // References
317 + assert_eq!(Bson::from(&24i32), Bson::Int32(24));
318 + #[allow(clippy::unnecessary_fallible_conversions)]
319 + {
320 + assert_eq!(
321 + Bson::try_from(&String::from("data")).unwrap(),
322 + Bson::String(String::from("data"))
323 + );
324 + }
325 + assert_eq!(Bson::from(&oid), Bson::ObjectId(oid));
326 + assert_eq!(
327 + Bson::from(&doc! {"a": "b"}),
328 + Bson::Document(doc! {"a": "b"})
329 + );
330 +
331 + // Optionals
332 + assert_eq!(Bson::from(Some(4)), Bson::Int32(4));
333 + assert_eq!(
334 + Bson::from(Some(String::from("data"))),
335 + Bson::String(String::from("data"))
336 + );
337 + assert_eq!(Bson::from(None::<i32>), Bson::Null);
338 + assert_eq!(Bson::from(None::<String>), Bson::Null);
339 + assert_eq!(doc! {"x": Some(4)}, doc! {"x": 4});
340 + assert_eq!(doc! {"x": None::<i32>}, doc! {"x": Bson::Null});
341 +
342 + let db_pointer = Bson::try_from(json!({
343 + "$dbPointer": {
344 + "$ref": "db.coll",
345 + "$id": { "$oid": "507f1f77bcf86cd799439011" },
346 + }
347 + }))
348 + .unwrap();
349 + let db_pointer = db_pointer.as_db_pointer().unwrap();
350 + assert_eq!(Bson::from(db_pointer), Bson::DbPointer(db_pointer.clone()));
351 +}
352 +
353 +#[test]
354 +fn timestamp_ordering() {
355 + let _guard = LOCK.run_concurrently();
356 + let ts1 = Timestamp {
357 + time: 0,
358 + increment: 1,
359 + };
360 + let ts2 = Timestamp {
361 + time: 0,
362 + increment: 2,
363 + };
364 + let ts3 = Timestamp {
365 + time: 1,
366 + increment: 0,
367 + };
368 + assert!(ts1 < ts2);
369 + assert!(ts1 < ts3);
370 + assert!(ts2 < ts3);
371 +}
372 +
373 +#[test]
374 +fn from_external_datetime() {
375 + use time::macros::datetime;
376 +
377 + let _guard = LOCK.run_concurrently();
378 +
379 + fn assert_millisecond_precision(dt: DateTime) {
380 + assert!(dt.to_time_0_3().microsecond() % 1000 == 0);
381 + }
382 + fn assert_subsec_millis(dt: DateTime, millis: u32) {
383 + assert_eq!(dt.to_time_0_3().millisecond() as u32, millis)
384 + }
385 +
386 + let now = time::OffsetDateTime::now_utc();
387 + let dt = DateTime::from_time_0_3(now);
388 + assert_millisecond_precision(dt);
389 +
390 + #[cfg(feature = "time-0_3")]
391 + {
392 + let bson = Bson::from(now);
393 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
394 +
395 + let from_time = DateTime::from(now);
396 + assert_millisecond_precision(from_time);
397 + }
398 + #[cfg(feature = "chrono-0_4")]
399 + {
400 + let now = chrono::Utc::now();
401 + let bson = Bson::from(now);
402 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
403 +
404 + let from_chrono = DateTime::from(now);
405 + assert_millisecond_precision(from_chrono);
406 + }
407 +
408 + let no_subsec_millis = datetime!(2014-11-28 12:00:09 UTC);
409 + let dt = DateTime::from_time_0_3(no_subsec_millis);
410 + assert_millisecond_precision(dt);
411 + assert_subsec_millis(dt, 0);
412 +
413 + #[cfg(feature = "time-0_3")]
414 + {
415 + let bson = Bson::from(dt);
416 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
417 + assert_subsec_millis(bson.as_datetime().unwrap().to_owned(), 0);
418 + }
419 + #[cfg(feature = "chrono-0_4")]
420 + {
421 + let no_subsec_millis: chrono::DateTime<chrono::Utc> =
422 + "2014-11-28T12:00:09Z".parse().unwrap();
423 + let dt = DateTime::from(no_subsec_millis);
424 + assert_millisecond_precision(dt);
425 + assert_subsec_millis(dt, 0);
426 +
427 + let bson = Bson::from(dt);
428 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
429 + assert_subsec_millis(bson.as_datetime().unwrap().to_owned(), 0);
430 + }
431 +
432 + for s in &[
433 + "2014-11-28T12:00:09.123Z",
434 + "2014-11-28T12:00:09.123456Z",
435 + "2014-11-28T12:00:09.123456789Z",
436 + ] {
437 + let time_dt =
438 + time::OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339).unwrap();
439 + let dt = DateTime::from_time_0_3(time_dt);
440 + assert_millisecond_precision(dt);
441 + assert_subsec_millis(dt, 123);
442 +
443 + #[cfg(feature = "time-0_3")]
444 + {
445 + let bson = Bson::from(time_dt);
446 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
447 + assert_subsec_millis(bson.as_datetime().unwrap().to_owned(), 123);
448 + }
449 + #[cfg(feature = "chrono-0_4")]
450 + {
451 + let chrono_dt: chrono::DateTime<chrono::Utc> = s.parse().unwrap();
452 + let dt = DateTime::from(chrono_dt);
453 + assert_millisecond_precision(dt);
454 + assert_subsec_millis(dt, 123);
455 +
456 + let bson = Bson::from(chrono_dt);
457 + assert_millisecond_precision(bson.as_datetime().unwrap().to_owned());
458 + assert_subsec_millis(bson.as_datetime().unwrap().to_owned(), 123);
459 + }
460 + }
461 +
462 + #[cfg(feature = "time-0_3")]
463 + {
464 + let max = time::PrimitiveDateTime::MAX.assume_utc();
465 + let bdt = DateTime::from(max);
466 + assert_eq!(
467 + bdt.to_time_0_3().unix_timestamp_nanos() / 1_000_000, // truncate to millis
468 + max.unix_timestamp_nanos() / 1_000_000
469 + );
470 +
471 + let min = time::PrimitiveDateTime::MIN.assume_utc();
472 + let bdt = DateTime::from(min);
473 + assert_eq!(
474 + bdt.to_time_0_3().unix_timestamp_nanos() / 1_000_000,
475 + min.unix_timestamp_nanos() / 1_000_000
476 + );
477 +
478 + let bdt = DateTime::MAX;
479 + assert_eq!(bdt.to_time_0_3(), max);
480 +
481 + let bdt = DateTime::MIN;
482 + assert_eq!(bdt.to_time_0_3(), min);
483 + }
484 + #[cfg(feature = "chrono-0_4")]
485 + {
486 + use chrono::Utc;
487 +
488 + let bdt = DateTime::from(chrono::DateTime::<Utc>::MAX_UTC);
489 + assert_eq!(
490 + bdt.to_chrono().timestamp_millis(),
491 + chrono::DateTime::<Utc>::MAX_UTC.timestamp_millis()
492 + );
493 +
494 + let bdt = DateTime::from(chrono::DateTime::<Utc>::MIN_UTC);
495 + assert_eq!(
496 + bdt.to_chrono().timestamp_millis(),
497 + chrono::DateTime::<Utc>::MIN_UTC.timestamp_millis()
498 + );
499 +
500 + let bdt = DateTime::MAX;
501 + assert_eq!(bdt.to_chrono(), chrono::DateTime::<Utc>::MAX_UTC);
502 +
503 + let bdt = DateTime::MIN;
504 + assert_eq!(bdt.to_chrono(), chrono::DateTime::<Utc>::MIN_UTC);
505 + }
506 +}
507 +
508 +#[test]
509 +fn from_datetime_builder() {
510 + {
511 + let dt = DateTime::builder()
512 + .year(2022)
513 + .month(9)
514 + .day(15)
515 + .minute(2)
516 + .millisecond(1)
517 + .build();
518 + assert!(dt.is_ok());
519 + assert_eq!(
520 + DateTime::from_time_0_3(time::macros::datetime!(2022 - 09 - 15 00:02:00.001 UTC)),
521 + dt.unwrap()
522 + );
523 + }
524 +
525 + {
526 + let dt = DateTime::builder()
527 + .year(2022)
528 + .month(18)
529 + .day(15)
530 + .minute(2)
531 + .millisecond(1)
532 + .build();
533 + assert!(dt.is_err());
534 + }
535 +
536 + {
537 + let dt = DateTime::builder()
538 + .year(2022)
539 + .day(15)
540 + .month(18)
541 + .minute(83)
542 + .millisecond(1)
543 + .build();
544 + assert!(dt.is_err());
545 + }
546 +}
547 +
548 +#[test]
549 +fn system_time() {
550 + let _guard = LOCK.run_concurrently();
551 +
552 + let st = SystemTime::now();
553 + let bt_into: crate::DateTime = st.into();
554 + let bt_from = crate::DateTime::from_system_time(st);
555 +
556 + assert_eq!(bt_into, bt_from);
557 + assert_eq!(
558 + bt_into.timestamp_millis(),
559 + st.duration_since(SystemTime::UNIX_EPOCH)
560 + .unwrap()
561 + .as_millis() as i64
562 + );
563 +
564 + let st = SystemTime::UNIX_EPOCH
565 + .checked_add(Duration::from_millis(1234))
566 + .unwrap();
567 + let bt = crate::DateTime::from_system_time(st);
568 + assert_eq!(bt.timestamp_millis(), 1234);
569 + assert_eq!(bt.to_system_time(), st);
570 +
571 + assert_eq!(
572 + crate::DateTime::MAX.to_system_time(),
573 + SystemTime::UNIX_EPOCH + Duration::from_millis(i64::MAX as u64)
574 + );
575 + assert_eq!(
576 + crate::DateTime::MIN.to_system_time(),
577 + SystemTime::UNIX_EPOCH - Duration::from_millis((i64::MIN as i128).unsigned_abs() as u64)
578 + );
579 +
580 + assert_eq!(
581 + crate::DateTime::from_system_time(SystemTime::UNIX_EPOCH).timestamp_millis(),
582 + 0
583 + );
584 +}
585 +
586 +#[test]
587 +fn debug_print() {
588 + let oid = ObjectId::parse_str("000000000000000000000000").unwrap();
589 +
590 + let doc = doc! {
591 + "oid": oid,
592 + "arr": Bson::Array(vec! [
593 + Bson::Null,
594 + Bson::Timestamp(Timestamp { time: 1, increment: 1 }),
595 + ]),
596 + "doc": doc! { "a": 1, "b": "data"},
597 + };
598 + let normal_print = "Document({\"oid\": ObjectId(\"000000000000000000000000\"), \"arr\": \
599 + Array([Null, Timestamp { time: 1, increment: 1 }]), \"doc\": \
600 + Document({\"a\": Int32(1), \"b\": String(\"data\")})})";
601 + let pretty_print = "Document({
602 + \"oid\": ObjectId(
603 + \"000000000000000000000000\",
604 + ),
605 + \"arr\": Array([
606 + Null,
607 + Timestamp {
608 + time: 1,
609 + increment: 1,
610 + },
611 + ]),
612 + \"doc\": Document({
613 + \"a\": Int32(
614 + 1,
615 + ),
616 + \"b\": String(
617 + \"data\",
618 + ),
619 + }),
620 +})";
621 +
622 + assert_eq!(format!("{:?}", doc), normal_print);
623 + assert_eq!(format!("{:#?}", doc), pretty_print);
624 +}
625 diff --git a/src/tests/modules/document.rs b/src/tests/modules/document.rs
626 new file mode 100644
627 index 0000000..85fc62f
628 --- /dev/null
629 +++ b/src/tests/modules/document.rs
630 @@ -0,0 +1,247 @@
631 +use crate::{
632 + doc,
633 + document::ValueAccessError,
634 + oid::ObjectId,
635 + spec::BinarySubtype,
636 + tests::LOCK,
637 + Binary,
638 + Bson,
639 + Document,
640 + Timestamp,
641 +};
642 +use time::OffsetDateTime;
643 +
644 +#[test]
645 +fn ordered_insert() {
646 + let _guard = LOCK.run_concurrently();
647 + let mut doc = Document::new();
648 + doc.insert("first".to_owned(), Bson::Int32(1));
649 + doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
650 + doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
651 +
652 + let expected_keys = vec![
653 + "first".to_owned(),
654 + "second".to_owned(),
655 + "alphanumeric".to_owned(),
656 + ];
657 +
658 + let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
659 + assert_eq!(expected_keys, keys);
660 +}
661 +
662 +#[test]
663 +fn ordered_insert_shorthand() {
664 + let _guard = LOCK.run_concurrently();
665 + let mut doc = Document::new();
666 + doc.insert("first", 1i32);
667 + doc.insert("second", "foo");
668 + doc.insert("alphanumeric", "bar".to_owned());
669 +
670 + let expected_keys = vec![
671 + "first".to_owned(),
672 + "second".to_owned(),
673 + "alphanumeric".to_owned(),
674 + ];
675 +
676 + let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
677 + assert_eq!(expected_keys, keys);
678 +}
679 +
680 +#[test]
681 +fn test_getters() {
682 + let _guard = LOCK.run_concurrently();
683 + let datetime = OffsetDateTime::now_utc();
684 + let cloned_dt = crate::DateTime::from_time_0_3(datetime);
685 + let binary = vec![0, 1, 2, 3, 4];
686 + let mut doc = doc! {
687 + "floating_point": 10.0,
688 + "string": "a value",
689 + "array": [10, 20, 30],
690 + "doc": { "key": 1 },
691 + "bool": true,
692 + "i32": 1i32,
693 + "i64": 1i64,
694 + "datetime": cloned_dt,
695 + "binary": Binary { subtype: BinarySubtype::Generic, bytes: binary.clone() }
696 + };
697 +
698 + assert_eq!(None, doc.get("nonsense"));
699 + assert_eq!(Err(ValueAccessError::NotPresent), doc.get_str("nonsense"));
700 + assert_eq!(
701 + Err(ValueAccessError::UnexpectedType),
702 + doc.get_str("floating_point")
703 + );
704 +
705 + assert_eq!(Some(&Bson::Double(10.0)), doc.get("floating_point"));
706 + assert_eq!(Ok(10.0), doc.get_f64("floating_point"));
707 +
708 + assert_eq!(
709 + Some(&Bson::String("a value".to_string())),
710 + doc.get("string")
711 + );
712 + assert_eq!(Ok("a value"), doc.get_str("string"));
713 +
714 + let array = vec![Bson::Int32(10), Bson::Int32(20), Bson::Int32(30)];
715 + assert_eq!(Some(&Bson::Array(array.clone())), doc.get("array"));
716 + assert_eq!(Ok(&array), doc.get_array("array"));
717 +
718 + let embedded = doc! { "key": 1 };
719 + assert_eq!(Some(&Bson::Document(embedded.clone())), doc.get("doc"));
720 + assert_eq!(Ok(&embedded), doc.get_document("doc"));
721 +
722 + assert_eq!(Some(&Bson::Boolean(true)), doc.get("bool"));
723 + assert_eq!(Ok(true), doc.get_bool("bool"));
724 +
725 + doc.insert("null".to_string(), Bson::Null);
726 + assert_eq!(Some(&Bson::Null), doc.get("null"));
727 + assert!(doc.is_null("null"));
728 + assert!(!doc.is_null("array"));
729 +
730 + assert_eq!(Some(&Bson::Int32(1)), doc.get("i32"));
731 + assert_eq!(Ok(1i32), doc.get_i32("i32"));
732 +
733 + assert_eq!(Some(&Bson::Int64(1)), doc.get("i64"));
734 + assert_eq!(Ok(1i64), doc.get_i64("i64"));
735 +
736 + doc.insert(
737 + "timestamp".to_string(),
738 + Bson::Timestamp(Timestamp {
739 + time: 0,
740 + increment: 100,
741 + }),
742 + );
743 + assert_eq!(
744 + Some(&Bson::Timestamp(Timestamp {
745 + time: 0,
746 + increment: 100
747 + })),
748 + doc.get("timestamp")
749 + );
750 + assert_eq!(
751 + Ok(Timestamp {
752 + time: 0,
753 + increment: 100,
754 + }),
755 + doc.get_timestamp("timestamp")
756 + );
757 +
758 + let dt = crate::DateTime::from_time_0_3(datetime);
759 + assert_eq!(Some(&Bson::DateTime(dt)), doc.get("datetime"));
760 + assert_eq!(Ok(&dt), doc.get_datetime("datetime"));
761 +
762 + let object_id = ObjectId::new();
763 + doc.insert("_id".to_string(), Bson::ObjectId(object_id));
764 + assert_eq!(Some(&Bson::ObjectId(object_id)), doc.get("_id"));
765 + assert_eq!(Ok(object_id), doc.get_object_id("_id"));
766 +
767 + assert_eq!(
768 + Some(&Bson::Binary(Binary {
769 + subtype: BinarySubtype::Generic,
770 + bytes: binary.clone()
771 + })),
772 + doc.get("binary")
773 + );
774 + assert_eq!(Ok(&binary), doc.get_binary_generic("binary"));
775 +}
776 +
777 +#[test]
778 +fn remove() {
779 + let _guard = LOCK.run_concurrently();
780 +
781 + let mut doc = Document::new();
782 + doc.insert("first", 1i32);
783 + doc.insert("second", "foo");
784 + doc.insert("third", "bar".to_owned());
785 + doc.insert("fourth", "bar".to_owned());
786 +
787 + let mut expected_keys = vec![
788 + "first".to_owned(),
789 + "second".to_owned(),
790 + "third".to_owned(),
791 + "fourth".to_owned(),
792 + ];
793 +
794 + let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
795 + assert_eq!(expected_keys, keys);
796 +
797 + assert_eq!(doc.remove("none"), None);
798 +
799 + assert!(doc.remove("second").is_some());
800 + expected_keys.remove(1);
801 + let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
802 + assert_eq!(keys, expected_keys);
803 +
804 + assert!(doc.remove("first").is_some());
805 + expected_keys.remove(0);
806 + let keys: Vec<_> = doc.iter().map(|(key, _)| key.to_owned()).collect();
807 + assert_eq!(keys, expected_keys);
808 +}
809 +
810 +#[test]
811 +fn entry() {
812 + let _guard = LOCK.run_concurrently();
813 + let mut doc = doc! {
814 + "first": 1i32,
815 + "second": "foo",
816 + "alphanumeric": "bar",
817 + };
818 +
819 + {
820 + let first_entry = doc.entry("first".to_owned());
821 + assert_eq!(first_entry.key(), "first");
822 +
823 + let v = first_entry.or_insert_with(|| {
824 + Bson::Timestamp(Timestamp {
825 + time: 0,
826 + increment: 27,
827 + })
828 + });
829 + assert_eq!(v, &mut Bson::Int32(1));
830 + }
831 +
832 + {
833 + let fourth_entry = doc.entry("fourth".to_owned());
834 + assert_eq!(fourth_entry.key(), "fourth");
835 +
836 + let v = fourth_entry.or_insert(Bson::Null);
837 + assert_eq!(v, &mut Bson::Null);
838 + }
839 +
840 + assert_eq!(
841 + doc,
842 + doc! {
843 + "first": 1i32,
844 + "second": "foo",
845 + "alphanumeric": "bar",
846 + "fourth": Bson::Null,
847 + },
848 + );
849 +}
850 +
851 +#[test]
852 +fn extend() {
853 + let _guard = LOCK.run_concurrently();
854 + let mut doc1 = doc! {
855 + "first": 1,
856 + "second": "data",
857 + "subdoc": doc! { "a": 1, "b": 2 },
858 + };
859 +
860 + let doc2 = doc! {
861 + "third": "abcdefg",
862 + "first": 2,
863 + "subdoc": doc! { "c": 3 },
864 + };
865 +
866 + doc1.extend(doc2);
867 +
868 + assert_eq!(
869 + doc1,
870 + doc! {
871 + "first": 2,
872 + "second": "data",
873 + "third": "abcdefg",
874 + "subdoc": doc! { "c": 3 },
875 + },
876 + );
877 +}
878 diff --git a/src/tests/modules/lock.rs b/src/tests/modules/lock.rs
879 new file mode 100644
880 index 0000000..37963dd
881 --- /dev/null
882 +++ b/src/tests/modules/lock.rs
883 @@ -0,0 +1,20 @@
884 +use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
885 +
886 +#[derive(Default)]
887 +pub struct TestLock {
888 + inner: RwLock<()>,
889 +}
890 +
891 +impl TestLock {
892 + pub fn new() -> Self {
893 + Default::default()
894 + }
895 +
896 + pub fn run_concurrently(&self) -> RwLockReadGuard<'_, ()> {
897 + self.inner.read().unwrap()
898 + }
899 +
900 + pub fn run_exclusively(&self) -> RwLockWriteGuard<'_, ()> {
901 + self.inner.write().unwrap()
902 + }
903 +}
904 diff --git a/src/tests/modules/macros.rs b/src/tests/modules/macros.rs
905 new file mode 100644
906 index 0000000..150e22d
907 --- /dev/null
908 +++ b/src/tests/modules/macros.rs
909 @@ -0,0 +1,275 @@
910 +use crate::{
911 + doc,
912 + oid::ObjectId,
913 + spec::BinarySubtype,
914 + tests::LOCK,
915 + Binary,
916 + Bson,
917 + RawBson,
918 + Regex,
919 + Timestamp,
920 +};
921 +use pretty_assertions::assert_eq;
922 +
923 +#[test]
924 +fn standard_format() {
925 + let _guard = LOCK.run_concurrently();
926 + let id_string = "thisismyname";
927 + let string_bytes: Vec<_> = id_string.bytes().collect();
928 + let mut bytes = [0; 12];
929 + bytes[..12].clone_from_slice(&string_bytes[..12]);
930 +
931 + let id = ObjectId::from_bytes(bytes);
932 + let date = time::OffsetDateTime::now_utc();
933 +
934 + let doc = doc! {
935 + "float": 2.4,
936 + "string": "hello",
937 + "array": ["testing", 1, true, [1, 2]],
938 + "doc": {
939 + "fish": "in",
940 + "a": "barrel",
941 + "!": 1,
942 + },
943 + "bool": true,
944 + "null": null,
945 + "regexp": Bson::RegularExpression(Regex { pattern: "s[ao]d".to_owned(), options: "i".to_owned() }),
946 + "with_wrapped_parens": (-20),
947 + "code": Bson::JavaScriptCode("function(x) { return x._id; }".to_owned()),
948 + "i32": 12,
949 + "i64": -55,
950 + "timestamp": Bson::Timestamp(Timestamp { time: 0, increment: 229_999_444 }),
951 + "binary": Binary { subtype: BinarySubtype::Md5, bytes: "thingies".to_owned().into_bytes() },
952 + "encrypted": Binary { subtype: BinarySubtype::Encrypted, bytes: "secret".to_owned().into_bytes() },
953 + "_id": id,
954 + "date": Bson::DateTime(crate::DateTime::from_time_0_3(date)),
955 + };
956 +
957 + let rawdoc = rawdoc! {
958 + "float": 2.4,
959 + "string": "hello",
960 + "array": ["testing", 1, true, [1, 2]],
961 + "doc": {
962 + "fish": "in",
963 + "a": "barrel",
964 + "!": 1,
965 + },
966 + "bool": true,
967 + "null": null,
968 + "regexp": Regex { pattern: "s[ao]d".to_owned(), options: "i".to_owned() },
969 + "with_wrapped_parens": (-20),
970 + "code": RawBson::JavaScriptCode("function(x) { return x._id; }".to_owned()),
971 + "i32": 12,
972 + "i64": -55,
973 + "timestamp": Timestamp { time: 0, increment: 229_999_444 },
974 + "binary": Binary { subtype: BinarySubtype::Md5, bytes: "thingies".to_owned().into_bytes() },
975 + "encrypted": Binary { subtype: BinarySubtype::Encrypted, bytes: "secret".to_owned().into_bytes() },
976 + "_id": id,
977 + "date": crate::DateTime::from_time_0_3(date),
978 + };
979 +
980 + let ts_nanos = date.unix_timestamp_nanos();
981 + let ts_millis = ts_nanos - (ts_nanos % 1_000_000);
982 + let date_trunc = time::OffsetDateTime::from_unix_timestamp_nanos(ts_millis).unwrap();
983 + let expected = format!(
984 + "{{ \"float\": 2.4, \"string\": \"hello\", \"array\": [\"testing\", 1, true, [1, 2]], \
985 + \"doc\": {{ \"fish\": \"in\", \"a\": \"barrel\", \"!\": 1 }}, \"bool\": true, \"null\": \
986 + null, \"regexp\": /s[ao]d/i, \"with_wrapped_parens\": -20, \"code\": function(x) {{ \
987 + return x._id; }}, \"i32\": 12, \"i64\": -55, \"timestamp\": Timestamp(0, 229999444), \
988 + \"binary\": Binary(0x5, {}), \"encrypted\": Binary(0x6, {}), \"_id\": ObjectId(\"{}\"), \
989 + \"date\": DateTime(\"{}\") }}",
990 + base64::encode("thingies"),
991 + base64::encode("secret"),
992 + hex::encode(id_string),
993 + date_trunc,
994 + );
995 +
996 + assert_eq!(expected, format!("{}", doc));
997 +
998 + assert_eq!(rawdoc.into_bytes(), crate::to_vec(&doc).unwrap());
999 +}
1000 +
1001 +#[test]
1002 +fn non_trailing_comma() {
1003 + let _guard = LOCK.run_concurrently();
1004 + let doc = doc! {
1005 + "a": "foo",
1006 + "b": { "ok": "then" }
1007 + };
1008 +
1009 + let expected = "{ \"a\": \"foo\", \"b\": { \"ok\": \"then\" } }".to_string();
1010 + assert_eq!(expected, format!("{}", doc));
1011 +}
1012 +
1013 +#[test]
1014 +#[allow(clippy::float_cmp)]
1015 +fn recursive_macro() {
1016 + let _guard = LOCK.run_concurrently();
1017 + let doc = doc! {
1018 + "a": "foo",
1019 + "b": {
1020 + "bar": {
1021 + "harbor": ["seal", false],
1022 + "jelly": 42.0,
1023 + },
1024 + "grape": 27,
1025 + },
1026 + "c": [-7],
1027 + "d": [
1028 + {
1029 + "apple": "ripe",
1030 + }
1031 + ],
1032 + "e": { "single": "test" },
1033 + "n": (Bson::Null),
1034 + };
1035 + let rawdoc = rawdoc! {
1036 + "a": "foo",
1037 + "b": {
1038 + "bar": {
1039 + "harbor": ["seal", false],
1040 + "jelly": 42.0,
1041 + },
1042 + "grape": 27,
1043 + },
1044 + "c": [-7],
1045 + "d": [
1046 + {
1047 + "apple": "ripe",
1048 + }
1049 + ],
1050 + "e": { "single": "test" },
1051 + "n": (RawBson::Null),
1052 + };
1053 +
1054 + match doc.get("a") {
1055 + Some(Bson::String(s)) => assert_eq!("foo", s),
1056 + _ => panic!("String 'foo' was not inserted correctly."),
1057 + }
1058 +
1059 + // Inner Doc 1
1060 + match doc.get("b") {
1061 + Some(Bson::Document(doc)) => {
1062 + // Inner doc 2
1063 + match doc.get("bar") {
1064 + Some(Bson::Document(inner_doc)) => {
1065 + // Inner array
1066 + match inner_doc.get("harbor") {
1067 + Some(Bson::Array(arr)) => {
1068 + assert_eq!(2, arr.len());
1069 +
1070 + // Match array items
1071 + match arr.first() {
1072 + Some(Bson::String(ref s)) => assert_eq!("seal", s),
1073 + _ => panic!(
1074 + "String 'seal' was not inserted into inner array correctly."
1075 + ),
1076 + }
1077 + match arr.get(1) {
1078 + Some(Bson::Boolean(ref b)) => assert!(!b),
1079 + _ => panic!(
1080 + "Bool 'false' was not inserted into inner array correctly."
1081 + ),
1082 + }
1083 + }
1084 + _ => panic!("Inner array was not inserted correctly."),
1085 + }
1086 +
1087 + // Inner floating point
1088 + match inner_doc.get("jelly") {
1089 + Some(Bson::Double(fp)) => assert_eq!(42.0, *fp),
1090 + _ => panic!("Floating point 42.0 was not inserted correctly."),
1091 + }
1092 + }
1093 + _ => panic!("Second inner document was not inserted correctly."),
1094 + }
1095 + }
1096 + _ => panic!("Inner document was not inserted correctly."),
1097 + }
1098 +
1099 + // Single-item array
1100 + match doc.get("c") {
1101 + Some(Bson::Array(arr)) => {
1102 + assert_eq!(1, arr.len());
1103 +
1104 + // Integer type
1105 + match arr.first() {
1106 + Some(Bson::Int32(ref i)) => assert_eq!(-7, *i),
1107 + _ => panic!("I32 '-7' was not inserted correctly."),
1108 + }
1109 + }
1110 + _ => panic!("Single-item array was not inserted correctly."),
1111 + }
1112 +
1113 + // Document nested in array
1114 + match doc.get("d") {
1115 + Some(Bson::Array(arr)) => {
1116 + assert_eq!(1, arr.len());
1117 +
1118 + // Nested document
1119 + match arr.first() {
1120 + Some(Bson::Document(ref doc)) => {
1121 + // String
1122 + match doc.get("apple") {
1123 + Some(Bson::String(s)) => assert_eq!("ripe", s),
1124 + _ => panic!("String 'ripe' was not inserted correctly."),
1125 + }
1126 + }
1127 + _ => panic!("Document was not inserted into array correctly."),
1128 + }
1129 + }
1130 + _ => panic!("Array was not inserted correctly."),
1131 + }
1132 +
1133 + // Single-item document
1134 + match doc.get("e") {
1135 + Some(Bson::Document(bdoc)) => {
1136 + // String
1137 + match bdoc.get("single") {
1138 + Some(Bson::String(s)) => assert_eq!("test", s),
1139 + _ => panic!("String 'test' was not inserted correctly."),
1140 + }
1141 + }
1142 + _ => panic!("Single-item document was not inserted correctly."),
1143 + }
1144 +
1145 + match doc.get("n") {
1146 + Some(&Bson::Null) => {
1147 + // It was null
1148 + }
1149 + _ => panic!("Null was not inserted correctly."),
1150 + }
1151 +
1152 + assert_eq!(rawdoc.into_bytes(), crate::to_vec(&doc).unwrap());
1153 +}
1154 +
1155 +#[test]
1156 +#[allow(clippy::from_over_into)]
1157 +fn can_use_macro_with_into_bson() {
1158 + struct Custom;
1159 +
1160 + impl Into<Bson> for Custom {
1161 + fn into(self) -> Bson {
1162 + "foo".into()
1163 + }
1164 + }
1165 +
1166 + impl Into<RawBson> for Custom {
1167 + fn into(self) -> RawBson {
1168 + "foo".into()
1169 + }
1170 + }
1171 +
1172 + _ = bson!({
1173 + "a": Custom,
1174 + });
1175 + _ = doc! {
1176 + "a": Custom,
1177 + };
1178 + _ = rawbson!({
1179 + "a": Custom,
1180 + });
1181 + _ = rawdoc! {
1182 + "a": Custom,
1183 + };
1184 +}
1185 diff --git a/src/tests/modules/mod.rs b/src/tests/modules/mod.rs
1186 new file mode 100644
1187 index 0000000..d55a287
1188 --- /dev/null
1189 +++ b/src/tests/modules/mod.rs
1190 @@ -0,0 +1,10 @@
1191 +mod binary;
1192 +mod bson;
1193 +mod document;
1194 +mod lock;
1195 +mod macros;
1196 +mod oid;
1197 +mod ser;
1198 +mod serializer_deserializer;
1199 +
1200 +pub use self::lock::TestLock;
1201 diff --git a/src/tests/modules/oid.rs b/src/tests/modules/oid.rs
1202 new file mode 100644
1203 index 0000000..b875eaa
1204 --- /dev/null
1205 +++ b/src/tests/modules/oid.rs
1206 @@ -0,0 +1,60 @@
1207 +use crate::{oid::ObjectId, tests::LOCK};
1208 +
1209 +#[test]
1210 +fn string_oid() {
1211 + let _guard = LOCK.run_concurrently();
1212 + let s = "123456789012123456789012";
1213 + let oid_res = ObjectId::parse_str(s);
1214 + assert!(oid_res.is_ok());
1215 + let actual_s = hex::encode(oid_res.unwrap().bytes());
1216 + assert_eq!(s.to_owned(), actual_s);
1217 +}
1218 +
1219 +#[test]
1220 +fn byte_string_oid() {
1221 + let _guard = LOCK.run_concurrently();
1222 + let s = "541b1a00e8a23afa832b218e";
1223 + let oid_res = ObjectId::parse_str(s);
1224 + assert!(oid_res.is_ok());
1225 + let oid = oid_res.unwrap();
1226 + let bytes: [u8; 12] = [
1227 + 0x54u8, 0x1Bu8, 0x1Au8, 0x00u8, 0xE8u8, 0xA2u8, 0x3Au8, 0xFAu8, 0x83u8, 0x2Bu8, 0x21u8,
1228 + 0x8Eu8,
1229 + ];
1230 +
1231 + assert_eq!(bytes, oid.bytes());
1232 + assert_eq!(s, oid.to_string());
1233 +}
1234 +
1235 +#[test]
1236 +#[allow(clippy::eq_op)]
1237 +fn oid_equals() {
1238 + let _guard = LOCK.run_concurrently();
1239 + let oid = ObjectId::new();
1240 + assert_eq!(oid, oid);
1241 +}
1242 +
1243 +#[test]
1244 +fn oid_not_equals() {
1245 + let _guard = LOCK.run_concurrently();
1246 + assert!(ObjectId::new() != ObjectId::new());
1247 +}
1248 +
1249 +// check that the last byte in objectIDs is increasing
1250 +#[test]
1251 +fn counter_increasing() {
1252 + let _guard = LOCK.run_concurrently();
1253 + let oid1_bytes = ObjectId::new().bytes();
1254 + let oid2_bytes = ObjectId::new().bytes();
1255 + assert!(oid1_bytes[11] < oid2_bytes[11]);
1256 +}
1257 +
1258 +#[test]
1259 +fn fromstr_oid() {
1260 + let _guard = LOCK.run_concurrently();
1261 + let s = "123456789012123456789012";
1262 + let oid_res = s.parse::<ObjectId>();
1263 + assert!(oid_res.is_ok(), "oid parse failed");
1264 + let actual_s = hex::encode(oid_res.unwrap().bytes());
1265 + assert_eq!(s, &actual_s, "parsed and expected oids differ");
1266 +}
1267 diff --git a/src/tests/modules/ser.rs b/src/tests/modules/ser.rs
1268 new file mode 100644
1269 index 0000000..3b93bbb
1270 --- /dev/null
1271 +++ b/src/tests/modules/ser.rs
1272 @@ -0,0 +1,172 @@
1273 +use std::{collections::BTreeMap, u16, u32, u64, u8};
1274 +
1275 +use assert_matches::assert_matches;
1276 +
1277 +use crate::{from_bson, oid::ObjectId, ser, tests::LOCK, to_bson, to_vec, Bson, Document, Regex};
1278 +
1279 +#[test]
1280 +#[allow(clippy::float_cmp)]
1281 +fn floating_point() {
1282 + let _guard = LOCK.run_concurrently();
1283 + let obj = Bson::Double(240.5);
1284 + let f: f64 = from_bson(obj.clone()).unwrap();
1285 + assert_eq!(f, 240.5);
1286 +
1287 + let deser: Bson = to_bson(&f).unwrap();
1288 + assert_eq!(obj, deser);
1289 +}
1290 +
1291 +#[test]
1292 +fn string() {
1293 + let _guard = LOCK.run_concurrently();
1294 + let obj = Bson::String("avocado".to_owned());
1295 + let s: String = from_bson(obj.clone()).unwrap();
1296 + assert_eq!(s, "avocado");
1297 +
1298 + let deser: Bson = to_bson(&s).unwrap();
1299 + assert_eq!(obj, deser);
1300 +}
1301 +
1302 +#[test]
1303 +fn arr() {
1304 + let _guard = LOCK.run_concurrently();
1305 + let obj = Bson::Array(vec![
1306 + Bson::Int32(0),
1307 + Bson::Int32(1),
1308 + Bson::Int32(2),
1309 + Bson::Int32(3),
1310 + ]);
1311 + let arr: Vec<i32> = from_bson(obj.clone()).unwrap();
1312 + assert_eq!(arr, vec![0i32, 1i32, 2i32, 3i32]);
1313 +
1314 + let deser: Bson = to_bson(&arr).unwrap();
1315 + assert_eq!(deser, obj);
1316 +}
1317 +
1318 +#[test]
1319 +fn boolean() {
1320 + let _guard = LOCK.run_concurrently();
1321 + let obj = Bson::Boolean(true);
1322 + let b: bool = from_bson(obj.clone()).unwrap();
1323 + assert!(b);
1324 +
1325 + let deser: Bson = to_bson(&b).unwrap();
1326 + assert_eq!(deser, obj);
1327 +}
1328 +
1329 +#[test]
1330 +fn int32() {
1331 + let _guard = LOCK.run_concurrently();
1332 + let obj = Bson::Int32(101);
1333 + let i: i32 = from_bson(obj.clone()).unwrap();
1334 +
1335 + assert_eq!(i, 101);
1336 +
1337 + let deser: Bson = to_bson(&i).unwrap();
1338 + assert_eq!(deser, obj);
1339 +}
1340 +
1341 +#[test]
1342 +fn uint8_u2i() {
1343 + let _guard = LOCK.run_concurrently();
1344 + let obj: Bson = to_bson(&u8::MIN).unwrap();
1345 + let deser: u8 = from_bson(obj).unwrap();
1346 + assert_eq!(deser, u8::MIN);
1347 +
1348 + let obj_max: Bson = to_bson(&u8::MAX).unwrap();
1349 + let deser_max: u8 = from_bson(obj_max).unwrap();
1350 + assert_eq!(deser_max, u8::MAX);
1351 +}
1352 +
1353 +#[test]
1354 +fn uint16_u2i() {
1355 + let _guard = LOCK.run_concurrently();
1356 + let obj: Bson = to_bson(&u16::MIN).unwrap();
1357 + let deser: u16 = from_bson(obj).unwrap();
1358 + assert_eq!(deser, u16::MIN);
1359 +
1360 + let obj_max: Bson = to_bson(&u16::MAX).unwrap();
1361 + let deser_max: u16 = from_bson(obj_max).unwrap();
1362 + assert_eq!(deser_max, u16::MAX);
1363 +}
1364 +
1365 +#[test]
1366 +fn uint32_u2i() {
1367 + let _guard = LOCK.run_concurrently();
1368 + let obj_min: Bson = to_bson(&u32::MIN).unwrap();
1369 + let deser_min: u32 = from_bson(obj_min).unwrap();
1370 + assert_eq!(deser_min, u32::MIN);
1371 +
1372 + let obj_max: Bson = to_bson(&u32::MAX).unwrap();
1373 + let deser_max: u32 = from_bson(obj_max).unwrap();
1374 + assert_eq!(deser_max, u32::MAX);
1375 +}
1376 +
1377 +#[test]
1378 +fn uint64_u2i() {
1379 + let _guard = LOCK.run_concurrently();
1380 + let obj_min: Bson = to_bson(&u64::MIN).unwrap();
1381 + let deser_min: u64 = from_bson(obj_min).unwrap();
1382 + assert_eq!(deser_min, u64::MIN);
1383 +
1384 + let obj_max: ser::Result<Bson> = to_bson(&u64::MAX);
1385 + assert_matches!(
1386 + obj_max,
1387 + Err(ser::Error::UnsignedIntegerExceededRange(u64::MAX))
1388 + );
1389 +}
1390 +
1391 +#[test]
1392 +fn int64() {
1393 + let _guard = LOCK.run_concurrently();
1394 + let obj = Bson::Int64(101);
1395 + let i: i64 = from_bson(obj.clone()).unwrap();
1396 + assert_eq!(i, 101);
1397 +
1398 + let deser: Bson = to_bson(&i).unwrap();
1399 + assert_eq!(deser, obj);
1400 +}
1401 +
1402 +#[test]
1403 +fn oid() {
1404 + let _guard = LOCK.run_concurrently();
1405 + let oid = ObjectId::new();
1406 + let obj = Bson::ObjectId(oid);
1407 + let s: BTreeMap<String, String> = from_bson(obj.clone()).unwrap();
1408 +
1409 + let mut expected = BTreeMap::new();
1410 + expected.insert("$oid".to_owned(), oid.to_string());
1411 + assert_eq!(s, expected);
1412 +
1413 + let deser: Bson = to_bson(&s).unwrap();
1414 + assert_eq!(deser, obj);
1415 +}
1416 +
1417 +#[test]
1418 +fn cstring_null_bytes_error() {
1419 + let _guard = LOCK.run_concurrently();
1420 +
1421 + let doc = doc! { "\0": "a" };
1422 + verify_doc(doc);
1423 +
1424 + let doc = doc! { "a": { "\0": "b" } };
1425 + verify_doc(doc);
1426 +
1427 + let regex = doc! { "regex": Regex { pattern: "\0".into(), options: "a".into() } };
1428 + verify_doc(regex);
1429 +
1430 + let regex = doc! { "regex": Regex { pattern: "a".into(), options: "\0".into() } };
1431 + verify_doc(regex);
1432 +
1433 + fn verify_doc(doc: Document) {
1434 + let mut vec = Vec::new();
1435 + assert!(matches!(
1436 + doc.to_writer(&mut vec).unwrap_err(),
1437 + ser::Error::InvalidCString(_)
1438 + ));
1439 + assert!(matches!(
1440 + to_vec(&doc).unwrap_err(),
1441 + ser::Error::InvalidCString(_)
1442 + ));
1443 + }
1444 +}
1445 diff --git a/src/tests/modules/serializer_deserializer.rs b/src/tests/modules/serializer_deserializer.rs
1446 new file mode 100644
1447 index 0000000..2f47684
1448 --- /dev/null
1449 +++ b/src/tests/modules/serializer_deserializer.rs
1450 @@ -0,0 +1,573 @@
1451 +use std::{
1452 + convert::TryFrom,
1453 + io::{Cursor, Write},
1454 +};
1455 +
1456 +use serde::{Deserialize, Serialize};
1457 +
1458 +use crate::{
1459 + de::from_document,
1460 + doc,
1461 + oid::ObjectId,
1462 + ser::Error,
1463 + spec::BinarySubtype,
1464 + tests::LOCK,
1465 + to_document,
1466 + Binary,
1467 + Bson,
1468 + Decimal128,
1469 + Document,
1470 + JavaScriptCodeWithScope,
1471 + Regex,
1472 + Timestamp,
1473 +};
1474 +use serde_json::json;
1475 +
1476 +#[test]
1477 +fn test_serialize_deserialize_floating_point() {
1478 + let _guard = LOCK.run_concurrently();
1479 + let src = 1020.123;
1480 + let dst = vec![
1481 + 18, 0, 0, 0, 1, 107, 101, 121, 0, 68, 139, 108, 231, 251, 224, 143, 64, 0,
1482 + ];
1483 +
1484 + let doc = doc! { "key": src };
1485 +
1486 + let mut buf = Vec::new();
1487 + doc.to_writer(&mut buf).unwrap();
1488 +
1489 + assert_eq!(buf, dst);
1490 +
1491 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1492 + assert_eq!(deserialized, doc);
1493 +}
1494 +
1495 +#[test]
1496 +fn test_serialize_deserialize_utf8_string() {
1497 + let _guard = LOCK.run_concurrently();
1498 + let src = "test你好吗".to_owned();
1499 + let dst = vec![
1500 + 28, 0, 0, 0, 2, 107, 101, 121, 0, 14, 0, 0, 0, 116, 101, 115, 116, 228, 189, 160, 229, 165,
1501 + 189, 229, 144, 151, 0, 0,
1502 + ];
1503 +
1504 + let doc = doc! { "key": src };
1505 +
1506 + let mut buf = Vec::new();
1507 + doc.to_writer(&mut buf).unwrap();
1508 +
1509 + assert_eq!(buf, dst);
1510 +
1511 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1512 + assert_eq!(deserialized, doc);
1513 +}
1514 +
1515 +#[test]
1516 +fn test_encode_decode_utf8_string_invalid() {
1517 + let bytes = b"\x80\xae".to_vec();
1518 + let src = unsafe { String::from_utf8_unchecked(bytes) };
1519 +
1520 + let doc = doc! { "key": src };
1521 +
1522 + let mut buf = Vec::new();
1523 + doc.to_writer(&mut buf).unwrap();
1524 +
1525 + let expected = doc! { "key": "��" };
1526 + let decoded = Document::from_reader_utf8_lossy(&mut Cursor::new(buf)).unwrap();
1527 + assert_eq!(decoded, expected);
1528 +}
1529 +
1530 +#[test]
1531 +fn test_serialize_deserialize_array() {
1532 + let _guard = LOCK.run_concurrently();
1533 + let src = vec![Bson::Double(1.01), Bson::String("xyz".to_owned())];
1534 + let dst = vec![
1535 + 37, 0, 0, 0, 4, 107, 101, 121, 0, 27, 0, 0, 0, 1, 48, 0, 41, 92, 143, 194, 245, 40, 240,
1536 + 63, 2, 49, 0, 4, 0, 0, 0, 120, 121, 122, 0, 0, 0,
1537 + ];
1538 +
1539 + let doc = doc! { "key": src };
1540 +
1541 + let mut buf = Vec::new();
1542 + doc.to_writer(&mut buf).unwrap();
1543 +
1544 + assert_eq!(buf, dst);
1545 +
1546 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1547 + assert_eq!(deserialized, doc);
1548 +}
1549 +
1550 +#[test]
1551 +fn test_serialize_deserialize() {
1552 + let _guard = LOCK.run_concurrently();
1553 + let src = doc! { "subkey": 1 };
1554 + let dst = vec![
1555 + 27, 0, 0, 0, 3, 107, 101, 121, 0, 17, 0, 0, 0, 16, 115, 117, 98, 107, 101, 121, 0, 1, 0, 0,
1556 + 0, 0, 0,
1557 + ];
1558 +
1559 + let doc = doc! { "key": src };
1560 +
1561 + let mut buf = Vec::new();
1562 + doc.to_writer(&mut buf).unwrap();
1563 +
1564 + assert_eq!(buf, dst);
1565 +
1566 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1567 + assert_eq!(deserialized, doc);
1568 +}
1569 +
1570 +#[test]
1571 +fn test_serialize_deserialize_boolean() {
1572 + let _guard = LOCK.run_concurrently();
1573 + let src = true;
1574 + let dst = vec![11, 0, 0, 0, 8, 107, 101, 121, 0, 1, 0];
1575 +
1576 + let doc = doc! { "key": src };
1577 +
1578 + let mut buf = Vec::new();
1579 + doc.to_writer(&mut buf).unwrap();
1580 +
1581 + assert_eq!(buf, dst);
1582 +
1583 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1584 + assert_eq!(deserialized, doc);
1585 +}
1586 +
1587 +#[test]
1588 +fn test_serialize_deserialize_null() {
1589 + let _guard = LOCK.run_concurrently();
1590 + let src = Bson::Null;
1591 + let dst = vec![10, 0, 0, 0, 10, 107, 101, 121, 0, 0];
1592 +
1593 + let doc = doc! { "key": src };
1594 +
1595 + let mut buf = Vec::new();
1596 + doc.to_writer(&mut buf).unwrap();
1597 +
1598 + assert_eq!(buf, dst);
1599 +
1600 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1601 + assert_eq!(deserialized, doc);
1602 +}
1603 +
1604 +#[test]
1605 +fn test_serialize_deserialize_regexp() {
1606 + let _guard = LOCK.run_concurrently();
1607 + let src = Bson::RegularExpression(Regex {
1608 + pattern: "1".to_owned(),
1609 + options: "2".to_owned(),
1610 + });
1611 + let dst = vec![14, 0, 0, 0, 11, 107, 101, 121, 0, 49, 0, 50, 0, 0];
1612 +
1613 + let doc = doc! { "key": src };
1614 +
1615 + let mut buf = Vec::new();
1616 + doc.to_writer(&mut buf).unwrap();
1617 +
1618 + assert_eq!(buf, dst);
1619 +
1620 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1621 + assert_eq!(deserialized, doc);
1622 +}
1623 +
1624 +#[test]
1625 +fn test_serialize_deserialize_javascript_code() {
1626 + let _guard = LOCK.run_concurrently();
1627 + let src = Bson::JavaScriptCode("1".to_owned());
1628 + let dst = vec![16, 0, 0, 0, 13, 107, 101, 121, 0, 2, 0, 0, 0, 49, 0, 0];
1629 +
1630 + let doc = doc! { "key": src };
1631 +
1632 + let mut buf = Vec::new();
1633 + doc.to_writer(&mut buf).unwrap();
1634 +
1635 + assert_eq!(buf, dst);
1636 +
1637 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1638 + assert_eq!(deserialized, doc);
1639 +}
1640 +
1641 +#[test]
1642 +fn test_serialize_deserialize_javascript_code_with_scope() {
1643 + let _guard = LOCK.run_concurrently();
1644 + let src = Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope {
1645 + code: "1".to_owned(),
1646 + scope: doc! {},
1647 + });
1648 + let dst = vec![
1649 + 25, 0, 0, 0, 15, 107, 101, 121, 0, 15, 0, 0, 0, 2, 0, 0, 0, 49, 0, 5, 0, 0, 0, 0, 0,
1650 + ];
1651 +
1652 + let doc = doc! { "key": src };
1653 +
1654 + let mut buf = Vec::new();
1655 + doc.to_writer(&mut buf).unwrap();
1656 +
1657 + assert_eq!(buf, dst);
1658 +
1659 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1660 + assert_eq!(deserialized, doc);
1661 +}
1662 +
1663 +#[test]
1664 +fn test_serialize_deserialize_i32() {
1665 + let _guard = LOCK.run_concurrently();
1666 + let src = 100i32;
1667 + let dst = vec![14, 0, 0, 0, 16, 107, 101, 121, 0, 100, 0, 0, 0, 0];
1668 +
1669 + let doc = doc! { "key": src };
1670 +
1671 + let mut buf = Vec::new();
1672 + doc.to_writer(&mut buf).unwrap();
1673 +
1674 + assert_eq!(buf, dst);
1675 +
1676 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1677 + assert_eq!(deserialized, doc);
1678 +}
1679 +
1680 +#[test]
1681 +fn test_serialize_deserialize_i64() {
1682 + let _guard = LOCK.run_concurrently();
1683 + let src = 100i64;
1684 + let dst = vec![
1685 + 18, 0, 0, 0, 18, 107, 101, 121, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0,
1686 + ];
1687 +
1688 + let doc = doc! { "key": src };
1689 +
1690 + let mut buf = Vec::new();
1691 + doc.to_writer(&mut buf).unwrap();
1692 +
1693 + assert_eq!(buf, dst);
1694 +
1695 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1696 + assert_eq!(deserialized, doc);
1697 +}
1698 +
1699 +#[test]
1700 +fn test_serialize_deserialize_timestamp() {
1701 + let _guard = LOCK.run_concurrently();
1702 + let src = Bson::Timestamp(Timestamp {
1703 + time: 0,
1704 + increment: 100,
1705 + });
1706 + let dst = vec![
1707 + 18, 0, 0, 0, 17, 107, 101, 121, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0,
1708 + ];
1709 +
1710 + let doc = doc! { "key": src };
1711 +
1712 + let mut buf = Vec::new();
1713 + doc.to_writer(&mut buf).unwrap();
1714 +
1715 + assert_eq!(buf, dst);
1716 +
1717 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1718 + assert_eq!(deserialized, doc);
1719 +}
1720 +
1721 +#[test]
1722 +fn test_serialize_binary_generic() {
1723 + let _guard = LOCK.run_concurrently();
1724 + let src = Binary {
1725 + subtype: BinarySubtype::Generic,
1726 + bytes: vec![0, 1, 2, 3, 4],
1727 + };
1728 + let dst = vec![
1729 + 20, 0, 0, 0, 5, 107, 101, 121, 0, 5, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0,
1730 + ];
1731 +
1732 + let doc = doc! { "key": src };
1733 +
1734 + let mut buf = Vec::new();
1735 + doc.to_writer(&mut buf).unwrap();
1736 +
1737 + assert_eq!(buf, dst);
1738 +
1739 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1740 + assert_eq!(deserialized, doc);
1741 +}
1742 +
1743 +#[test]
1744 +fn test_serialize_deserialize_object_id() {
1745 + let _guard = LOCK.run_concurrently();
1746 + let src = ObjectId::parse_str("507f1f77bcf86cd799439011").unwrap();
1747 + let dst = vec![
1748 + 22, 0, 0, 0, 7, 107, 101, 121, 0, 80, 127, 31, 119, 188, 248, 108, 215, 153, 67, 144, 17, 0,
1749 + ];
1750 +
1751 + let doc = doc! { "key": src };
1752 +
1753 + let mut buf = Vec::new();
1754 + doc.to_writer(&mut buf).unwrap();
1755 +
1756 + assert_eq!(buf, dst);
1757 +
1758 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1759 + assert_eq!(deserialized, doc);
1760 +}
1761 +
1762 +#[test]
1763 +fn test_serialize_utc_date_time() {
1764 + #[cfg(feature = "chrono-0_4")]
1765 + use chrono::offset::TimeZone;
1766 + let _guard = LOCK.run_concurrently();
1767 + #[cfg(not(any(feature = "chrono-0_4", feature = "time-0_3")))]
1768 + let src = crate::DateTime::from_time_0_3(
1769 + time::OffsetDateTime::from_unix_timestamp(1_286_705_410).unwrap(),
1770 + );
1771 + #[cfg(feature = "time-0_3")]
1772 + #[allow(unused)]
1773 + let src = time::OffsetDateTime::from_unix_timestamp(1_286_705_410).unwrap();
1774 + #[cfg(feature = "chrono-0_4")]
1775 + let src = chrono::Utc.timestamp_opt(1_286_705_410, 0).unwrap();
1776 + let dst = vec![
1777 + 18, 0, 0, 0, 9, 107, 101, 121, 0, 208, 111, 158, 149, 43, 1, 0, 0, 0,
1778 + ];
1779 +
1780 + let doc = doc! { "key": src };
1781 +
1782 + let mut buf = Vec::new();
1783 + doc.to_writer(&mut buf).unwrap();
1784 +
1785 + assert_eq!(buf, dst);
1786 +
1787 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1788 + assert_eq!(deserialized, doc);
1789 +}
1790 +
1791 +#[test]
1792 +fn test_serialize_deserialize_symbol() {
1793 + let _guard = LOCK.run_concurrently();
1794 + let symbol = Bson::Symbol("abc".to_owned());
1795 + let dst = vec![
1796 + 18, 0, 0, 0, 14, 107, 101, 121, 0, 4, 0, 0, 0, 97, 98, 99, 0, 0,
1797 + ];
1798 +
1799 + let doc = doc! { "key": symbol };
1800 +
1801 + let mut buf = Vec::new();
1802 + doc.to_writer(&mut buf).unwrap();
1803 +
1804 + assert_eq!(buf, dst);
1805 +
1806 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1807 + assert_eq!(deserialized, doc);
1808 +}
1809 +
1810 +#[test]
1811 +fn test_deserialize_utc_date_time_overflows() {
1812 + let _guard = LOCK.run_concurrently();
1813 + let t: i64 = 1_530_492_218 * 1_000 + 999;
1814 +
1815 + let mut raw0 = vec![0x09, b'A', 0x00];
1816 + raw0.write_all(&t.to_le_bytes()).unwrap();
1817 +
1818 + let mut raw = vec![];
1819 + raw.write_all(&((raw0.len() + 4 + 1) as i32).to_le_bytes())
1820 + .unwrap();
1821 + raw.write_all(&raw0).unwrap();
1822 + raw.write_all(&[0]).unwrap();
1823 +
1824 + let deserialized = Document::from_reader(&mut Cursor::new(raw)).unwrap();
1825 +
1826 + let expected = doc! { "A": crate::DateTime::from_time_0_3(time::OffsetDateTime::from_unix_timestamp(1_530_492_218).unwrap() + time::Duration::nanoseconds(999 * 1_000_000))};
1827 + assert_eq!(deserialized, expected);
1828 +}
1829 +
1830 +#[test]
1831 +fn test_deserialize_invalid_utf8_string_issue64() {
1832 + let _guard = LOCK.run_concurrently();
1833 + let buffer = b"\x13\x00\x00\x00\x02\x01\x00\x00\x00\x00\x00\x00\x00foo\x00\x13\x05\x00\x00\x00";
1834 +
1835 + assert!(Document::from_reader(&mut Cursor::new(buffer)).is_err());
1836 +}
1837 +
1838 +#[test]
1839 +fn test_deserialize_multiply_overflows_issue64() {
1840 + let _guard = LOCK.run_concurrently();
1841 + let buffer = b"*\xc9*\xc9\t\x00\x00\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\xca\x01\t\x00\x00\x01\x10";
1842 +
1843 + assert!(Document::from_reader(&mut Cursor::new(&buffer[..])).is_err());
1844 +}
1845 +
1846 +#[test]
1847 +fn test_serialize_deserialize_decimal128() {
1848 + let _guard = LOCK.run_concurrently();
1849 + let val = Bson::Decimal128(Decimal128 {
1850 + bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 34],
1851 + });
1852 + let dst = vec![
1853 + 26, 0, 0, 0, 19, 107, 101, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 34, 0,
1854 + ];
1855 +
1856 + let doc = doc! { "key": val };
1857 +
1858 + let mut buf = Vec::new();
1859 + doc.to_writer(&mut buf).unwrap();
1860 +
1861 + assert_eq!(buf, dst);
1862 +
1863 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1864 + assert_eq!(deserialized, doc);
1865 +}
1866 +
1867 +#[test]
1868 +fn test_illegal_size() {
1869 + let _guard = LOCK.run_concurrently();
1870 + let buffer = [
1871 + 0x06, 0xcc, 0xf9, 0x0a, 0x05, 0x00, 0x00, 0x03, 0x00, 0xff, 0xff,
1872 + ];
1873 + assert!(Document::from_reader(&mut Cursor::new(&buffer[..])).is_err());
1874 +}
1875 +
1876 +#[test]
1877 +fn test_serialize_deserialize_undefined() {
1878 + let _guard = LOCK.run_concurrently();
1879 + let src = Bson::Undefined;
1880 + let dst = vec![10, 0, 0, 0, 6, 107, 101, 121, 0, 0];
1881 +
1882 + let doc = doc! { "key": src };
1883 +
1884 + let mut buf = Vec::new();
1885 + doc.to_writer(&mut buf).unwrap();
1886 +
1887 + assert_eq!(buf, dst);
1888 +
1889 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1890 + assert_eq!(deserialized, doc);
1891 +}
1892 +
1893 +#[test]
1894 +fn test_serialize_deserialize_min_key() {
1895 + let _guard = LOCK.run_concurrently();
1896 + let src = Bson::MinKey;
1897 + let dst = vec![10, 0, 0, 0, 255, 107, 101, 121, 0, 0];
1898 +
1899 + let doc = doc! { "key": src };
1900 +
1901 + let mut buf = Vec::new();
1902 + doc.to_writer(&mut buf).unwrap();
1903 +
1904 + assert_eq!(buf, dst);
1905 +
1906 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1907 + assert_eq!(deserialized, doc);
1908 +}
1909 +
1910 +#[test]
1911 +fn test_serialize_deserialize_max_key() {
1912 + let _guard = LOCK.run_concurrently();
1913 + let src = Bson::MaxKey;
1914 + let dst = vec![10, 0, 0, 0, 127, 107, 101, 121, 0, 0];
1915 +
1916 + let doc = doc! {"key": src };
1917 +
1918 + let mut buf = Vec::new();
1919 + doc.to_writer(&mut buf).unwrap();
1920 +
1921 + assert_eq!(buf, dst);
1922 +
1923 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1924 + assert_eq!(deserialized, doc);
1925 +}
1926 +
1927 +#[test]
1928 +fn test_serialize_deserialize_db_pointer() {
1929 + let _guard = LOCK.run_concurrently();
1930 + let src = Bson::try_from(json!({
1931 + "$dbPointer": {
1932 + "$ref": "db.coll",
1933 + "$id": { "$oid": "507f1f77bcf86cd799439011" },
1934 + }
1935 + }))
1936 + .unwrap();
1937 + let dst = vec![
1938 + 34, 0, 0, 0, 12, 107, 101, 121, 0, 8, 0, 0, 0, 100, 98, 46, 99, 111, 108, 108, 0, 80, 127,
1939 + 31, 119, 188, 248, 108, 215, 153, 67, 144, 17, 0,
1940 + ];
1941 +
1942 + let doc = doc! { "key": src };
1943 +
1944 + let mut buf = Vec::new();
1945 + doc.to_writer(&mut buf).unwrap();
1946 +
1947 + assert_eq!(buf, dst);
1948 +
1949 + let deserialized = Document::from_reader(&mut Cursor::new(buf)).unwrap();
1950 + assert_eq!(deserialized, doc);
1951 +}
1952 +
1953 +#[test]
1954 +fn test_serialize_deserialize_document() {
1955 + let _guard = LOCK.run_concurrently();
1956 +
1957 + #[derive(Debug, Deserialize, Serialize, PartialEq)]
1958 + struct Point {
1959 + x: i32,
1960 + y: i32,
1961 + }
1962 + let src = Point { x: 1, y: 2 };
1963 +
1964 + let doc = to_document(&src).unwrap();
1965 + assert_eq!(doc, doc! { "x": 1, "y": 2 });
1966 +
1967 + let point: Point = from_document(doc).unwrap();
1968 + assert_eq!(src, point);
1969 +
1970 + #[derive(Debug, Deserialize, Serialize, PartialEq)]
1971 + struct Line {
1972 + p1: Point,
1973 + p2: Point,
1974 + }
1975 + let src = Line {
1976 + p1: Point { x: 0, y: 0 },
1977 + p2: Point { x: 1, y: 1 },
1978 + };
1979 +
1980 + let doc = to_document(&src).unwrap();
1981 + assert_eq!(
1982 + doc,
1983 + doc! { "p1": { "x": 0, "y": 0 }, "p2": { "x": 1, "y": 1 } }
1984 + );
1985 +
1986 + let line: Line = from_document(doc).unwrap();
1987 + assert_eq!(src, line);
1988 +
1989 + let x = 1;
1990 + let err = to_document(&x).unwrap_err();
1991 + match err {
1992 + Error::SerializationError { message } => {
1993 + assert!(message.contains("Could not be serialized to Document"));
1994 + }
1995 + e => panic!("expected SerializationError, got {}", e),
1996 + }
1997 +
1998 + let bad_point = doc! { "x": "one", "y": "two" };
1999 + let bad_point: Result<Point, crate::de::Error> = from_document(bad_point);
2000 + assert!(bad_point.is_err());
2001 +}
2002 +
2003 +/// [RUST-713](https://jira.mongodb.org/browse/RUST-713)
2004 +#[test]
2005 +fn test_deserialize_invalid_array_length() {
2006 + let _guard = LOCK.run_concurrently();
2007 + let buffer = b"\n\x00\x00\x00\x04\x00\x00\x00\x00\x00";
2008 + Document::from_reader(&mut std::io::Cursor::new(buffer))
2009 + .expect_err("expected deserialization to fail");
2010 +}
2011 +
2012 +/// [RUST-713](https://jira.mongodb.org/browse/RUST-713)
2013 +#[test]
2014 +fn test_deserialize_invalid_old_binary_length() {
2015 + let _guard = LOCK.run_concurrently();
2016 + let buffer = b"\x0F\x00\x00\x00\x05\x00\x00\x00\x00\x00\x02\xFC\xFF\xFF\xFF";
2017 + Document::from_reader(&mut std::io::Cursor::new(buffer))
2018 + .expect_err("expected deserialization to fail");
2019 +
2020 + let buffer = b".\x00\x00\x00\x05\x01\x00\x00\x00\x00\x00\x02\xfc\xff\xff\xff\xff\xff\xff\xff\x00\x00*\x00h\x0e\x10++\x00h\x0e++\x00\x00\t\x00\x00\x00\x00\x00*\x0e\x10++";
2021 + Document::from_reader(&mut std::io::Cursor::new(buffer))
2022 + .expect_err("expected deserialization to fail");
2023 +}
2024 diff --git a/src/tests/serde.rs b/src/tests/serde.rs
2025 new file mode 100644
2026 index 0000000..29d3253
2027 --- /dev/null
2028 +++ b/src/tests/serde.rs
2029 @@ -0,0 +1,1050 @@
2030 +#![allow(clippy::disallowed_names)]
2031 +
2032 +use crate::{
2033 + bson,
2034 + doc,
2035 + from_bson,
2036 + from_document,
2037 + oid::ObjectId,
2038 + serde_helpers,
2039 + serde_helpers::{
2040 + bson_datetime_as_rfc3339_string,
2041 + hex_string_as_object_id,
2042 + i64_as_bson_datetime,
2043 + rfc3339_string_as_bson_datetime,
2044 + serialize_object_id_as_hex_string,
2045 + timestamp_as_u32,
2046 + u32_as_timestamp,
2047 + },
2048 + spec::BinarySubtype,
2049 + tests::LOCK,
2050 + to_bson,
2051 + to_document,
2052 + Binary,
2053 + Bson,
2054 + DateTime,
2055 + Deserializer,
2056 + Document,
2057 + Serializer,
2058 + Timestamp,
2059 +};
2060 +
2061 +use serde::{Deserialize, Serialize};
2062 +use serde_json::json;
2063 +
2064 +use std::{
2065 + collections::BTreeMap,
2066 + convert::{TryFrom, TryInto},
2067 +};
2068 +
2069 +#[test]
2070 +fn test_ser_vec() {
2071 + let _guard = LOCK.run_concurrently();
2072 + let vec = vec![1, 2, 3];
2073 +
2074 + let serializer = Serializer::new();
2075 + let result = vec.serialize(serializer).unwrap();
2076 +
2077 + let expected = bson!([1, 2, 3]);
2078 + assert_eq!(expected, result);
2079 +}
2080 +
2081 +#[test]
2082 +fn test_ser_map() {
2083 + let _guard = LOCK.run_concurrently();
2084 + let mut map = BTreeMap::new();
2085 + map.insert("x", 0);
2086 + map.insert("y", 1);
2087 +
2088 + let serializer = Serializer::new();
2089 + let result = map.serialize(serializer).unwrap();
2090 +
2091 + let expected = bson!({ "x": 0, "y": 1 });
2092 + assert_eq!(expected, result);
2093 +}
2094 +
2095 +#[test]
2096 +fn test_de_vec() {
2097 + let _guard = LOCK.run_concurrently();
2098 + let bson = bson!([1, 2, 3]);
2099 +
2100 + let deserializer = Deserializer::new(bson);
2101 + let vec = Vec::<i32>::deserialize(deserializer).unwrap();
2102 +
2103 + let expected = vec![1, 2, 3];
2104 + assert_eq!(expected, vec);
2105 +}
2106 +
2107 +#[test]
2108 +fn test_de_map() {
2109 + let _guard = LOCK.run_concurrently();
2110 + let bson = bson!({ "x": 0, "y": 1 });
2111 +
2112 + let deserializer = Deserializer::new(bson);
2113 + let map = BTreeMap::<String, i32>::deserialize(deserializer).unwrap();
2114 +
2115 + let mut expected = BTreeMap::new();
2116 + expected.insert("x".to_string(), 0);
2117 + expected.insert("y".to_string(), 1);
2118 + assert_eq!(expected, map);
2119 +}
2120 +
2121 +#[test]
2122 +fn test_ser_timestamp() {
2123 + let _guard = LOCK.run_concurrently();
2124 + use bson::Timestamp;
2125 +
2126 + #[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
2127 + struct Foo {
2128 + ts: Timestamp,
2129 + }
2130 +
2131 + let foo = Foo {
2132 + ts: Timestamp {
2133 + time: 12,
2134 + increment: 10,
2135 + },
2136 + };
2137 +
2138 + let x = to_bson(&foo).unwrap();
2139 + assert_eq!(
2140 + x.as_document().unwrap(),
2141 + &doc! { "ts": Bson::Timestamp(Timestamp { time: 0x0000_000C, increment: 0x0000_000A }) }
2142 + );
2143 +
2144 + let xfoo: Foo = from_bson(x).unwrap();
2145 + assert_eq!(xfoo, foo);
2146 +}
2147 +
2148 +#[test]
2149 +fn test_de_timestamp() {
2150 + let _guard = LOCK.run_concurrently();
2151 + use bson::Timestamp;
2152 +
2153 + #[derive(Deserialize, Eq, PartialEq, Debug)]
2154 + struct Foo {
2155 + ts: Timestamp,
2156 + }
2157 +
2158 + let foo: Foo = from_bson(Bson::Document(doc! {
2159 + "ts": Bson::Timestamp(Timestamp { time: 0x0000_000C, increment: 0x0000_000A }),
2160 + }))
2161 + .unwrap();
2162 +
2163 + assert_eq!(
2164 + foo.ts,
2165 + Timestamp {
2166 + time: 12,
2167 + increment: 10
2168 + }
2169 + );
2170 +}
2171 +
2172 +#[test]
2173 +fn test_ser_regex() {
2174 + let _guard = LOCK.run_concurrently();
2175 + use bson::Regex;
2176 +
2177 + #[derive(Serialize, Deserialize, PartialEq, Debug)]
2178 + struct Foo {
2179 + regex: Regex,
2180 + }
2181 +
2182 + let regex = Regex {
2183 + pattern: "12".into(),
2184 + options: "01".into(),
2185 + };
2186 +
2187 + let foo = Foo {
2188 + regex: regex.clone(),
2189 + };
2190 +
2191 + let x = to_bson(&foo).unwrap();
2192 + assert_eq!(
2193 + x.as_document().unwrap(),
2194 + &doc! { "regex": Bson::RegularExpression(regex) }
2195 + );
2196 +
2197 + let xfoo: Foo = from_bson(x).unwrap();
2198 + assert_eq!(xfoo, foo);
2199 +}
2200 +
2201 +#[test]
2202 +fn test_de_regex() {
2203 + let _guard = LOCK.run_concurrently();
2204 + use bson::Regex;
2205 +
2206 + #[derive(Deserialize, PartialEq, Debug)]
2207 + struct Foo {
2208 + regex: Regex,
2209 + }
2210 +
2211 + let regex = Regex {
2212 + pattern: "12".into(),
2213 + options: "01".into(),
2214 + };
2215 +
2216 + let foo: Foo = from_bson(Bson::Document(doc! {
2217 + "regex": Bson::RegularExpression(regex.clone()),
2218 + }))
2219 + .unwrap();
2220 +
2221 + assert_eq!(foo.regex, regex);
2222 +}
2223 +
2224 +#[test]
2225 +fn test_ser_code_with_scope() {
2226 + let _guard = LOCK.run_concurrently();
2227 + use bson::JavaScriptCodeWithScope;
2228 +
2229 + #[derive(Serialize, Deserialize, PartialEq, Debug)]
2230 + struct Foo {
2231 + code_with_scope: JavaScriptCodeWithScope,
2232 + }
2233 +
2234 + let code_with_scope = JavaScriptCodeWithScope {
2235 + code: "x".into(),
2236 + scope: doc! { "x": 12 },
2237 + };
2238 +
2239 + let foo = Foo {
2240 + code_with_scope: code_with_scope.clone(),
2241 + };
2242 +
2243 + let x = to_bson(&foo).unwrap();
2244 + assert_eq!(
2245 + x.as_document().unwrap(),
2246 + &doc! { "code_with_scope": Bson::JavaScriptCodeWithScope(code_with_scope) }
2247 + );
2248 +
2249 + let xfoo: Foo = from_bson(x).unwrap();
2250 + assert_eq!(xfoo, foo);
2251 +}
2252 +
2253 +#[test]
2254 +fn test_de_code_with_scope() {
2255 + let _guard = LOCK.run_concurrently();
2256 + use bson::JavaScriptCodeWithScope;
2257 +
2258 + #[derive(Deserialize, PartialEq, Debug)]
2259 + struct Foo {
2260 + code_with_scope: JavaScriptCodeWithScope,
2261 + }
2262 +
2263 + let code_with_scope = JavaScriptCodeWithScope {
2264 + code: "x".into(),
2265 + scope: doc! { "x": 12 },
2266 + };
2267 +
2268 + let foo: Foo = from_bson(Bson::Document(doc! {
2269 + "code_with_scope": Bson::JavaScriptCodeWithScope(code_with_scope.clone()),
2270 + }))
2271 + .unwrap();
2272 +
2273 + assert_eq!(foo.code_with_scope, code_with_scope);
2274 +}
2275 +
2276 +#[test]
2277 +fn test_ser_datetime() {
2278 + let _guard = LOCK.run_concurrently();
2279 + use crate::DateTime;
2280 +
2281 + #[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
2282 + struct Foo {
2283 + date: DateTime,
2284 + }
2285 +
2286 + let now = DateTime::now();
2287 +
2288 + let foo = Foo { date: now };
2289 +
2290 + let x = to_bson(&foo).unwrap();
2291 + assert_eq!(
2292 + x.as_document().unwrap(),
2293 + &doc! { "date": (Bson::DateTime(now)) }
2294 + );
2295 +
2296 + let xfoo: Foo = from_bson(x).unwrap();
2297 + assert_eq!(xfoo, foo);
2298 +}
2299 +
2300 +#[test]
2301 +fn test_binary_generic_roundtrip() {
2302 + let _guard = LOCK.run_concurrently();
2303 + #[derive(Serialize, Deserialize, Debug, PartialEq)]
2304 + pub struct Foo {
2305 + data: Bson,
2306 + }
2307 +
2308 + let x = Foo {
2309 + data: Bson::Binary(Binary {
2310 + subtype: BinarySubtype::Generic,
2311 + bytes: b"12345abcde".to_vec(),
2312 + }),
2313 + };
2314 +
2315 + let b = to_bson(&x).unwrap();
2316 + assert_eq!(
2317 + b.as_document().unwrap(),
2318 + &doc! {"data": Bson::Binary(Binary { subtype: BinarySubtype::Generic, bytes: b"12345abcde".to_vec() })}
2319 + );
2320 +
2321 + let f = from_bson::<Foo>(b).unwrap();
2322 + assert_eq!(x, f);
2323 +}
2324 +
2325 +#[test]
2326 +fn test_binary_non_generic_roundtrip() {
2327 + let _guard = LOCK.run_concurrently();
2328 + #[derive(Serialize, Deserialize, Debug, PartialEq)]
2329 + pub struct Foo {
2330 + data: Bson,
2331 + }
2332 +
2333 + let x = Foo {
2334 + data: Bson::Binary(Binary {
2335 + subtype: BinarySubtype::BinaryOld,
2336 + bytes: b"12345abcde".to_vec(),
2337 + }),
2338 + };
2339 +
2340 + let b = to_bson(&x).unwrap();
2341 + assert_eq!(
2342 + b.as_document().unwrap(),
2343 + &doc! {"data": Bson::Binary(Binary { subtype: BinarySubtype::BinaryOld, bytes: b"12345abcde".to_vec() })}
2344 + );
2345 +
2346 + let f = from_bson::<Foo>(b).unwrap();
2347 + assert_eq!(x, f);
2348 +}
2349 +
2350 +#[test]
2351 +fn test_binary_helper_generic_roundtrip() {
2352 + let _guard = LOCK.run_concurrently();
2353 + #[derive(Serialize, Deserialize, Debug, PartialEq)]
2354 + pub struct Foo {
2355 + data: Binary,
2356 + }
2357 +
2358 + let x = Foo {
2359 + data: Binary {
2360 + subtype: BinarySubtype::Generic,
2361 + bytes: b"12345abcde".to_vec(),
2362 + },
2363 + };
2364 +
2365 + let b = to_bson(&x).unwrap();
2366 + assert_eq!(
2367 + b.as_document().unwrap(),
2368 + &doc! {"data": Bson::Binary(Binary { subtype: BinarySubtype::Generic, bytes: b"12345abcde".to_vec() })}
2369 + );
2370 +
2371 + let f = from_bson::<Foo>(b).unwrap();
2372 + assert_eq!(x, f);
2373 +}
2374 +
2375 +#[test]
2376 +fn test_binary_helper_non_generic_roundtrip() {
2377 + let _guard = LOCK.run_concurrently();
2378 + #[derive(Serialize, Deserialize, Debug, PartialEq)]
2379 + pub struct Foo {
2380 + data: Binary,
2381 + }
2382 +
2383 + let x = Foo {
2384 + data: Binary {
2385 + subtype: BinarySubtype::BinaryOld,
2386 + bytes: b"12345abcde".to_vec(),
2387 + },
2388 + };
2389 +
2390 + let b = to_bson(&x).unwrap();
2391 + assert_eq!(
2392 + b.as_document().unwrap(),
2393 + &doc! {"data": Bson::Binary(Binary { subtype: BinarySubtype::BinaryOld, bytes: b"12345abcde".to_vec() })}
2394 + );
2395 +
2396 + let f = from_bson::<Foo>(b).unwrap();
2397 + assert_eq!(x, f);
2398 +}
2399 +
2400 +#[test]
2401 +fn test_byte_vec() {
2402 + let _guard = LOCK.run_concurrently();
2403 + #[derive(Serialize, Debug, Eq, PartialEq)]
2404 + pub struct AuthChallenge<'a> {
2405 + #[serde(with = "serde_bytes")]
2406 + pub challenge: &'a [u8],
2407 + }
2408 +
2409 + let x = AuthChallenge {
2410 + challenge: b"18762b98b7c34c25bf9dc3154e4a5ca3",
2411 + };
2412 +
2413 + let b = to_bson(&x).unwrap();
2414 + assert_eq!(
2415 + b,
2416 + Bson::Document(
2417 + doc! { "challenge": (Bson::Binary(Binary { subtype: BinarySubtype::Generic, bytes: x.challenge.to_vec() }))}
2418 + )
2419 + );
2420 +
2421 + // let mut buf = Vec::new();
2422 + // b.as_document().unwrap().to_writer(&mut buf).unwrap();
2423 +
2424 + // let xb = Document::from_reader(&mut Cursor::new(buf)).unwrap();
2425 + // assert_eq!(b.as_document().unwrap(), &xb);
2426 +}
2427 +
2428 +#[test]
2429 +fn test_serde_bytes() {
2430 + let _guard = LOCK.run_concurrently();
2431 + #[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
2432 + pub struct Foo {
2433 + #[serde(with = "serde_bytes")]
2434 + data: Vec<u8>,
2435 + }
2436 +
2437 + let x = Foo {
2438 + data: b"12345abcde".to_vec(),
2439 + };
2440 +
2441 + let b = to_bson(&x).unwrap();
2442 + assert_eq!(
2443 + b.as_document().unwrap(),
2444 + &doc! {"data": Bson::Binary(Binary { subtype: BinarySubtype::Generic, bytes: b"12345abcde".to_vec() })}
2445 + );
2446 +
2447 + let f = from_bson::<Foo>(b).unwrap();
2448 + assert_eq!(x, f);
2449 +}
2450 +
2451 +#[test]
2452 +fn test_serde_newtype_struct() {
2453 + let _guard = LOCK.run_concurrently();
2454 + #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
2455 + struct Email(String);
2456 +
2457 + let email_1 = Email(String::from("[email protected]"));
2458 + let b = to_bson(&email_1).unwrap();
2459 + assert_eq!(b, Bson::String(email_1.0));
2460 +
2461 + let s = String::from("[email protected]");
2462 + let de = Bson::String(s.clone());
2463 + let email_2 = from_bson::<Email>(de).unwrap();
2464 + assert_eq!(email_2, Email(s));
2465 +}
2466 +
2467 +#[test]
2468 +fn test_serde_tuple_struct() {
2469 + let _guard = LOCK.run_concurrently();
2470 + #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
2471 + struct Name(String, String); // first, last
2472 +
2473 + let name_1 = Name(String::from("Graydon"), String::from("Hoare"));
2474 + let b = to_bson(&name_1).unwrap();
2475 + assert_eq!(b, bson!([name_1.0.clone(), name_1.1]));
2476 +
2477 + let (first, last) = (String::from("Donald"), String::from("Knuth"));
2478 + let de = bson!([first.clone(), last.clone()]);
2479 + let name_2 = from_bson::<Name>(de).unwrap();
2480 + assert_eq!(name_2, Name(first, last));
2481 +}
2482 +
2483 +#[test]
2484 +fn test_serde_newtype_variant() {
2485 + let _guard = LOCK.run_concurrently();
2486 + #[derive(Debug, PartialEq, Serialize, Deserialize)]
2487 + #[serde(tag = "type", content = "value")]
2488 + enum Number {
2489 + Int(i64),
2490 + Float(f64),
2491 + }
2492 +
2493 + let n = 42;
2494 + let num_1 = Number::Int(n);
2495 + let b = to_bson(&num_1).unwrap();
2496 + assert_eq!(b, bson!({ "type": "Int", "value": n }));
2497 +
2498 + let x = 1337.0;
2499 + let de = bson!({ "type": "Float", "value": x });
2500 + let num_2 = from_bson::<Number>(de).unwrap();
2501 + assert_eq!(num_2, Number::Float(x));
2502 +}
2503 +
2504 +#[test]
2505 +fn test_serde_tuple_variant() {
2506 + let _guard = LOCK.run_concurrently();
2507 + #[derive(Debug, PartialEq, Serialize, Deserialize)]
2508 + enum Point {
2509 + TwoDim(f64, f64),
2510 + ThreeDim(f64, f64, f64),
2511 + }
2512 +
2513 + #[allow(clippy::approx_constant)]
2514 + let (x1, y1) = (3.14, -2.71);
2515 + let p1 = Point::TwoDim(x1, y1);
2516 + let b = to_bson(&p1).unwrap();
2517 + assert_eq!(b, bson!({ "TwoDim": [x1, y1] }));
2518 +
2519 + let (x2, y2, z2) = (0.0, -13.37, 4.2);
2520 + let de = bson!({ "ThreeDim": [x2, y2, z2] });
2521 + let p2 = from_bson::<Point>(de).unwrap();
2522 + assert_eq!(p2, Point::ThreeDim(x2, y2, z2));
2523 +}
2524 +
2525 +#[test]
2526 +fn test_ser_db_pointer() {
2527 + let _guard = LOCK.run_concurrently();
2528 + use bson::DbPointer;
2529 +
2530 + #[derive(Serialize, Deserialize, PartialEq, Debug)]
2531 + struct Foo {
2532 + db_pointer: DbPointer,
2533 + }
2534 +
2535 + let db_pointer = Bson::try_from(json!({
2536 + "$dbPointer": {
2537 + "$ref": "db.coll",
2538 + "$id": { "$oid": "507f1f77bcf86cd799439011" },
2539 + }
2540 + }))
2541 + .unwrap();
2542 +
2543 + let db_pointer = db_pointer.as_db_pointer().unwrap();
2544 +
2545 + let foo = Foo {
2546 + db_pointer: db_pointer.clone(),
2547 + };
2548 +
2549 + let x = to_bson(&foo).unwrap();
2550 + assert_eq!(
2551 + x.as_document().unwrap(),
2552 + &doc! {"db_pointer": Bson::DbPointer(db_pointer.clone()) }
2553 + );
2554 +
2555 + let xfoo: Foo = from_bson(x).unwrap();
2556 + assert_eq!(xfoo, foo);
2557 +}
2558 +
2559 +#[test]
2560 +fn test_de_db_pointer() {
2561 + let _guard = LOCK.run_concurrently();
2562 + use bson::DbPointer;
2563 +
2564 + #[derive(Deserialize, PartialEq, Debug)]
2565 + struct Foo {
2566 + db_pointer: DbPointer,
2567 + }
2568 +
2569 + let db_pointer = Bson::try_from(json!({
2570 + "$dbPointer": {
2571 + "$ref": "db.coll",
2572 + "$id": { "$oid": "507f1f77bcf86cd799439011" },
2573 + }
2574 + }))
2575 + .unwrap();
2576 + let db_pointer = db_pointer.as_db_pointer().unwrap();
2577 +
2578 + let foo: Foo = from_bson(Bson::Document(
2579 + doc! {"db_pointer": Bson::DbPointer(db_pointer.clone())},
2580 + ))
2581 + .unwrap();
2582 +
2583 + assert_eq!(foo.db_pointer, db_pointer.clone());
2584 +}
2585 +
2586 +#[cfg(feature = "uuid-0_8")]
2587 +#[test]
2588 +fn test_serde_legacy_uuid_0_8() {
2589 + use uuid_0_8::Uuid;
2590 +
2591 + let _guard = LOCK.run_concurrently();
2592 +
2593 + #[derive(Serialize, Deserialize)]
2594 + struct Foo {
2595 + #[serde(with = "serde_helpers::uuid_as_java_legacy_binary")]
2596 + java_legacy: Uuid,
2597 + #[serde(with = "serde_helpers::uuid_as_python_legacy_binary")]
2598 + python_legacy: Uuid,
2599 + #[serde(with = "serde_helpers::uuid_as_c_sharp_legacy_binary")]
2600 + csharp_legacy: Uuid,
2601 + }
2602 + let uuid = Uuid::parse_str("00112233445566778899AABBCCDDEEFF").unwrap();
2603 + let foo = Foo {
2604 + java_legacy: uuid,
2605 + python_legacy: uuid,
2606 + csharp_legacy: uuid,
2607 + };
2608 +
2609 + let x = to_bson(&foo).unwrap();
2610 + assert_eq!(
2611 + x.as_document().unwrap(),
2612 + &doc! {
2613 + "java_legacy": Bson::Binary(Binary{
2614 + subtype:BinarySubtype::UuidOld,
2615 + bytes: hex::decode("7766554433221100FFEEDDCCBBAA9988").unwrap(),
2616 + }),
2617 + "python_legacy": Bson::Binary(Binary{
2618 + subtype:BinarySubtype::UuidOld,
2619 + bytes: hex::decode("00112233445566778899AABBCCDDEEFF").unwrap(),
2620 + }),
2621 + "csharp_legacy": Bson::Binary(Binary{
2622 + subtype:BinarySubtype::UuidOld,
2623 + bytes: hex::decode("33221100554477668899AABBCCDDEEFF").unwrap(),
2624 + })
2625 + }
2626 + );
2627 +
2628 + let foo: Foo = from_bson(x).unwrap();
2629 + assert_eq!(foo.java_legacy, uuid);
2630 + assert_eq!(foo.python_legacy, uuid);
2631 + assert_eq!(foo.csharp_legacy, uuid);
2632 +}
2633 +
2634 +#[cfg(feature = "uuid-1")]
2635 +#[test]
2636 +fn test_serde_legacy_uuid_1() {
2637 + use uuid::Uuid;
2638 +
2639 + let _guard = LOCK.run_concurrently();
2640 +
2641 + #[derive(Serialize, Deserialize)]
2642 + struct Foo {
2643 + #[serde(with = "serde_helpers::uuid_1_as_java_legacy_binary")]
2644 + java_legacy: Uuid,
2645 + #[serde(with = "serde_helpers::uuid_1_as_python_legacy_binary")]
2646 + python_legacy: Uuid,
2647 + #[serde(with = "serde_helpers::uuid_1_as_c_sharp_legacy_binary")]
2648 + csharp_legacy: Uuid,
2649 + }
2650 + let uuid = Uuid::parse_str("00112233445566778899AABBCCDDEEFF").unwrap();
2651 + let foo = Foo {
2652 + java_legacy: uuid,
2653 + python_legacy: uuid,
2654 + csharp_legacy: uuid,
2655 + };
2656 +
2657 + let x = to_bson(&foo).unwrap();
2658 + assert_eq!(
2659 + x.as_document().unwrap(),
2660 + &doc! {
2661 + "java_legacy": Bson::Binary(Binary{
2662 + subtype:BinarySubtype::UuidOld,
2663 + bytes: hex::decode("7766554433221100FFEEDDCCBBAA9988").unwrap(),
2664 + }),
2665 + "python_legacy": Bson::Binary(Binary{
2666 + subtype:BinarySubtype::UuidOld,
2667 + bytes: hex::decode("00112233445566778899AABBCCDDEEFF").unwrap(),
2668 + }),
2669 + "csharp_legacy": Bson::Binary(Binary{
2670 + subtype:BinarySubtype::UuidOld,
2671 + bytes: hex::decode("33221100554477668899AABBCCDDEEFF").unwrap(),
2672 + })
2673 + }
2674 + );
2675 +
2676 + let foo: Foo = from_bson(x).unwrap();
2677 + assert_eq!(foo.java_legacy, uuid);
2678 + assert_eq!(foo.python_legacy, uuid);
2679 + assert_eq!(foo.csharp_legacy, uuid);
2680 +}
2681 +
2682 +#[test]
2683 +fn test_de_oid_string() {
2684 + let _guard = LOCK.run_concurrently();
2685 +
2686 + #[derive(Debug, Deserialize)]
2687 + struct Foo {
2688 + pub oid: ObjectId,
2689 + }
2690 +
2691 + let foo: Foo = serde_json::from_str("{ \"oid\": \"507f1f77bcf86cd799439011\" }").unwrap();
2692 + let oid = ObjectId::parse_str("507f1f77bcf86cd799439011").unwrap();
2693 + assert_eq!(foo.oid, oid);
2694 +}
2695 +
2696 +#[test]
2697 +fn test_serialize_deserialize_unsigned_numbers() {
2698 + let _guard = LOCK.run_concurrently();
2699 +
2700 + let num = 1;
2701 + let json = format!("{{ \"num\": {} }}", num);
2702 + let doc: Document = serde_json::from_str(&json).unwrap();
2703 + assert_eq!(doc.get_i32("num").unwrap(), num);
2704 +
2705 + let num = i32::MAX as u64 + 1;
2706 + let json = format!("{{ \"num\": {} }}", num);
2707 + let doc: Document = serde_json::from_str(&json).unwrap();
2708 + assert_eq!(doc.get_i64("num").unwrap(), num as i64);
2709 +
2710 + let num = u64::MAX;
2711 + let json = format!("{{ \"num\": {} }}", num);
2712 + let doc_result: Result<Document, serde_json::Error> = serde_json::from_str(&json);
2713 + assert!(doc_result.is_err());
2714 +}
2715 +
2716 +#[test]
2717 +fn test_unsigned_helpers() {
2718 + let _guard = LOCK.run_concurrently();
2719 +
2720 + #[derive(Serialize)]
2721 + struct A {
2722 + #[serde(serialize_with = "serde_helpers::serialize_u32_as_i32")]
2723 + num_1: u32,
2724 + #[serde(serialize_with = "serde_helpers::serialize_u64_as_i32")]
2725 + num_2: u64,
2726 + }
2727 +
2728 + let a = A { num_1: 1, num_2: 2 };
2729 + let doc = to_document(&a).unwrap();
2730 + assert!(doc.get_i32("num_1").unwrap() == 1);
2731 + assert!(doc.get_i32("num_2").unwrap() == 2);
2732 +
2733 + let a = A {
2734 + num_1: u32::MAX,
2735 + num_2: 1,
2736 + };
2737 + let doc_result = to_document(&a);
2738 + assert!(doc_result.is_err());
2739 +
2740 + let a = A {
2741 + num_1: 1,
2742 + num_2: u64::MAX,
2743 + };
2744 + let doc_result = to_document(&a);
2745 + assert!(doc_result.is_err());
2746 +
2747 + #[derive(Serialize)]
2748 + struct B {
2749 + #[serde(serialize_with = "serde_helpers::serialize_u32_as_i64")]
2750 + num_1: u32,
2751 + #[serde(serialize_with = "serde_helpers::serialize_u64_as_i64")]
2752 + num_2: u64,
2753 + }
2754 +
2755 + let b = B {
2756 + num_1: u32::MAX,
2757 + num_2: i64::MAX as u64,
2758 + };
2759 + let doc = to_document(&b).unwrap();
2760 + assert!(doc.get_i64("num_1").unwrap() == u32::MAX as i64);
2761 + assert!(doc.get_i64("num_2").unwrap() == i64::MAX);
2762 +
2763 + let b = B {
2764 + num_1: 1,
2765 + num_2: i64::MAX as u64 + 1,
2766 + };
2767 + let doc_result = to_document(&b);
2768 + assert!(doc_result.is_err());
2769 +
2770 + #[derive(Deserialize, Serialize, Debug, PartialEq)]
2771 + struct F {
2772 + #[serde(with = "serde_helpers::u32_as_f64")]
2773 + num_1: u32,
2774 + #[serde(with = "serde_helpers::u64_as_f64")]
2775 + num_2: u64,
2776 + }
2777 +
2778 + let f = F {
2779 + num_1: 101,
2780 + num_2: 12345,
2781 + };
2782 + let doc = to_document(&f).unwrap();
2783 + assert!((doc.get_f64("num_1").unwrap() - 101.0).abs() < f64::EPSILON);
2784 + assert!((doc.get_f64("num_2").unwrap() - 12345.0).abs() < f64::EPSILON);
2785 +
2786 + let back: F = from_document(doc).unwrap();
2787 + assert_eq!(back, f);
2788 +
2789 + let f = F {
2790 + num_1: 1,
2791 + // f64 cannot represent many large integers exactly, u64::MAX included
2792 + num_2: u64::MAX,
2793 + };
2794 + let doc_result = to_document(&f);
2795 + assert!(doc_result.is_err());
2796 +
2797 + let f = F {
2798 + num_1: 1,
2799 + num_2: u64::MAX - 255,
2800 + };
2801 + let doc_result = to_document(&f);
2802 + assert!(doc_result.is_err());
2803 +}
2804 +
2805 +#[test]
2806 +fn test_datetime_helpers() {
2807 + use time::{format_description::well_known::Rfc3339, OffsetDateTime};
2808 +
2809 + let _guard = LOCK.run_concurrently();
2810 +
2811 + #[derive(Deserialize, Serialize)]
2812 + struct A {
2813 + #[serde(with = "bson_datetime_as_rfc3339_string")]
2814 + pub date: DateTime,
2815 + }
2816 +
2817 + let iso = "1996-12-20T00:39:57Z";
2818 + let date = OffsetDateTime::parse(iso, &Rfc3339).unwrap();
2819 + let a = A {
2820 + date: crate::DateTime::from_time_0_3(date),
2821 + };
2822 + let doc = to_document(&a).unwrap();
2823 + assert_eq!(doc.get_str("date").unwrap(), iso);
2824 + let a: A = from_document(doc).unwrap();
2825 + assert_eq!(a.date.to_time_0_3(), date);
2826 +
2827 + #[cfg(feature = "time-0_3")]
2828 + {
2829 + use time::macros::datetime;
2830 +
2831 + #[derive(Deserialize, Serialize)]
2832 + struct B {
2833 + #[serde(with = "serde_helpers::time_0_3_offsetdatetime_as_bson_datetime")]
2834 + pub date: time::OffsetDateTime,
2835 + }
2836 +
2837 + let date = r#"
2838 + {
2839 + "date": {
2840 + "$date": {
2841 + "$numberLong": "1591700287095"
2842 + }
2843 + }
2844 + }"#;
2845 + let json: serde_json::Value = serde_json::from_str(date).unwrap();
2846 + let b: B = serde_json::from_value(json).unwrap();
2847 + let expected = datetime!(2020-06-09 10:58:07.095 UTC);
2848 + assert_eq!(b.date, expected);
2849 + let doc = to_document(&b).unwrap();
2850 + assert_eq!(doc.get_datetime("date").unwrap().to_time_0_3(), expected);
2851 + let b: B = from_document(doc).unwrap();
2852 + assert_eq!(b.date, expected);
2853 + }
2854 +
2855 + #[cfg(feature = "chrono-0_4")]
2856 + {
2857 + use std::str::FromStr;
2858 + #[derive(Deserialize, Serialize)]
2859 + struct B {
2860 + #[serde(with = "serde_helpers::chrono_datetime_as_bson_datetime")]
2861 + pub date: chrono::DateTime<chrono::Utc>,
2862 + }
2863 +
2864 + let date = r#"
2865 + {
2866 + "date": {
2867 + "$date": {
2868 + "$numberLong": "1591700287095"
2869 + }
2870 + }
2871 + }"#;
2872 + let json: serde_json::Value = serde_json::from_str(date).unwrap();
2873 + let b: B = serde_json::from_value(json).unwrap();
2874 + let expected: chrono::DateTime<chrono::Utc> =
2875 + chrono::DateTime::from_str("2020-06-09 10:58:07.095 UTC").unwrap();
2876 + assert_eq!(b.date, expected);
2877 + let doc = to_document(&b).unwrap();
2878 + assert_eq!(doc.get_datetime("date").unwrap().to_chrono(), expected);
2879 + let b: B = from_document(doc).unwrap();
2880 + assert_eq!(b.date, expected);
2881 + }
2882 +
2883 + #[derive(Deserialize, Serialize)]
2884 + struct C {
2885 + #[serde(with = "rfc3339_string_as_bson_datetime")]
2886 + pub date: String,
2887 + }
2888 +
2889 + let date = "2020-06-09T10:58:07.095Z";
2890 + let c = C {
2891 + date: date.to_string(),
2892 + };
2893 + let doc = to_document(&c).unwrap();
2894 + assert!(doc.get_datetime("date").is_ok());
2895 + let c: C = from_document(doc).unwrap();
2896 + assert_eq!(c.date.as_str(), date);
2897 +}
2898 +
2899 +#[test]
2900 +fn test_oid_helpers() {
2901 + let _guard = LOCK.run_concurrently();
2902 +
2903 + #[derive(Serialize, Deserialize)]
2904 + struct A {
2905 + #[serde(with = "hex_string_as_object_id")]
2906 + oid: String,
2907 + }
2908 +
2909 + let oid = ObjectId::new();
2910 + let a = A {
2911 + oid: oid.to_string(),
2912 + };
2913 + let doc = to_document(&a).unwrap();
2914 + assert_eq!(doc.get_object_id("oid").unwrap(), oid);
2915 + let a: A = from_document(doc).unwrap();
2916 + assert_eq!(a.oid, oid.to_string());
2917 +}
2918 +
2919 +#[test]
2920 +fn test_i64_as_bson_datetime() {
2921 + let _guard = LOCK.run_concurrently();
2922 +
2923 + #[derive(Serialize, Deserialize)]
2924 + struct A {
2925 + #[serde(with = "i64_as_bson_datetime")]
2926 + now: i64,
2927 + }
2928 +
2929 + let now = DateTime::now();
2930 + let a = A {
2931 + now: now.timestamp_millis(),
2932 + };
2933 + let doc = to_document(&a).unwrap();
2934 + assert_eq!(doc.get_datetime("now").unwrap(), &now);
2935 + let a: A = from_document(doc).unwrap();
2936 + assert_eq!(a.now, now.timestamp_millis());
2937 +}
2938 +
2939 +#[test]
2940 +#[cfg(feature = "uuid-0_8")]
2941 +fn test_uuid_0_8_helpers() {
2942 + use serde_helpers::uuid_as_binary;
2943 + use uuid_0_8::Uuid;
2944 +
2945 + let _guard = LOCK.run_concurrently();
2946 +
2947 + #[derive(Serialize, Deserialize)]
2948 + struct A {
2949 + #[serde(with = "uuid_as_binary")]
2950 + uuid: Uuid,
2951 + }
2952 +
2953 + let uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
2954 + let a = A { uuid };
2955 + let doc = to_document(&a).unwrap();
2956 + match doc.get("uuid").unwrap() {
2957 + Bson::Binary(bin) => {
2958 + assert_eq!(bin.subtype, BinarySubtype::Uuid);
2959 + assert_eq!(bin.bytes, uuid.as_bytes());
2960 + }
2961 + _ => panic!("expected Bson::Binary"),
2962 + }
2963 + let a: A = from_document(doc).unwrap();
2964 + assert_eq!(a.uuid, uuid);
2965 +}
2966 +
2967 +#[test]
2968 +#[cfg(feature = "uuid-1")]
2969 +fn test_uuid_1_helpers() {
2970 + use serde_helpers::uuid_1_as_binary;
2971 + use uuid::Uuid;
2972 +
2973 + let _guard = LOCK.run_concurrently();
2974 +
2975 + #[derive(Serialize, Deserialize)]
2976 + struct A {
2977 + #[serde(with = "uuid_1_as_binary")]
2978 + uuid: Uuid,
2979 + }
2980 +
2981 + let uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
2982 + let a = A { uuid };
2983 + let doc = to_document(&a).unwrap();
2984 + match doc.get("uuid").unwrap() {
2985 + Bson::Binary(bin) => {
2986 + assert_eq!(bin.subtype, BinarySubtype::Uuid);
2987 + assert_eq!(bin.bytes, uuid.as_bytes());
2988 + }
2989 + _ => panic!("expected Bson::Binary"),
2990 + }
2991 + let a: A = from_document(doc).unwrap();
2992 + assert_eq!(a.uuid, uuid);
2993 +}
2994 +
2995 +#[test]
2996 +fn test_timestamp_helpers() {
2997 + let _guard = LOCK.run_concurrently();
2998 +
2999 + #[derive(Deserialize, Serialize)]
3000 + struct A {
3001 + #[serde(with = "u32_as_timestamp")]
3002 + pub time: u32,
3003 + }
3004 +
3005 + let time = 12345;
3006 + let a = A { time };
3007 + let doc = to_document(&a).unwrap();
3008 + let timestamp = doc.get_timestamp("time").unwrap();
3009 + assert_eq!(timestamp.time, time);
3010 + assert_eq!(timestamp.increment, 0);
3011 + let a: A = from_document(doc).unwrap();
3012 + assert_eq!(a.time, time);
3013 +
3014 + #[derive(Deserialize, Serialize)]
3015 + struct B {
3016 + #[serde(with = "timestamp_as_u32")]
3017 + pub timestamp: Timestamp,
3018 + }
3019 +
3020 + let time = 12345;
3021 + let timestamp = Timestamp { time, increment: 0 };
3022 + let b = B { timestamp };
3023 + let val = serde_json::to_value(b).unwrap();
3024 + assert_eq!(val["timestamp"], time);
3025 + let b: B = serde_json::from_value(val).unwrap();
3026 + assert_eq!(b.timestamp, timestamp);
3027 +
3028 + let timestamp = Timestamp {
3029 + time: 12334,
3030 + increment: 1,
3031 + };
3032 + let b = B { timestamp };
3033 + assert!(serde_json::to_value(b).is_err());
3034 +}
3035 +
3036 +#[test]
3037 +fn large_dates() {
3038 + let _guard = LOCK.run_concurrently();
3039 +
3040 + let json = json!({ "d": { "$date": { "$numberLong": i64::MAX.to_string() } } });
3041 + let d = serde_json::from_value::<Document>(json.clone()).unwrap();
3042 + assert_eq!(d.get_datetime("d").unwrap(), &DateTime::MAX);
3043 + let d: Bson = json.try_into().unwrap();
3044 + assert_eq!(
3045 + d.as_document().unwrap().get_datetime("d").unwrap(),
3046 + &DateTime::MAX
3047 + );
3048 +
3049 + let json = json!({ "d": { "$date": { "$numberLong": i64::MIN.to_string() } } });
3050 + let d = serde_json::from_value::<Document>(json.clone()).unwrap();
3051 + assert_eq!(d.get_datetime("d").unwrap(), &DateTime::MIN);
3052 + let d: Bson = json.try_into().unwrap();
3053 + assert_eq!(
3054 + d.as_document().unwrap().get_datetime("d").unwrap(),
3055 + &DateTime::MIN
3056 + );
3057 +}
3058 +
3059 +#[test]
3060 +fn oid_as_hex_string() {
3061 + let _guard = LOCK.run_concurrently();
3062 +
3063 + #[derive(Serialize)]
3064 + struct Foo {
3065 + #[serde(serialize_with = "serialize_object_id_as_hex_string")]
3066 + oid: ObjectId,
3067 + }
3068 +
3069 + let oid = ObjectId::new();
3070 + let foo = Foo { oid };
3071 + let doc = to_document(&foo).unwrap();
3072 + assert_eq!(doc.get_str("oid").unwrap(), oid.to_hex());
3073 +}
3074 +
3075 +#[test]
3076 +fn fuzz_regression_00() {
3077 + let buf: &[u8] = &[227, 0, 35, 4, 2, 0, 255, 255, 255, 127, 255, 255, 255, 47];
3078 + let _ = crate::from_slice::<Document>(buf);
3079 +}
3080 diff --git a/src/tests/spec/corpus.rs b/src/tests/spec/corpus.rs
3081 new file mode 100644
3082 index 0000000..88d872c
3083 --- /dev/null
3084 +++ b/src/tests/spec/corpus.rs
3085 @@ -0,0 +1,573 @@
3086 +use std::{
3087 + convert::{TryFrom, TryInto},
3088 + iter::FromIterator,
3089 + marker::PhantomData,
3090 + str::FromStr,
3091 +};
3092 +
3093 +use crate::{
3094 + raw::{RawBsonRef, RawDocument},
3095 + tests::LOCK,
3096 + Bson,
3097 + Document,
3098 + RawBson,
3099 + RawDocumentBuf,
3100 +};
3101 +use pretty_assertions::assert_eq;
3102 +use serde::{Deserialize, Deserializer};
3103 +
3104 +use super::run_spec_test;
3105 +
3106 +#[derive(Debug, Deserialize)]
3107 +#[serde(deny_unknown_fields)]
3108 +struct TestFile {
3109 + description: String,
3110 + bson_type: String,
3111 + test_key: Option<String>,
3112 +
3113 + #[serde(default)]
3114 + valid: Vec<Valid>,
3115 +
3116 + #[serde(rename = "decodeErrors")]
3117 + #[serde(default)]
3118 + decode_errors: Vec<DecodeError>,
3119 +
3120 + #[serde(rename = "parseErrors")]
3121 + #[serde(default)]
3122 + parse_errors: Vec<ParseError>,
3123 +
3124 + #[allow(dead_code)]
3125 + deprecated: Option<bool>,
3126 +}
3127 +
3128 +#[derive(Debug, Deserialize)]
3129 +#[serde(deny_unknown_fields)]
3130 +struct Valid {
3131 + description: String,
3132 + canonical_bson: String,
3133 + canonical_extjson: String,
3134 + relaxed_extjson: Option<String>,
3135 + degenerate_bson: Option<String>,
3136 + degenerate_extjson: Option<String>,
3137 + #[allow(dead_code)]
3138 + converted_bson: Option<String>,
3139 + #[allow(dead_code)]
3140 + converted_extjson: Option<String>,
3141 + lossy: Option<bool>,
3142 +}
3143 +
3144 +#[derive(Debug, Deserialize)]
3145 +struct DecodeError {
3146 + description: String,
3147 + bson: String,
3148 +}
3149 +
3150 +#[derive(Debug, Deserialize)]
3151 +struct ParseError {
3152 + description: String,
3153 + string: String,
3154 +}
3155 +
3156 +struct FieldVisitor<'a, T>(&'a str, PhantomData<T>);
3157 +
3158 +impl<'de, 'a, T> serde::de::Visitor<'de> for FieldVisitor<'a, T>
3159 +where
3160 + T: Deserialize<'de>,
3161 +{
3162 + type Value = T;
3163 +
3164 + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3165 + write!(formatter, "expecting RawBson at field {}", self.0)
3166 + }
3167 +
3168 + fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
3169 + where
3170 + A: serde::de::MapAccess<'de>,
3171 + {
3172 + while let Some((k, v)) = map.next_entry::<String, T>()? {
3173 + if k.as_str() == self.0 {
3174 + return Ok(v);
3175 + }
3176 + }
3177 + Err(serde::de::Error::custom(format!(
3178 + "missing field: {}",
3179 + self.0
3180 + )))
3181 + }
3182 +}
3183 +
3184 +fn run_test(test: TestFile) {
3185 + let _guard = LOCK.run_concurrently();
3186 + for valid in test.valid {
3187 + let description = format!("{}: {}", test.description, valid.description);
3188 +
3189 + let canonical_bson = hex::decode(&valid.canonical_bson).expect(&description);
3190 +
3191 + // these four cover the four ways to create a [`Document`] from the provided BSON.
3192 + let documentfromreader_cb =
3193 + Document::from_reader(canonical_bson.as_slice()).expect(&description);
3194 +
3195 + let fromreader_cb: Document =
3196 + crate::from_reader(canonical_bson.as_slice()).expect(&description);
3197 +
3198 + let fromdocument_documentfromreader_cb: Document =
3199 + crate::from_document(documentfromreader_cb.clone()).expect(&description);
3200 +
3201 + let todocument_documentfromreader_cb: Document =
3202 + crate::to_document(&documentfromreader_cb).expect(&description);
3203 +
3204 + let canonical_raw_document =
3205 + RawDocument::from_bytes(canonical_bson.as_slice()).expect(&description);
3206 + let document_from_raw_document: Document =
3207 + canonical_raw_document.try_into().expect(&description);
3208 +
3209 + let canonical_raw_bson_from_slice =
3210 + crate::from_slice::<RawBsonRef>(canonical_bson.as_slice())
3211 + .expect(&description)
3212 + .as_document()
3213 + .expect(&description);
3214 +
3215 + let canonical_owned_raw_bson_from_slice =
3216 + crate::from_slice::<RawBson>(canonical_bson.as_slice()).expect(&description);
3217 +
3218 + let canonical_raw_document_from_slice =
3219 + crate::from_slice::<&RawDocument>(canonical_bson.as_slice()).expect(&description);
3220 +
3221 + // These cover the ways to serialize those [`Documents`] back to BSON.
3222 + let mut documenttowriter_documentfromreader_cb = Vec::new();
3223 + documentfromreader_cb
3224 + .to_writer(&mut documenttowriter_documentfromreader_cb)
3225 + .expect(&description);
3226 +
3227 + let mut documenttowriter_fromreader_cb = Vec::new();
3228 + fromreader_cb
3229 + .to_writer(&mut documenttowriter_fromreader_cb)
3230 + .expect(&description);
3231 +
3232 + let mut documenttowriter_fromdocument_documentfromreader_cb = Vec::new();
3233 + fromdocument_documentfromreader_cb
3234 + .to_writer(&mut documenttowriter_fromdocument_documentfromreader_cb)
3235 + .expect(&description);
3236 +
3237 + let mut documenttowriter_todocument_documentfromreader_cb = Vec::new();
3238 + todocument_documentfromreader_cb
3239 + .to_writer(&mut documenttowriter_todocument_documentfromreader_cb)
3240 + .expect(&description);
3241 +
3242 + let tovec_documentfromreader_cb =
3243 + crate::to_vec(&documentfromreader_cb).expect(&description);
3244 +
3245 + let mut documenttowriter_document_from_raw_document = Vec::new();
3246 + document_from_raw_document
3247 + .to_writer(&mut documenttowriter_document_from_raw_document)
3248 + .expect(&description);
3249 +
3250 + // Serialize the raw versions "back" to BSON also.
3251 + let tovec_rawdocument = crate::to_vec(&canonical_raw_document).expect(&description);
3252 + let tovec_rawdocument_from_slice =
3253 + crate::to_vec(&canonical_raw_document_from_slice).expect(&description);
3254 + let tovec_rawbson = crate::to_vec(&canonical_raw_bson_from_slice).expect(&description);
3255 + let tovec_ownedrawbson =
3256 + crate::to_vec(&canonical_owned_raw_bson_from_slice).expect(&description);
3257 +
3258 + // test Bson / RawBson field deserialization
3259 + if let Some(ref test_key) = test.test_key {
3260 + // skip regex tests that don't have the value at the test key
3261 + if !description.contains("$regex query operator") {
3262 + // deserialize the field from raw Bytes into a RawBson
3263 + let mut deserializer_raw =
3264 + crate::de::RawDeserializer::new(canonical_bson.as_slice(), false);
3265 + let raw_bson_field = deserializer_raw
3266 + .deserialize_any(FieldVisitor(test_key.as_str(), PhantomData::<RawBsonRef>))
3267 + .expect(&description);
3268 + // convert to an owned Bson and put into a Document
3269 + let bson: Bson = raw_bson_field.try_into().expect(&description);
3270 + let from_raw_doc = doc! {
3271 + test_key: bson
3272 + };
3273 +
3274 + // deserialize the field from raw Bytes into an OwnedRawBson
3275 + let mut deserializer_raw =
3276 + crate::de::RawDeserializer::new(canonical_bson.as_slice(), false);
3277 + let owned_raw_bson_field = deserializer_raw
3278 + .deserialize_any(FieldVisitor(test_key.as_str(), PhantomData::<RawBson>))
3279 + .expect(&description);
3280 + let from_slice_owned_vec =
3281 + RawDocumentBuf::from_iter([(test_key, owned_raw_bson_field)]).into_bytes();
3282 +
3283 + // deserialize the field from raw Bytes into a Bson
3284 + let mut deserializer_value =
3285 + crate::de::RawDeserializer::new(canonical_bson.as_slice(), false);
3286 + let bson_field = deserializer_value
3287 + .deserialize_any(FieldVisitor(test_key.as_str(), PhantomData::<Bson>))
3288 + .expect(&description);
3289 + // put into a Document
3290 + let from_slice_value_doc = doc! {
3291 + test_key: bson_field,
3292 + };
3293 +
3294 + // deserialize the field from a Bson into a Bson
3295 + let deserializer_value_value =
3296 + crate::Deserializer::new(Bson::Document(documentfromreader_cb.clone()));
3297 + let bson_field = deserializer_value_value
3298 + .deserialize_any(FieldVisitor(test_key.as_str(), PhantomData::<Bson>))
3299 + .expect(&description);
3300 + // put into a Document
3301 + let from_value_value_doc = doc! {
3302 + test_key: bson_field,
3303 + };
3304 +
3305 + // deserialize the field from a Bson into a RawBson
3306 + let deserializer_value_raw =
3307 + crate::Deserializer::new(Bson::Document(documentfromreader_cb.clone()));
3308 + let raw_bson_field = deserializer_value_raw
3309 + .deserialize_any(FieldVisitor(test_key.as_str(), PhantomData::<RawBson>))
3310 + .expect(&description);
3311 + let from_value_raw_doc = doc! {
3312 + test_key: Bson::try_from(raw_bson_field).expect(&description),
3313 + };
3314 +
3315 + // convert back into raw BSON for comparison with canonical BSON
3316 + let from_raw_vec = crate::to_vec(&from_raw_doc).expect(&description);
3317 + let from_slice_value_vec =
3318 + crate::to_vec(&from_slice_value_doc).expect(&description);
3319 + let from_bson_value_vec = crate::to_vec(&from_value_value_doc).expect(&description);
3320 + let from_value_raw_vec = crate::to_vec(&from_value_raw_doc).expect(&description);
3321 +
3322 + assert_eq!(from_raw_vec, canonical_bson, "{}", description);
3323 + assert_eq!(from_slice_value_vec, canonical_bson, "{}", description);
3324 + assert_eq!(from_bson_value_vec, canonical_bson, "{}", description);
3325 + assert_eq!(from_slice_owned_vec, canonical_bson, "{}", description);
3326 + assert_eq!(from_value_raw_vec, canonical_bson, "{}", description);
3327 + }
3328 + }
3329 +
3330 + // native_to_bson( bson_to_native(cB) ) = cB
3331 +
3332 + // now we ensure the hex for all 5 are equivalent to the canonical BSON provided by the
3333 + // test.
3334 + assert_eq!(
3335 + hex::encode(documenttowriter_documentfromreader_cb).to_lowercase(),
3336 + valid.canonical_bson.to_lowercase(),
3337 + "{}",
3338 + description,
3339 + );
3340 +
3341 + assert_eq!(
3342 + hex::encode(documenttowriter_fromreader_cb).to_lowercase(),
3343 + valid.canonical_bson.to_lowercase(),
3344 + "{}",
3345 + description,
3346 + );
3347 +
3348 + assert_eq!(
3349 + hex::encode(documenttowriter_fromdocument_documentfromreader_cb).to_lowercase(),
3350 + valid.canonical_bson.to_lowercase(),
3351 + "{}",
3352 + description,
3353 + );
3354 +
3355 + assert_eq!(
3356 + hex::encode(documenttowriter_todocument_documentfromreader_cb).to_lowercase(),
3357 + valid.canonical_bson.to_lowercase(),
3358 + "{}",
3359 + description,
3360 + );
3361 +
3362 + assert_eq!(
3363 + hex::encode(tovec_documentfromreader_cb).to_lowercase(),
3364 + valid.canonical_bson.to_lowercase(),
3365 + "{}",
3366 + description,
3367 + );
3368 +
3369 + assert_eq!(
3370 + hex::encode(documenttowriter_document_from_raw_document).to_lowercase(),
3371 + valid.canonical_bson.to_lowercase(),
3372 + "{}",
3373 + description,
3374 + );
3375 +
3376 + assert_eq!(tovec_rawdocument, tovec_rawbson, "{}", description);
3377 + assert_eq!(
3378 + tovec_rawdocument, tovec_rawdocument_from_slice,
3379 + "{}",
3380 + description
3381 + );
3382 + assert_eq!(tovec_rawdocument, tovec_ownedrawbson, "{}", description);
3383 +
3384 + assert_eq!(
3385 + hex::encode(tovec_rawdocument).to_lowercase(),
3386 + valid.canonical_bson.to_lowercase(),
3387 + "{}",
3388 + description,
3389 + );
3390 +
3391 + // NaN == NaN is false, so we skip document comparisons that contain NaN
3392 + if !description.to_ascii_lowercase().contains("nan") && !description.contains("decq541") {
3393 + assert_eq!(documentfromreader_cb, fromreader_cb, "{}", description);
3394 +
3395 + assert_eq!(
3396 + documentfromreader_cb, fromdocument_documentfromreader_cb,
3397 + "{}",
3398 + description
3399 + );
3400 +
3401 + assert_eq!(
3402 + documentfromreader_cb, todocument_documentfromreader_cb,
3403 + "{}",
3404 + description
3405 + );
3406 +
3407 + assert_eq!(
3408 + document_from_raw_document, documentfromreader_cb,
3409 + "{}",
3410 + description
3411 + );
3412 + }
3413 +
3414 + // native_to_bson( bson_to_native(dB) ) = cB
3415 +
3416 + if let Some(db) = valid.degenerate_bson {
3417 + let db = hex::decode(&db).expect(&description);
3418 +
3419 + let bson_to_native_db = Document::from_reader(db.as_slice()).expect(&description);
3420 + let mut native_to_bson_bson_to_native_db = Vec::new();
3421 + bson_to_native_db
3422 + .to_writer(&mut native_to_bson_bson_to_native_db)
3423 + .unwrap();
3424 + assert_eq!(
3425 + hex::encode(native_to_bson_bson_to_native_db).to_lowercase(),
3426 + valid.canonical_bson.to_lowercase(),
3427 + "{}",
3428 + description,
3429 + );
3430 +
3431 + let bson_to_native_db_serde: Document =
3432 + crate::from_reader(db.as_slice()).expect(&description);
3433 + let mut native_to_bson_bson_to_native_db_serde = Vec::new();
3434 + bson_to_native_db_serde
3435 + .to_writer(&mut native_to_bson_bson_to_native_db_serde)
3436 + .unwrap();
3437 + assert_eq!(
3438 + hex::encode(native_to_bson_bson_to_native_db_serde).to_lowercase(),
3439 + valid.canonical_bson.to_lowercase(),
3440 + "{}",
3441 + description,
3442 + );
3443 +
3444 + let document_from_raw_document: Document = RawDocument::from_bytes(db.as_slice())
3445 + .expect(&description)
3446 + .try_into()
3447 + .expect(&description);
3448 + let mut documenttowriter_document_from_raw_document = Vec::new();
3449 + document_from_raw_document
3450 + .to_writer(&mut documenttowriter_document_from_raw_document)
3451 + .expect(&description);
3452 + assert_eq!(
3453 + hex::encode(documenttowriter_document_from_raw_document).to_lowercase(),
3454 + valid.canonical_bson.to_lowercase(),
3455 + "{}",
3456 + description,
3457 + );
3458 +
3459 + // NaN == NaN is false, so we skip document comparisons that contain NaN
3460 + if !description.contains("NaN") {
3461 + assert_eq!(
3462 + bson_to_native_db_serde, documentfromreader_cb,
3463 + "{}",
3464 + description
3465 + );
3466 +
3467 + assert_eq!(
3468 + document_from_raw_document, documentfromreader_cb,
3469 + "{}",
3470 + description
3471 + );
3472 + }
3473 + }
3474 +
3475 + let cej: serde_json::Value =
3476 + serde_json::from_str(&valid.canonical_extjson).expect(&description);
3477 +
3478 + // native_to_canonical_extended_json( bson_to_native(cB) ) = cEJ
3479 +
3480 + let mut cej_updated_float = cej.clone();
3481 +
3482 + // Rust doesn't format f64 with exponential notation by default, and the spec doesn't give
3483 + // guidance on when to use it, so we manually parse any $numberDouble fields with
3484 + // exponential notation and replace them with non-exponential notation.
3485 + if let Some(ref key) = test.test_key {
3486 + if let Some(serde_json::Value::Object(subdoc)) = cej_updated_float.get_mut(key) {
3487 + if let Some(&mut serde_json::Value::String(ref mut s)) =
3488 + subdoc.get_mut("$numberDouble")
3489 + {
3490 + if s.to_lowercase().contains('e') {
3491 + let d = f64::from_str(s).unwrap();
3492 + let mut fixed_string = format!("{}", d);
3493 +
3494 + if d.fract() == 0.0 {
3495 + fixed_string.push_str(".0");
3496 + }
3497 +
3498 + *s = fixed_string;
3499 + }
3500 + }
3501 + }
3502 + }
3503 +
3504 + assert_eq!(
3505 + Bson::Document(documentfromreader_cb.clone()).into_canonical_extjson(),
3506 + cej_updated_float,
3507 + "{}",
3508 + description
3509 + );
3510 +
3511 + // native_to_relaxed_extended_json( bson_to_native(cB) ) = cEJ
3512 +
3513 + if let Some(ref relaxed_extjson) = valid.relaxed_extjson {
3514 + let rej: serde_json::Value = serde_json::from_str(relaxed_extjson).expect(&description);
3515 +
3516 + assert_eq!(
3517 + Bson::Document(documentfromreader_cb.clone()).into_relaxed_extjson(),
3518 + rej,
3519 + "{}",
3520 + description
3521 + );
3522 + }
3523 +
3524 + // native_to_canonical_extended_json( json_to_native(cEJ) ) = cEJ
3525 +
3526 + let json_to_native_cej: Bson = cej.clone().try_into().expect("cej into bson should work");
3527 +
3528 + let native_to_canonical_extended_json_bson_to_native_cej =
3529 + json_to_native_cej.clone().into_canonical_extjson();
3530 +
3531 + assert_eq!(
3532 + native_to_canonical_extended_json_bson_to_native_cej, cej_updated_float,
3533 + "{}",
3534 + description,
3535 + );
3536 +
3537 + // native_to_bson( json_to_native(cEJ) ) = cB (unless lossy)
3538 +
3539 + if valid.lossy != Some(true) {
3540 + let mut native_to_bson_json_to_native_cej = Vec::new();
3541 + json_to_native_cej
3542 + .as_document()
3543 + .unwrap()
3544 + .to_writer(&mut native_to_bson_json_to_native_cej)
3545 + .unwrap();
3546 +
3547 + assert_eq!(
3548 + hex::encode(native_to_bson_json_to_native_cej).to_lowercase(),
3549 + valid.canonical_bson.to_lowercase(),
3550 + "{}",
3551 + description,
3552 + );
3553 + }
3554 +
3555 + if let Some(ref degenerate_extjson) = valid.degenerate_extjson {
3556 + let dej: serde_json::Value =
3557 + serde_json::from_str(degenerate_extjson).expect(&description);
3558 +
3559 + let json_to_native_dej: Bson = dej.clone().try_into().unwrap();
3560 +
3561 + // native_to_canonical_extended_json( json_to_native(dEJ) ) = cEJ
3562 +
3563 + let native_to_canonical_extended_json_json_to_native_dej =
3564 + json_to_native_dej.clone().into_canonical_extjson();
3565 +
3566 + assert_eq!(
3567 + native_to_canonical_extended_json_json_to_native_dej, cej,
3568 + "{}",
3569 + description,
3570 + );
3571 +
3572 + // native_to_bson( json_to_native(dEJ) ) = cB (unless lossy)
3573 +
3574 + if valid.lossy != Some(true) {
3575 + let mut native_to_bson_json_to_native_dej = Vec::new();
3576 + json_to_native_dej
3577 + .as_document()
3578 + .unwrap()
3579 + .to_writer(&mut native_to_bson_json_to_native_dej)
3580 + .unwrap();
3581 +
3582 + assert_eq!(
3583 + hex::encode(native_to_bson_json_to_native_dej).to_lowercase(),
3584 + valid.canonical_bson.to_lowercase(),
3585 + "{}",
3586 + description,
3587 + );
3588 + }
3589 + }
3590 +
3591 + // native_to_relaxed_extended_json( json_to_native(rEJ) ) = rEJ
3592 +
3593 + if let Some(ref rej) = valid.relaxed_extjson {
3594 + let rej: serde_json::Value = serde_json::from_str(rej).unwrap();
3595 +
3596 + let json_to_native_rej: Bson = rej.clone().try_into().unwrap();
3597 +
3598 + let native_to_relaxed_extended_json_bson_to_native_rej =
3599 + json_to_native_rej.clone().into_relaxed_extjson();
3600 +
3601 + assert_eq!(
3602 + native_to_relaxed_extended_json_bson_to_native_rej, rej,
3603 + "{}",
3604 + description,
3605 + );
3606 + }
3607 + }
3608 +
3609 + for decode_error in test.decode_errors.iter() {
3610 + let description = format!(
3611 + "{} decode error: {}",
3612 + test.bson_type, decode_error.description
3613 + );
3614 + let bson = hex::decode(&decode_error.bson).expect("should decode from hex");
3615 +
3616 + if let Ok(doc) = RawDocument::from_bytes(bson.as_slice()) {
3617 + Document::try_from(doc).expect_err(description.as_str());
3618 + }
3619 +
3620 + // No meaningful definition of "byte count" for an arbitrary reader.
3621 + if decode_error.description
3622 + == "Stated length less than byte count, with garbage after envelope"
3623 + {
3624 + continue;
3625 + }
3626 +
3627 + Document::from_reader(bson.as_slice()).expect_err(&description);
3628 + crate::from_reader::<_, Document>(bson.as_slice()).expect_err(description.as_str());
3629 +
3630 + if decode_error.description.contains("invalid UTF-8") {
3631 + crate::from_reader_utf8_lossy::<_, Document>(bson.as_slice()).unwrap_or_else(|err| {
3632 + panic!(
3633 + "{}: utf8_lossy should not fail (failed with {:?})",
3634 + description, err
3635 + )
3636 + });
3637 + }
3638 + }
3639 +
3640 + for parse_error in test.parse_errors {
3641 + // no special support for dbref convention
3642 + if parse_error.description.contains("DBRef") {
3643 + continue;
3644 + }
3645 +
3646 + let json: serde_json::Value = serde_json::Value::String(parse_error.string);
3647 +
3648 + if let Ok(bson) = Bson::try_from(json.clone()) {
3649 + // if converting to bson succeeds, assert that translating that bson to bytes fails
3650 + assert!(crate::to_vec(&bson).is_err());
3651 + }
3652 + }
3653 +}
3654 +
3655 +#[test]
3656 +fn run() {
3657 + run_spec_test(&["bson-corpus"], run_test);
3658 +}
3659 diff --git a/src/tests/spec/json/bson-corpus/array.json b/src/tests/spec/json/bson-corpus/array.json
3660 new file mode 100644
3661 index 0000000..9ff953e
3662 --- /dev/null
3663 +++ b/src/tests/spec/json/bson-corpus/array.json
3664 @@ -0,0 +1,49 @@
3665 +{
3666 + "description": "Array",
3667 + "bson_type": "0x04",
3668 + "test_key": "a",
3669 + "valid": [
3670 + {
3671 + "description": "Empty",
3672 + "canonical_bson": "0D000000046100050000000000",
3673 + "canonical_extjson": "{\"a\" : []}"
3674 + },
3675 + {
3676 + "description": "Single Element Array",
3677 + "canonical_bson": "140000000461000C0000001030000A0000000000",
3678 + "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
3679 + },
3680 + {
3681 + "description": "Single Element Array with index set incorrectly to empty string",
3682 + "degenerate_bson": "130000000461000B00000010000A0000000000",
3683 + "canonical_bson": "140000000461000C0000001030000A0000000000",
3684 + "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
3685 + },
3686 + {
3687 + "description": "Single Element Array with index set incorrectly to ab",
3688 + "degenerate_bson": "150000000461000D000000106162000A0000000000",
3689 + "canonical_bson": "140000000461000C0000001030000A0000000000",
3690 + "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
3691 + },
3692 + {
3693 + "description": "Multi Element Array with duplicate indexes",
3694 + "degenerate_bson": "1b000000046100130000001030000a000000103000140000000000",
3695 + "canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
3696 + "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}"
3697 + }
3698 + ],
3699 + "decodeErrors": [
3700 + {
3701 + "description": "Array length too long: eats outer terminator",
3702 + "bson": "140000000461000D0000001030000A0000000000"
3703 + },
3704 + {
3705 + "description": "Array length too short: leaks terminator",
3706 + "bson": "140000000461000B0000001030000A0000000000"
3707 + },
3708 + {
3709 + "description": "Invalid Array: bad string length in field",
3710 + "bson": "1A00000004666F6F00100000000230000500000062617A000000"
3711 + }
3712 + ]
3713 +}
3714 diff --git a/src/tests/spec/json/bson-corpus/binary.json b/src/tests/spec/json/bson-corpus/binary.json
3715 new file mode 100644
3716 index 0000000..20aaef7
3717 --- /dev/null
3718 +++ b/src/tests/spec/json/bson-corpus/binary.json
3719 @@ -0,0 +1,123 @@
3720 +{
3721 + "description": "Binary type",
3722 + "bson_type": "0x05",
3723 + "test_key": "x",
3724 + "valid": [
3725 + {
3726 + "description": "subtype 0x00 (Zero-length)",
3727 + "canonical_bson": "0D000000057800000000000000",
3728 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}"
3729 + },
3730 + {
3731 + "description": "subtype 0x00 (Zero-length, keys reversed)",
3732 + "canonical_bson": "0D000000057800000000000000",
3733 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}",
3734 + "degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}"
3735 + },
3736 + {
3737 + "description": "subtype 0x00",
3738 + "canonical_bson": "0F0000000578000200000000FFFF00",
3739 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}"
3740 + },
3741 + {
3742 + "description": "subtype 0x01",
3743 + "canonical_bson": "0F0000000578000200000001FFFF00",
3744 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}"
3745 + },
3746 + {
3747 + "description": "subtype 0x02",
3748 + "canonical_bson": "13000000057800060000000202000000FFFF00",
3749 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}"
3750 + },
3751 + {
3752 + "description": "subtype 0x03",
3753 + "canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
3754 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}"
3755 + },
3756 + {
3757 + "description": "subtype 0x04",
3758 + "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
3759 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
3760 + },
3761 + {
3762 + "description": "subtype 0x04 UUID",
3763 + "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
3764 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
3765 + "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
3766 + },
3767 + {
3768 + "description": "subtype 0x05",
3769 + "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
3770 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}"
3771 + },
3772 + {
3773 + "description": "subtype 0x07",
3774 + "canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
3775 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
3776 + },
3777 + {
3778 + "description": "subtype 0x08",
3779 + "canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
3780 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
3781 + },
3782 + {
3783 + "description": "subtype 0x80",
3784 + "canonical_bson": "0F0000000578000200000080FFFF00",
3785 + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}"
3786 + },
3787 + {
3788 + "description": "$type query operator (conflicts with legacy $binary form with $type field)",
3789 + "canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000",
3790 + "canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}"
3791 + },
3792 + {
3793 + "description": "$type query operator (conflicts with legacy $binary form with $type field)",
3794 + "canonical_bson": "180000000378001000000010247479706500020000000000",
3795 + "canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}"
3796 + }
3797 + ],
3798 + "decodeErrors": [
3799 + {
3800 + "description": "Length longer than document",
3801 + "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
3802 + },
3803 + {
3804 + "description": "Negative length",
3805 + "bson": "0D000000057800FFFFFFFF0000"
3806 + },
3807 + {
3808 + "description": "subtype 0x02 length too long ",
3809 + "bson": "13000000057800060000000203000000FFFF00"
3810 + },
3811 + {
3812 + "description": "subtype 0x02 length too short",
3813 + "bson": "13000000057800060000000201000000FFFF00"
3814 + },
3815 + {
3816 + "description": "subtype 0x02 length negative one",
3817 + "bson": "130000000578000600000002FFFFFFFFFFFF00"
3818 + }
3819 + ],
3820 + "parseErrors": [
3821 + {
3822 + "description": "$uuid wrong type",
3823 + "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
3824 + },
3825 + {
3826 + "description": "$uuid invalid value--too short",
3827 + "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
3828 + },
3829 + {
3830 + "description": "$uuid invalid value--too long",
3831 + "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}"
3832 + },
3833 + {
3834 + "description": "$uuid invalid value--misplaced hyphens",
3835 + "string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}"
3836 + },
3837 + {
3838 + "description": "$uuid invalid value--too many hyphens",
3839 + "string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}"
3840 + }
3841 + ]
3842 +}
3843 diff --git a/src/tests/spec/json/bson-corpus/boolean.json b/src/tests/spec/json/bson-corpus/boolean.json
3844 new file mode 100644
3845 index 0000000..84c2822
3846 --- /dev/null
3847 +++ b/src/tests/spec/json/bson-corpus/boolean.json
3848 @@ -0,0 +1,27 @@
3849 +{
3850 + "description": "Boolean",
3851 + "bson_type": "0x08",
3852 + "test_key": "b",
3853 + "valid": [
3854 + {
3855 + "description": "True",
3856 + "canonical_bson": "090000000862000100",
3857 + "canonical_extjson": "{\"b\" : true}"
3858 + },
3859 + {
3860 + "description": "False",
3861 + "canonical_bson": "090000000862000000",
3862 + "canonical_extjson": "{\"b\" : false}"
3863 + }
3864 + ],
3865 + "decodeErrors": [
3866 + {
3867 + "description": "Invalid boolean value of 2",
3868 + "bson": "090000000862000200"
3869 + },
3870 + {
3871 + "description": "Invalid boolean value of -1",
3872 + "bson": "09000000086200FF00"
3873 + }
3874 + ]
3875 +}
3876 diff --git a/src/tests/spec/json/bson-corpus/bsonview b/src/tests/spec/json/bson-corpus/bsonview
3877 new file mode 100755
3878 index 0000000..b803fc8
3879 --- /dev/null
3880 +++ b/src/tests/spec/json/bson-corpus/bsonview
3881 @@ -0,0 +1,434 @@
3882 +#!/usr/bin/env perl
3883 +use v5.10;
3884 +use strict;
3885 +use warnings;
3886 +use utf8;
3887 +use open qw/:std :utf8/;
3888 +
3889 +use Getopt::Long;
3890 +use Pod::Usage;
3891 +
3892 +use if $^O eq 'MSWin32', 'Win32::Console::ANSI';
3893 +use Term::ANSIColor;
3894 +
3895 +use constant {
3896 + NULL => "\x00",
3897 + BSON_TYPE => "C",
3898 + BSON_ENAME => "Z*",
3899 + BSON_TYPE_NAME => "CZ*",
3900 + BSON_DOUBLE => "d",
3901 + BSON_STRING => "l/A",
3902 + BSON_BOOLEAN => "C",
3903 + BSON_REGEX => "Z*Z*",
3904 + BSON_JSCODE => "",
3905 + BSON_INT32 => "l",
3906 + BSON_INT64 => "q",
3907 + BSON_TIMESTAMP => "q",
3908 + BSON_CODE_W_SCOPE => "l",
3909 + BSON_REMAINING => 'a*',
3910 + BSON_SKIP_4_BYTES => 'x4',
3911 + BSON_OBJECTID => 'a12',
3912 + BSON_BINARY_TYPE => 'C',
3913 + BSON_CSTRING => 'Z*',
3914 + BSON_BYTES => 'a*'
3915 +};
3916 +
3917 +my $BOLD = $^O eq 'MSWin32' ? "bold " : "";
3918 +
3919 +# minimum field size
3920 +my %FIELD_SIZES = (
3921 + 0x01 => 8,
3922 + 0x02 => 5,
3923 + 0x03 => 5,
3924 + 0x04 => 5,
3925 + 0x05 => 5,
3926 + 0x06 => 0,
3927 + 0x07 => 12,
3928 + 0x08 => 1,
3929 + 0x09 => 8,
3930 + 0x0A => 0,
3931 + 0x0B => 2,
3932 + 0x0C => 17,
3933 + 0x0D => 5,
3934 + 0x0E => 5,
3935 + 0x0F => 14,
3936 + 0x10 => 4,
3937 + 0x11 => 8,
3938 + 0x12 => 8,
3939 + 0x7F => 0,
3940 + 0xFF => 0,
3941 +);
3942 +
3943 +sub main {
3944 + my ( $hex, $file, $help );
3945 + GetOptions(
3946 + "file=s" => \$file,
3947 + "x" => \$hex,
3948 + "help|h" => \$help,
3949 + ) or die("Error in command line args");
3950 + pod2usage( { -exitval => 2, -verbose => 2, } ) if $help;
3951 +
3952 + if ( $file ) {
3953 + dump_file($file);
3954 + }
3955 + else {
3956 + dump_stdin($hex);
3957 + }
3958 +}
3959 +
3960 +sub dump_stdin {
3961 + my $hex = shift;
3962 + while ( defined( my $bson = <STDIN> ) ) {
3963 + chomp $bson;
3964 + if ( !length($bson) ) {
3965 + print_error("[ no document ]\n");
3966 + next;
3967 + }
3968 + # in -x mode, treat leading # as a comment
3969 + if ( $hex && index( $bson, "#" ) == 0 ) {
3970 + say $bson;
3971 + next;
3972 + }
3973 + $bson =~ s[ ][]g if $hex;
3974 + $bson = pack( "H*", $bson ) if $hex;
3975 + dump_document( \$bson );
3976 + print "\n";
3977 + }
3978 +}
3979 +
3980 +sub dump_file {
3981 + my $file = shift;
3982 + open my $fh, "<", $file;
3983 + binmode($fh);
3984 + my $data = do { local $/; <$fh> };
3985 + while ( length $data ) {
3986 + my $len = unpack( BSON_INT32, $data );
3987 + my $bson = substr($data,0,$len,'');
3988 + dump_document(\$bson);
3989 + print "\n";
3990 + }
3991 +}
3992 +
3993 +sub dump_document {
3994 + my ( $ref, $is_array ) = @_;
3995 + print $is_array ? " [" : " {" if defined $is_array;
3996 + dump_header($ref);
3997 + 1 while dump_field($ref);
3998 + print_error( " " . unpack( "H*", $$ref ) ) if length($$ref);
3999 + print $is_array ? " ]" : " }" if defined $is_array;
4000 + return;
4001 +}
4002 +
4003 +sub dump_header {
4004 + my ($ref) = @_;
4005 +
4006 + my $len = get_length( $ref, 4 );
4007 + return unless defined $len;
4008 +
4009 + if ( $len < 5 || $len < length($$ref) + 4 ) {
4010 + print_length( $len, 'red' );
4011 + }
4012 + else {
4013 + print_length( $len, 'blue' );
4014 + }
4015 +}
4016 +
4017 +sub dump_field {
4018 + my ($ref) = @_;
4019 +
4020 + # detect end of document
4021 + if ( length($$ref) < 2 ) {
4022 + if ( length($$ref) == 0 ) {
4023 + print_error(" [missing terminator]");
4024 + }
4025 + else {
4026 + my $end = substr( $$ref, 0, 1, '' );
4027 + print_hex( $end, $end eq NULL ? 'blue' : 'red' );
4028 + }
4029 + return;
4030 + }
4031 +
4032 + # unpack type
4033 + my $type = unpack( BSON_TYPE, substr( $$ref, 0, 1, '' ) );
4034 +
4035 + if ( !exists $FIELD_SIZES{$type} ) {
4036 + print_type( $type, 'red' );
4037 + return;
4038 + }
4039 +
4040 + print_type($type);
4041 +
4042 + # check for key termination
4043 + my $key_end = index( $$ref, NULL );
4044 + return if $key_end == -1;
4045 +
4046 + # unpack key
4047 + my $key = unpack( BSON_CSTRING, substr( $$ref, 0, $key_end + 1, '' ) );
4048 + print_key($key);
4049 +
4050 + # Check if there is enough data to complete field for this type
4051 + # This is greedy, so it checks length, not length -1
4052 + my $min_size = $FIELD_SIZES{$type};
4053 + return if length($$ref) < $min_size;
4054 +
4055 + # fields without payload: 0x06, 0x0A, 0x7F, 0xFF
4056 + return 1 if $min_size == 0;
4057 +
4058 + # document or array
4059 + if ( $type == 0x03 || $type == 0x04 ) {
4060 + my ($len) = unpack( BSON_INT32, $$ref );
4061 + my $doc = substr( $$ref, 0, $len, '' );
4062 + dump_document( \$doc, $type == 0x04 );
4063 + return 1;
4064 + }
4065 +
4066 + # fixed width fields
4067 + if ( $type == 0x01
4068 + || $type == 0x07
4069 + || $type == 0x09
4070 + || $type == 0x10
4071 + || $type == 0x11
4072 + || $type == 0x12 )
4073 + {
4074 + my $len = ( $type == 0x10 ? 4 : $type == 0x07 ? 12 : 8 );
4075 + print_hex( substr( $$ref, 0, $len, '' ) );
4076 + return 1;
4077 + }
4078 +
4079 + # boolean
4080 + if ( $type == 0x08 ) {
4081 + my $bool = substr( $$ref, 0, 1, '' );
4082 + print_hex( $bool, ( $bool eq "\x00" || $bool eq "\x01" ) ? 'green' : 'red' );
4083 + return 1;
4084 + }
4085 +
4086 + # binary field
4087 + if ( $type == 0x05 ) {
4088 + my $len = get_length( $ref, -1 );
4089 + my $subtype = substr( $$ref, 0, 1, '' );
4090 +
4091 + if ( !defined($len) ) {
4092 + print_hex($subtype);
4093 + return;
4094 + }
4095 +
4096 + my $binary = substr( $$ref, 0, $len, '' );
4097 +
4098 + print_length($len);
4099 + print_hex($subtype);
4100 +
4101 + if ( $subtype eq "\x02" ) {
4102 + my $bin_len = get_length( \$binary );
4103 + if ( !defined($bin_len) ) {
4104 + print_hex( $binary, 'red' );
4105 + return;
4106 + }
4107 + if ( $bin_len != length($binary) ) {
4108 + print_length( $bin_len, 'red' );
4109 + print_hex( $binary, 'red' );
4110 + return;
4111 + }
4112 + }
4113 +
4114 + print_hex($binary) if length($binary);
4115 + return 1;
4116 + }
4117 +
4118 + # string or symbol or code
4119 + if ( $type == 0x02 || $type == 0x0e || $type == 0x0d ) {
4120 + my ( $len, $string ) = get_string($ref);
4121 + return unless defined $len;
4122 +
4123 + print_length( $len, 'cyan' );
4124 + print_string($string);
4125 + return 1;
4126 +
4127 + }
4128 +
4129 + # regex 0x0B
4130 + if ( $type == 0x0B ) {
4131 + my ( $pattern, $flag ) = unpack( BSON_CSTRING . BSON_CSTRING, $$ref );
4132 + substr( $$ref, 0, length($pattern) + length($flag) + 2, '' );
4133 + print_string($pattern);
4134 + print_string($flag);
4135 + return 1;
4136 + }
4137 +
4138 + # code with scope 0x0F
4139 + if ( $type == 0x0F ) {
4140 + my $len = get_length( $ref, 4 );
4141 + return unless defined $len;
4142 +
4143 + # len + string + doc minimum size is 4 + 5 + 5
4144 + if ( $len < 14 ) {
4145 + print_length( $len, 'red' );
4146 + return;
4147 + }
4148 +
4149 + print_length($len);
4150 +
4151 + my $cws = substr( $$ref, 0, $len - 4, '' );
4152 +
4153 + my ( $strlen, $string ) = get_string( \$cws );
4154 +
4155 + if ( !defined $strlen ) {
4156 + print_hex( $cws, 'red' );
4157 + return;
4158 + }
4159 +
4160 + print_length($strlen);
4161 + print_string($string);
4162 +
4163 + dump_document( \$cws, 0 );
4164 +
4165 + return 1;
4166 + }
4167 +
4168 + # dbpointer 0x0C
4169 + if ( $type == 0x0C ) {
4170 + my ( $len, $string ) = get_string($ref);
4171 + return unless defined $len;
4172 +
4173 + print_length($len);
4174 + print_string($string);
4175 +
4176 + # Check if there are 12 bytes (plus terminator) or more
4177 + return if length($$ref) < 13;
4178 +
4179 + my $oid = substr( $$ref, 0, 12, '' );
4180 + print_hex($oid);
4181 +
4182 + return 1;
4183 + }
4184 +
4185 + die "Shouldn't reach here";
4186 +}
4187 +
4188 +sub get_length {
4189 + my ( $ref, $adj ) = @_;
4190 + $adj ||= 0;
4191 + my $len = unpack( BSON_INT32, substr( $$ref, 0, 4, '' ) );
4192 + return unless defined $len;
4193 +
4194 + # check if requested length is too long
4195 + if ( $len < 0 || $len > length($$ref) + $adj ) {
4196 + print_length( $len, 'red' );
4197 + return;
4198 + }
4199 +
4200 + return $len;
4201 +}
4202 +
4203 +sub get_string {
4204 + my ($ref) = @_;
4205 +
4206 + my $len = get_length($ref);
4207 + return unless defined $len;
4208 +
4209 + # len must be at least 1 for trailing 0x00
4210 + if ( $len == 0 ) {
4211 + print_length( $len, 'red' );
4212 + return;
4213 + }
4214 +
4215 + my $string = substr( $$ref, 0, $len, '' );
4216 +
4217 + # check if null terminated
4218 + if ( substr( $string, -1, 1 ) ne NULL ) {
4219 + print_length($len);
4220 + print_hex( $string, 'red' );
4221 + return;
4222 + }
4223 +
4224 + # remove trailing null
4225 + chop($string);
4226 +
4227 + # try to decode to UTF-8
4228 + if ( !utf8::decode($string) ) {
4229 + print_length($len);
4230 + print_hex( $string . "\x00", 'red' );
4231 + return;
4232 + }
4233 +
4234 + return ( $len, $string );
4235 +}
4236 +
4237 +sub print_error {
4238 + my ($text) = @_;
4239 + print colored( ["${BOLD}red"], $text );
4240 +}
4241 +
4242 +sub print_type {
4243 + my ( $type, $color ) = @_;
4244 + $color ||= 'magenta';
4245 + print colored( ["$BOLD$color"], sprintf( " %02x", $type ) );
4246 +}
4247 +
4248 +sub print_key {
4249 + my ($string) = @_;
4250 + print_string( $string, 'yellow' );
4251 +}
4252 +
4253 +sub print_string {
4254 + my ( $string, $color ) = @_;
4255 + $color ||= 'green';
4256 + $string =~ s{([^[:graph:]])}{sprintf("\\x%02x",ord($1))}ge;
4257 + print colored( ["$BOLD$color"], qq[ "$string"] . " 00" );
4258 +}
4259 +
4260 +sub print_length {
4261 + my ( $len, $color ) = @_;
4262 + $color ||= 'cyan';
4263 + print colored( ["$BOLD$color"], " " . unpack( "H*", pack( BSON_INT32, $len ) ) );
4264 +}
4265 +
4266 +sub print_hex {
4267 + my ( $value, $color ) = @_;
4268 + $color ||= 'green';
4269 + print colored( ["$BOLD$color"], " " . uc( unpack( "H*", $value ) ) );
4270 +}
4271 +
4272 +main();
4273 +
4274 +__END__
4275 +
4276 +=head1 NAME
4277 +
4278 +bsonview - dump a BSON string with color output showing structure
4279 +
4280 +=head1 SYNOPSIS
4281 +
4282 + cat file.bson | bsondump
4283 +
4284 + echo "0500000000" | bsondump -x
4285 +
4286 +=head1 OPTIONS
4287 +
4288 + -x input is in hex format (default is 0)
4289 + --help, -h show help
4290 +
4291 +=head1 USAGE
4292 +
4293 +Reads from C<STDIN> and dumps colored structures to C<STDOUT>.
4294 +
4295 +=head1 AUTHOR
4296 +
4297 +=over 4
4298 +
4299 +=item *
4300 +
4301 +David Golden <[email protected]>
4302 +
4303 +=back
4304 +
4305 +=head1 COPYRIGHT AND LICENSE
4306 +
4307 +This software is Copyright (c) 2016 by MongoDB, Inc..
4308 +
4309 +This is free software, licensed under:
4310 +
4311 + The Apache License, Version 2.0, January 2004
4312 +
4313 +=cut
4314 +
4315 +=cut
4316 diff --git a/src/tests/spec/json/bson-corpus/code.json b/src/tests/spec/json/bson-corpus/code.json
4317 new file mode 100644
4318 index 0000000..b8482b2
4319 --- /dev/null
4320 +++ b/src/tests/spec/json/bson-corpus/code.json
4321 @@ -0,0 +1,67 @@
4322 +{
4323 + "description": "Javascript Code",
4324 + "bson_type": "0x0D",
4325 + "test_key": "a",
4326 + "valid": [
4327 + {
4328 + "description": "Empty string",
4329 + "canonical_bson": "0D0000000D6100010000000000",
4330 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\"}}"
4331 + },
4332 + {
4333 + "description": "Single character",
4334 + "canonical_bson": "0E0000000D610002000000620000",
4335 + "canonical_extjson": "{\"a\" : {\"$code\" : \"b\"}}"
4336 + },
4337 + {
4338 + "description": "Multi-character",
4339 + "canonical_bson": "190000000D61000D0000006162616261626162616261620000",
4340 + "canonical_extjson": "{\"a\" : {\"$code\" : \"abababababab\"}}"
4341 + },
4342 + {
4343 + "description": "two-byte UTF-8 (\u00e9)",
4344 + "canonical_bson": "190000000D61000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
4345 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}}"
4346 + },
4347 + {
4348 + "description": "three-byte UTF-8 (\u2606)",
4349 + "canonical_bson": "190000000D61000D000000E29886E29886E29886E298860000",
4350 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u2606\\u2606\\u2606\\u2606\"}}"
4351 + },
4352 + {
4353 + "description": "Embedded nulls",
4354 + "canonical_bson": "190000000D61000D0000006162006261620062616261620000",
4355 + "canonical_extjson": "{\"a\" : {\"$code\" : \"ab\\u0000bab\\u0000babab\"}}"
4356 + }
4357 + ],
4358 + "decodeErrors": [
4359 + {
4360 + "description": "bad code string length: 0 (but no 0x00 either)",
4361 + "bson": "0C0000000D61000000000000"
4362 + },
4363 + {
4364 + "description": "bad code string length: -1",
4365 + "bson": "0C0000000D6100FFFFFFFF00"
4366 + },
4367 + {
4368 + "description": "bad code string length: eats terminator",
4369 + "bson": "100000000D6100050000006200620000"
4370 + },
4371 + {
4372 + "description": "bad code string length: longer than rest of document",
4373 + "bson": "120000000D00FFFFFF00666F6F6261720000"
4374 + },
4375 + {
4376 + "description": "code string is not null-terminated",
4377 + "bson": "100000000D610004000000616263FF00"
4378 + },
4379 + {
4380 + "description": "empty code string, but extra null",
4381 + "bson": "0E0000000D610001000000000000"
4382 + },
4383 + {
4384 + "description": "invalid UTF-8",
4385 + "bson": "0E0000000D610002000000E90000"
4386 + }
4387 + ]
4388 +}
4389 diff --git a/src/tests/spec/json/bson-corpus/code_w_scope.json b/src/tests/spec/json/bson-corpus/code_w_scope.json
4390 new file mode 100644
4391 index 0000000..f956bcd
4392 --- /dev/null
4393 +++ b/src/tests/spec/json/bson-corpus/code_w_scope.json
4394 @@ -0,0 +1,78 @@
4395 +{
4396 + "description": "Javascript Code with Scope",
4397 + "bson_type": "0x0F",
4398 + "test_key": "a",
4399 + "valid": [
4400 + {
4401 + "description": "Empty code string, empty scope",
4402 + "canonical_bson": "160000000F61000E0000000100000000050000000000",
4403 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {}}}"
4404 + },
4405 + {
4406 + "description": "Non-empty code string, empty scope",
4407 + "canonical_bson": "1A0000000F610012000000050000006162636400050000000000",
4408 + "canonical_extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {}}}"
4409 + },
4410 + {
4411 + "description": "Empty code string, non-empty scope",
4412 + "canonical_bson": "1D0000000F61001500000001000000000C000000107800010000000000",
4413 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {\"x\" : {\"$numberInt\": \"1\"}}}}"
4414 + },
4415 + {
4416 + "description": "Non-empty code string and non-empty scope",
4417 + "canonical_bson": "210000000F6100190000000500000061626364000C000000107800010000000000",
4418 + "canonical_extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {\"x\" : {\"$numberInt\": \"1\"}}}}"
4419 + },
4420 + {
4421 + "description": "Unicode and embedded null in code string, empty scope",
4422 + "canonical_bson": "1A0000000F61001200000005000000C3A9006400050000000000",
4423 + "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u0000d\", \"$scope\" : {}}}"
4424 + }
4425 + ],
4426 + "decodeErrors": [
4427 + {
4428 + "description": "field length zero",
4429 + "bson": "280000000F6100000000000500000061626364001300000010780001000000107900010000000000"
4430 + },
4431 + {
4432 + "description": "field length negative",
4433 + "bson": "280000000F6100FFFFFFFF0500000061626364001300000010780001000000107900010000000000"
4434 + },
4435 + {
4436 + "description": "field length too short (less than minimum size)",
4437 + "bson": "160000000F61000D0000000100000000050000000000"
4438 + },
4439 + {
4440 + "description": "field length too short (truncates scope)",
4441 + "bson": "280000000F61001F0000000500000061626364001300000010780001000000107900010000000000"
4442 + },
4443 + {
4444 + "description": "field length too long (clips outer doc)",
4445 + "bson": "280000000F6100210000000500000061626364001300000010780001000000107900010000000000"
4446 + },
4447 + {
4448 + "description": "field length too long (longer than outer doc)",
4449 + "bson": "280000000F6100FF0000000500000061626364001300000010780001000000107900010000000000"
4450 + },
4451 + {
4452 + "description": "bad code string: length too short",
4453 + "bson": "280000000F6100200000000400000061626364001300000010780001000000107900010000000000"
4454 + },
4455 + {
4456 + "description": "bad code string: length too long (clips scope)",
4457 + "bson": "280000000F6100200000000600000061626364001300000010780001000000107900010000000000"
4458 + },
4459 + {
4460 + "description": "bad code string: negative length",
4461 + "bson": "280000000F610020000000FFFFFFFF61626364001300000010780001000000107900010000000000"
4462 + },
4463 + {
4464 + "description": "bad code string: length longer than field",
4465 + "bson": "280000000F610020000000FF00000061626364001300000010780001000000107900010000000000"
4466 + },
4467 + {
4468 + "description": "bad scope doc (field has bad string length)",
4469 + "bson": "1C0000000F001500000001000000000C000000020000000000000000"
4470 + }
4471 + ]
4472 +}
4473 diff --git a/src/tests/spec/json/bson-corpus/datetime.json b/src/tests/spec/json/bson-corpus/datetime.json
4474 new file mode 100644
4475 index 0000000..f857afd
4476 --- /dev/null
4477 +++ b/src/tests/spec/json/bson-corpus/datetime.json
4478 @@ -0,0 +1,42 @@
4479 +{
4480 + "description": "DateTime",
4481 + "bson_type": "0x09",
4482 + "test_key": "a",
4483 + "valid": [
4484 + {
4485 + "description": "epoch",
4486 + "canonical_bson": "10000000096100000000000000000000",
4487 + "relaxed_extjson": "{\"a\" : {\"$date\" : \"1970-01-01T00:00:00Z\"}}",
4488 + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"0\"}}}"
4489 + },
4490 + {
4491 + "description": "positive ms",
4492 + "canonical_bson": "10000000096100C5D8D6CC3B01000000",
4493 + "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.501Z\"}}",
4494 + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}}}"
4495 + },
4496 + {
4497 + "description": "negative",
4498 + "canonical_bson": "10000000096100C33CE7B9BDFFFFFF00",
4499 + "relaxed_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"-284643869501\"}}}",
4500 + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"-284643869501\"}}}"
4501 + },
4502 + {
4503 + "description" : "Y10K",
4504 + "canonical_bson" : "1000000009610000DC1FD277E6000000",
4505 + "canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}"
4506 + },
4507 + {
4508 + "description": "leading zero ms",
4509 + "canonical_bson": "10000000096100D1D6D6CC3B01000000",
4510 + "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}",
4511 + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}"
4512 + }
4513 + ],
4514 + "decodeErrors": [
4515 + {
4516 + "description": "datetime field truncated",
4517 + "bson": "0C0000000961001234567800"
4518 + }
4519 + ]
4520 +}
4521 diff --git a/src/tests/spec/json/bson-corpus/dbpointer.json b/src/tests/spec/json/bson-corpus/dbpointer.json
4522 new file mode 100644
4523 index 0000000..377e556
4524 --- /dev/null
4525 +++ b/src/tests/spec/json/bson-corpus/dbpointer.json
4526 @@ -0,0 +1,56 @@
4527 +{
4528 + "description": "DBPointer type (deprecated)",
4529 + "bson_type": "0x0C",
4530 + "deprecated": true,
4531 + "test_key": "a",
4532 + "valid": [
4533 + {
4534 + "description": "DBpointer",
4535 + "canonical_bson": "1A0000000C610002000000620056E1FC72E0C917E9C471416100",
4536 + "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
4537 + "converted_bson": "2a00000003610022000000022472656600020000006200072469640056e1fc72e0c917e9c47141610000",
4538 + "converted_extjson": "{\"a\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
4539 + },
4540 + {
4541 + "description": "DBpointer with opposite key order",
4542 + "canonical_bson": "1A0000000C610002000000620056E1FC72E0C917E9C471416100",
4543 + "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
4544 + "degenerate_extjson": "{\"a\": {\"$dbPointer\": {\"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"$ref\": \"b\"}}}",
4545 + "converted_bson": "2a00000003610022000000022472656600020000006200072469640056e1fc72e0c917e9c47141610000",
4546 + "converted_extjson": "{\"a\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
4547 + },
4548 + {
4549 + "description": "With two-byte UTF-8",
4550 + "canonical_bson": "1B0000000C610003000000C3A90056E1FC72E0C917E9C471416100",
4551 + "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"é\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
4552 + "converted_bson": "2B0000000361002300000002247265660003000000C3A900072469640056E1FC72E0C917E9C47141610000",
4553 + "converted_extjson": "{\"a\": {\"$ref\": \"é\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
4554 + }
4555 + ],
4556 + "decodeErrors": [
4557 + {
4558 + "description": "String with negative length",
4559 + "bson": "1A0000000C6100FFFFFFFF620056E1FC72E0C917E9C471416100"
4560 + },
4561 + {
4562 + "description": "String with zero length",
4563 + "bson": "1A0000000C610000000000620056E1FC72E0C917E9C471416100"
4564 + },
4565 + {
4566 + "description": "String not null terminated",
4567 + "bson": "1A0000000C610002000000626256E1FC72E0C917E9C471416100"
4568 + },
4569 + {
4570 + "description": "short OID (less than minimum length for field)",
4571 + "bson": "160000000C61000300000061620056E1FC72E0C91700"
4572 + },
4573 + {
4574 + "description": "short OID (greater than minimum, but truncated)",
4575 + "bson": "1A0000000C61000300000061620056E1FC72E0C917E9C4716100"
4576 + },
4577 + {
4578 + "description": "String with bad UTF-8",
4579 + "bson": "1A0000000C610002000000E90056E1FC72E0C917E9C471416100"
4580 + }
4581 + ]
4582 +}
4583 diff --git a/src/tests/spec/json/bson-corpus/dbref.json b/src/tests/spec/json/bson-corpus/dbref.json
4584 new file mode 100644
4585 index 0000000..41c0b09
4586 --- /dev/null
4587 +++ b/src/tests/spec/json/bson-corpus/dbref.json
4588 @@ -0,0 +1,51 @@
4589 +{
4590 + "description": "Document type (DBRef sub-documents)",
4591 + "bson_type": "0x03",
4592 + "valid": [
4593 + {
4594 + "description": "DBRef",
4595 + "canonical_bson": "37000000036462726566002b0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0000",
4596 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
4597 + },
4598 + {
4599 + "description": "DBRef with database",
4600 + "canonical_bson": "4300000003646272656600370000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0224646200030000006462000000",
4601 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": \"db\"}}"
4602 + },
4603 + {
4604 + "description": "DBRef with database and additional fields",
4605 + "canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e0010246964002a00000002246462000300000064620002666f6f0004000000626172000000",
4606 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$numberInt\": \"42\"}, \"$db\": \"db\", \"foo\": \"bar\"}}"
4607 + },
4608 + {
4609 + "description": "DBRef with additional fields",
4610 + "canonical_bson": "4400000003646272656600380000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e02666f6f0004000000626172000000",
4611 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"foo\": \"bar\"}}"
4612 + },
4613 + {
4614 + "description": "Document with key names similar to those of a DBRef",
4615 + "canonical_bson": "3e0000000224726566000c0000006e6f742d612d646272656600072469640058921b3e6e32ab156a22b59e022462616e616e6100050000007065656c0000",
4616 + "canonical_extjson": "{\"$ref\": \"not-a-dbref\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$banana\": \"peel\"}"
4617 + },
4618 + {
4619 + "description": "DBRef with additional dollar-prefixed and dotted fields",
4620 + "canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000",
4621 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"a.b\": {\"$numberInt\": \"1\"}, \"$c\": {\"$numberInt\": \"1\"}}}"
4622 + },
4623 + {
4624 + "description": "Sub-document resembles DBRef but $id is missing",
4625 + "canonical_bson": "26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000",
4626 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\"}}"
4627 + },
4628 + {
4629 + "description": "Sub-document resembles DBRef but $ref is not a string",
4630 + "canonical_bson": "2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000",
4631 + "canonical_extjson": "{\"dbref\": {\"$ref\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
4632 + },
4633 + {
4634 + "description": "Sub-document resembles DBRef but $db is not a string",
4635 + "canonical_bson": "4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000",
4636 + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": {\"$numberInt\": \"1\"}}}"
4637 + }
4638 + ]
4639 +}
4640 diff --git a/src/tests/spec/json/bson-corpus/decimal128-1.json b/src/tests/spec/json/bson-corpus/decimal128-1.json
4641 new file mode 100644
4642 index 0000000..7eefec6
4643 --- /dev/null
4644 +++ b/src/tests/spec/json/bson-corpus/decimal128-1.json
4645 @@ -0,0 +1,317 @@
4646 +{
4647 + "description": "Decimal128",
4648 + "bson_type": "0x13",
4649 + "test_key": "d",
4650 + "valid": [
4651 + {
4652 + "description": "Special - Canonical NaN",
4653 + "canonical_bson": "180000001364000000000000000000000000000000007C00",
4654 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}"
4655 + },
4656 + {
4657 + "description": "Special - Negative NaN",
4658 + "canonical_bson": "18000000136400000000000000000000000000000000FC00",
4659 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}",
4660 + "lossy": true
4661 + },
4662 + {
4663 + "description": "Special - Negative NaN",
4664 + "canonical_bson": "18000000136400000000000000000000000000000000FC00",
4665 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}",
4666 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-NaN\"}}",
4667 + "lossy": true
4668 + },
4669 + {
4670 + "description": "Special - Canonical SNaN",
4671 + "canonical_bson": "180000001364000000000000000000000000000000007E00",
4672 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}",
4673 + "lossy": true
4674 + },
4675 + {
4676 + "description": "Special - Negative SNaN",
4677 + "canonical_bson": "18000000136400000000000000000000000000000000FE00",
4678 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}",
4679 + "lossy": true
4680 + },
4681 + {
4682 + "description": "Special - NaN with a payload",
4683 + "canonical_bson": "180000001364001200000000000000000000000000007E00",
4684 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}",
4685 + "lossy": true
4686 + },
4687 + {
4688 + "description": "Special - Canonical Positive Infinity",
4689 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4690 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4691 + },
4692 + {
4693 + "description": "Special - Canonical Negative Infinity",
4694 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4695 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4696 + },
4697 + {
4698 + "description": "Special - Invalid representation treated as 0",
4699 + "canonical_bson": "180000001364000000000000000000000000000000106C00",
4700 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}",
4701 + "lossy": true
4702 + },
4703 + {
4704 + "description": "Special - Invalid representation treated as -0",
4705 + "canonical_bson": "18000000136400DCBA9876543210DEADBEEF00000010EC00",
4706 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}",
4707 + "lossy": true
4708 + },
4709 + {
4710 + "description": "Special - Invalid representation treated as 0E3",
4711 + "canonical_bson": "18000000136400FFFFFFFFFFFFFFFFFFFFFFFFFFFF116C00",
4712 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+3\"}}",
4713 + "lossy": true
4714 + },
4715 + {
4716 + "description": "Regular - Adjusted Exponent Limit",
4717 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3CF22F00",
4718 + "canonical_extjson": "{\"d\": { \"$numberDecimal\": \"0.000001234567890123456789012345678901234\" }}"
4719 + },
4720 + {
4721 + "description": "Regular - Smallest",
4722 + "canonical_bson": "18000000136400D204000000000000000000000000343000",
4723 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.001234\"}}"
4724 + },
4725 + {
4726 + "description": "Regular - Smallest with Trailing Zeros",
4727 + "canonical_bson": "1800000013640040EF5A07000000000000000000002A3000",
4728 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00123400000\"}}"
4729 + },
4730 + {
4731 + "description": "Regular - 0.1",
4732 + "canonical_bson": "1800000013640001000000000000000000000000003E3000",
4733 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1\"}}"
4734 + },
4735 + {
4736 + "description": "Regular - 0.1234567890123456789012345678901234",
4737 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3CFC2F00",
4738 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1234567890123456789012345678901234\"}}"
4739 + },
4740 + {
4741 + "description": "Regular - 0",
4742 + "canonical_bson": "180000001364000000000000000000000000000000403000",
4743 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
4744 + },
4745 + {
4746 + "description": "Regular - -0",
4747 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
4748 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
4749 + },
4750 + {
4751 + "description": "Regular - -0.0",
4752 + "canonical_bson": "1800000013640000000000000000000000000000003EB000",
4753 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}"
4754 + },
4755 + {
4756 + "description": "Regular - 2",
4757 + "canonical_bson": "180000001364000200000000000000000000000000403000",
4758 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2\"}}"
4759 + },
4760 + {
4761 + "description": "Regular - 2.000",
4762 + "canonical_bson": "18000000136400D0070000000000000000000000003A3000",
4763 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2.000\"}}"
4764 + },
4765 + {
4766 + "description": "Regular - Largest",
4767 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3C403000",
4768 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1234567890123456789012345678901234\"}}"
4769 + },
4770 + {
4771 + "description": "Scientific - Tiniest",
4772 + "canonical_bson": "18000000136400FFFFFFFF638E8D37C087ADBE09ED010000",
4773 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9.999999999999999999999999999999999E-6143\"}}"
4774 + },
4775 + {
4776 + "description": "Scientific - Tiny",
4777 + "canonical_bson": "180000001364000100000000000000000000000000000000",
4778 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6176\"}}"
4779 + },
4780 + {
4781 + "description": "Scientific - Negative Tiny",
4782 + "canonical_bson": "180000001364000100000000000000000000000000008000",
4783 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6176\"}}"
4784 + },
4785 + {
4786 + "description": "Scientific - Adjusted Exponent Limit",
4787 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3CF02F00",
4788 + "canonical_extjson": "{\"d\": { \"$numberDecimal\": \"1.234567890123456789012345678901234E-7\" }}"
4789 + },
4790 + {
4791 + "description": "Scientific - Fractional",
4792 + "canonical_bson": "1800000013640064000000000000000000000000002CB000",
4793 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.00E-8\"}}"
4794 + },
4795 + {
4796 + "description": "Scientific - 0 with Exponent",
4797 + "canonical_bson": "180000001364000000000000000000000000000000205F00",
4798 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6000\"}}"
4799 + },
4800 + {
4801 + "description": "Scientific - 0 with Negative Exponent",
4802 + "canonical_bson": "1800000013640000000000000000000000000000007A2B00",
4803 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-611\"}}"
4804 + },
4805 + {
4806 + "description": "Scientific - No Decimal with Signed Exponent",
4807 + "canonical_bson": "180000001364000100000000000000000000000000463000",
4808 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+3\"}}"
4809 + },
4810 + {
4811 + "description": "Scientific - Trailing Zero",
4812 + "canonical_bson": "180000001364001A04000000000000000000000000423000",
4813 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.050E+4\"}}"
4814 + },
4815 + {
4816 + "description": "Scientific - With Decimal",
4817 + "canonical_bson": "180000001364006900000000000000000000000000423000",
4818 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.05E+3\"}}"
4819 + },
4820 + {
4821 + "description": "Scientific - Full",
4822 + "canonical_bson": "18000000136400FFFFFFFFFFFFFFFFFFFFFFFFFFFF403000",
4823 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5192296858534827628530496329220095\"}}"
4824 + },
4825 + {
4826 + "description": "Scientific - Large",
4827 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FE5F00",
4828 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+6144\"}}"
4829 + },
4830 + {
4831 + "description": "Scientific - Largest",
4832 + "canonical_bson": "18000000136400FFFFFFFF638E8D37C087ADBE09EDFF5F00",
4833 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9.999999999999999999999999999999999E+6144\"}}"
4834 + },
4835 + {
4836 + "description": "Non-Canonical Parsing - Exponent Normalization",
4837 + "canonical_bson": "1800000013640064000000000000000000000000002CB000",
4838 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-100E-10\"}}",
4839 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.00E-8\"}}"
4840 + },
4841 + {
4842 + "description": "Non-Canonical Parsing - Unsigned Positive Exponent",
4843 + "canonical_bson": "180000001364000100000000000000000000000000463000",
4844 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E3\"}}",
4845 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+3\"}}"
4846 + },
4847 + {
4848 + "description": "Non-Canonical Parsing - Lowercase Exponent Identifier",
4849 + "canonical_bson": "180000001364000100000000000000000000000000463000",
4850 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1e+3\"}}",
4851 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+3\"}}"
4852 + },
4853 + {
4854 + "description": "Non-Canonical Parsing - Long Significand with Exponent",
4855 + "canonical_bson": "1800000013640079D9E0F9763ADA429D0200000000583000",
4856 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12345689012345789012345E+12\"}}",
4857 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.2345689012345789012345E+34\"}}"
4858 + },
4859 + {
4860 + "description": "Non-Canonical Parsing - Positive Sign",
4861 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3C403000",
4862 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+1234567890123456789012345678901234\"}}",
4863 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1234567890123456789012345678901234\"}}"
4864 + },
4865 + {
4866 + "description": "Non-Canonical Parsing - Long Decimal String",
4867 + "canonical_bson": "180000001364000100000000000000000000000000722800",
4868 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\"}}",
4869 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-999\"}}"
4870 + },
4871 + {
4872 + "description": "Non-Canonical Parsing - nan",
4873 + "canonical_bson": "180000001364000000000000000000000000000000007C00",
4874 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"nan\"}}",
4875 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}"
4876 + },
4877 + {
4878 + "description": "Non-Canonical Parsing - nAn",
4879 + "canonical_bson": "180000001364000000000000000000000000000000007C00",
4880 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"nAn\"}}",
4881 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}"
4882 + },
4883 + {
4884 + "description": "Non-Canonical Parsing - +infinity",
4885 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4886 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+infinity\"}}",
4887 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4888 + },
4889 + {
4890 + "description": "Non-Canonical Parsing - infinity",
4891 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4892 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"infinity\"}}",
4893 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4894 + },
4895 + {
4896 + "description": "Non-Canonical Parsing - infiniTY",
4897 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4898 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"infiniTY\"}}",
4899 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4900 + },
4901 + {
4902 + "description": "Non-Canonical Parsing - inf",
4903 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4904 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"inf\"}}",
4905 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4906 + },
4907 + {
4908 + "description": "Non-Canonical Parsing - inF",
4909 + "canonical_bson": "180000001364000000000000000000000000000000007800",
4910 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"inF\"}}",
4911 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
4912 + },
4913 + {
4914 + "description": "Non-Canonical Parsing - -infinity",
4915 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4916 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-infinity\"}}",
4917 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4918 + },
4919 + {
4920 + "description": "Non-Canonical Parsing - -infiniTy",
4921 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4922 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-infiniTy\"}}",
4923 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4924 + },
4925 + {
4926 + "description": "Non-Canonical Parsing - -Inf",
4927 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4928 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}",
4929 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4930 + },
4931 + {
4932 + "description": "Non-Canonical Parsing - -inf",
4933 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4934 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-inf\"}}",
4935 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4936 + },
4937 + {
4938 + "description": "Non-Canonical Parsing - -inF",
4939 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
4940 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-inF\"}}",
4941 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
4942 + },
4943 + {
4944 + "description": "Rounded Subnormal number",
4945 + "canonical_bson": "180000001364000100000000000000000000000000000000",
4946 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10E-6177\"}}",
4947 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6176\"}}"
4948 + },
4949 + {
4950 + "description": "Clamped",
4951 + "canonical_bson": "180000001364000a00000000000000000000000000fe5f00",
4952 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E6112\"}}",
4953 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6112\"}}"
4954 + },
4955 + {
4956 + "description": "Exact rounding",
4957 + "canonical_bson": "18000000136400000000000a5bc138938d44c64d31cc3700",
4958 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}}",
4959 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+999\"}}"
4960 + }
4961 + ]
4962 +}
4963 diff --git a/src/tests/spec/json/bson-corpus/decimal128-2.json b/src/tests/spec/json/bson-corpus/decimal128-2.json
4964 new file mode 100644
4965 index 0000000..316d3b0
4966 --- /dev/null
4967 +++ b/src/tests/spec/json/bson-corpus/decimal128-2.json
4968 @@ -0,0 +1,793 @@
4969 +{
4970 + "description": "Decimal128",
4971 + "bson_type": "0x13",
4972 + "test_key": "d",
4973 + "valid": [
4974 + {
4975 + "description": "[decq021] Normality",
4976 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3C40B000",
4977 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1234567890123456789012345678901234\"}}"
4978 + },
4979 + {
4980 + "description": "[decq823] values around [u]int32 edges (zeros done earlier)",
4981 + "canonical_bson": "18000000136400010000800000000000000000000040B000",
4982 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-2147483649\"}}"
4983 + },
4984 + {
4985 + "description": "[decq822] values around [u]int32 edges (zeros done earlier)",
4986 + "canonical_bson": "18000000136400000000800000000000000000000040B000",
4987 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-2147483648\"}}"
4988 + },
4989 + {
4990 + "description": "[decq821] values around [u]int32 edges (zeros done earlier)",
4991 + "canonical_bson": "18000000136400FFFFFF7F0000000000000000000040B000",
4992 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-2147483647\"}}"
4993 + },
4994 + {
4995 + "description": "[decq820] values around [u]int32 edges (zeros done earlier)",
4996 + "canonical_bson": "18000000136400FEFFFF7F0000000000000000000040B000",
4997 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-2147483646\"}}"
4998 + },
4999 + {
5000 + "description": "[decq152] fold-downs (more below)",
5001 + "canonical_bson": "18000000136400393000000000000000000000000040B000",
5002 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-12345\"}}"
5003 + },
5004 + {
5005 + "description": "[decq154] fold-downs (more below)",
5006 + "canonical_bson": "18000000136400D20400000000000000000000000040B000",
5007 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1234\"}}"
5008 + },
5009 + {
5010 + "description": "[decq006] derivative canonical plain strings",
5011 + "canonical_bson": "18000000136400EE0200000000000000000000000040B000",
5012 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-750\"}}"
5013 + },
5014 + {
5015 + "description": "[decq164] fold-downs (more below)",
5016 + "canonical_bson": "1800000013640039300000000000000000000000003CB000",
5017 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-123.45\"}}"
5018 + },
5019 + {
5020 + "description": "[decq156] fold-downs (more below)",
5021 + "canonical_bson": "180000001364007B0000000000000000000000000040B000",
5022 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-123\"}}"
5023 + },
5024 + {
5025 + "description": "[decq008] derivative canonical plain strings",
5026 + "canonical_bson": "18000000136400EE020000000000000000000000003EB000",
5027 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-75.0\"}}"
5028 + },
5029 + {
5030 + "description": "[decq158] fold-downs (more below)",
5031 + "canonical_bson": "180000001364000C0000000000000000000000000040B000",
5032 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-12\"}}"
5033 + },
5034 + {
5035 + "description": "[decq122] Nmax and similar",
5036 + "canonical_bson": "18000000136400FFFFFFFF638E8D37C087ADBE09EDFFDF00",
5037 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.999999999999999999999999999999999E+6144\"}}"
5038 + },
5039 + {
5040 + "description": "[decq002] (mostly derived from the Strawman 4 document and examples)",
5041 + "canonical_bson": "18000000136400EE020000000000000000000000003CB000",
5042 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-7.50\"}}"
5043 + },
5044 + {
5045 + "description": "[decq004] derivative canonical plain strings",
5046 + "canonical_bson": "18000000136400EE0200000000000000000000000042B000",
5047 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-7.50E+3\"}}"
5048 + },
5049 + {
5050 + "description": "[decq018] derivative canonical plain strings",
5051 + "canonical_bson": "18000000136400EE020000000000000000000000002EB000",
5052 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-7.50E-7\"}}"
5053 + },
5054 + {
5055 + "description": "[decq125] Nmax and similar",
5056 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3CFEDF00",
5057 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.234567890123456789012345678901234E+6144\"}}"
5058 + },
5059 + {
5060 + "description": "[decq131] fold-downs (more below)",
5061 + "canonical_bson": "18000000136400000000807F1BCF85B27059C8A43CFEDF00",
5062 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.230000000000000000000000000000000E+6144\"}}"
5063 + },
5064 + {
5065 + "description": "[decq162] fold-downs (more below)",
5066 + "canonical_bson": "180000001364007B000000000000000000000000003CB000",
5067 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.23\"}}"
5068 + },
5069 + {
5070 + "description": "[decq176] Nmin and below",
5071 + "canonical_bson": "18000000136400010000000A5BC138938D44C64D31008000",
5072 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.000000000000000000000000000000001E-6143\"}}"
5073 + },
5074 + {
5075 + "description": "[decq174] Nmin and below",
5076 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31008000",
5077 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.000000000000000000000000000000000E-6143\"}}"
5078 + },
5079 + {
5080 + "description": "[decq133] fold-downs (more below)",
5081 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FEDF00",
5082 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.000000000000000000000000000000000E+6144\"}}"
5083 + },
5084 + {
5085 + "description": "[decq160] fold-downs (more below)",
5086 + "canonical_bson": "18000000136400010000000000000000000000000040B000",
5087 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1\"}}"
5088 + },
5089 + {
5090 + "description": "[decq172] Nmin and below",
5091 + "canonical_bson": "180000001364000100000000000000000000000000428000",
5092 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6143\"}}"
5093 + },
5094 + {
5095 + "description": "[decq010] derivative canonical plain strings",
5096 + "canonical_bson": "18000000136400EE020000000000000000000000003AB000",
5097 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.750\"}}"
5098 + },
5099 + {
5100 + "description": "[decq012] derivative canonical plain strings",
5101 + "canonical_bson": "18000000136400EE0200000000000000000000000038B000",
5102 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0750\"}}"
5103 + },
5104 + {
5105 + "description": "[decq014] derivative canonical plain strings",
5106 + "canonical_bson": "18000000136400EE0200000000000000000000000034B000",
5107 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000750\"}}"
5108 + },
5109 + {
5110 + "description": "[decq016] derivative canonical plain strings",
5111 + "canonical_bson": "18000000136400EE0200000000000000000000000030B000",
5112 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000750\"}}"
5113 + },
5114 + {
5115 + "description": "[decq404] zeros",
5116 + "canonical_bson": "180000001364000000000000000000000000000000000000",
5117 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}"
5118 + },
5119 + {
5120 + "description": "[decq424] negative zeros",
5121 + "canonical_bson": "180000001364000000000000000000000000000000008000",
5122 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}"
5123 + },
5124 + {
5125 + "description": "[decq407] zeros",
5126 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
5127 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
5128 + },
5129 + {
5130 + "description": "[decq427] negative zeros",
5131 + "canonical_bson": "1800000013640000000000000000000000000000003CB000",
5132 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00\"}}"
5133 + },
5134 + {
5135 + "description": "[decq409] zeros",
5136 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5137 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5138 + },
5139 + {
5140 + "description": "[decq428] negative zeros",
5141 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
5142 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
5143 + },
5144 + {
5145 + "description": "[decq700] Selected DPD codes",
5146 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5147 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5148 + },
5149 + {
5150 + "description": "[decq406] zeros",
5151 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
5152 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
5153 + },
5154 + {
5155 + "description": "[decq426] negative zeros",
5156 + "canonical_bson": "1800000013640000000000000000000000000000003CB000",
5157 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00\"}}"
5158 + },
5159 + {
5160 + "description": "[decq410] zeros",
5161 + "canonical_bson": "180000001364000000000000000000000000000000463000",
5162 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+3\"}}"
5163 + },
5164 + {
5165 + "description": "[decq431] negative zeros",
5166 + "canonical_bson": "18000000136400000000000000000000000000000046B000",
5167 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+3\"}}"
5168 + },
5169 + {
5170 + "description": "[decq419] clamped zeros...",
5171 + "canonical_bson": "180000001364000000000000000000000000000000FE5F00",
5172 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}"
5173 + },
5174 + {
5175 + "description": "[decq432] negative zeros",
5176 + "canonical_bson": "180000001364000000000000000000000000000000FEDF00",
5177 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}"
5178 + },
5179 + {
5180 + "description": "[decq405] zeros",
5181 + "canonical_bson": "180000001364000000000000000000000000000000000000",
5182 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}"
5183 + },
5184 + {
5185 + "description": "[decq425] negative zeros",
5186 + "canonical_bson": "180000001364000000000000000000000000000000008000",
5187 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}"
5188 + },
5189 + {
5190 + "description": "[decq508] Specials",
5191 + "canonical_bson": "180000001364000000000000000000000000000000007800",
5192 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"Infinity\"}}"
5193 + },
5194 + {
5195 + "description": "[decq528] Specials",
5196 + "canonical_bson": "18000000136400000000000000000000000000000000F800",
5197 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-Infinity\"}}"
5198 + },
5199 + {
5200 + "description": "[decq541] Specials",
5201 + "canonical_bson": "180000001364000000000000000000000000000000007C00",
5202 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"NaN\"}}"
5203 + },
5204 + {
5205 + "description": "[decq074] Nmin and below",
5206 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31000000",
5207 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E-6143\"}}"
5208 + },
5209 + {
5210 + "description": "[decq602] fold-down full sequence",
5211 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FE5F00",
5212 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+6144\"}}"
5213 + },
5214 + {
5215 + "description": "[decq604] fold-down full sequence",
5216 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04FE5F00",
5217 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000000E+6143\"}}"
5218 + },
5219 + {
5220 + "description": "[decq606] fold-down full sequence",
5221 + "canonical_bson": "1800000013640000000080264B91C02220BE377E00FE5F00",
5222 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000000000E+6142\"}}"
5223 + },
5224 + {
5225 + "description": "[decq608] fold-down full sequence",
5226 + "canonical_bson": "1800000013640000000040EAED7446D09C2C9F0C00FE5F00",
5227 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000E+6141\"}}"
5228 + },
5229 + {
5230 + "description": "[decq610] fold-down full sequence",
5231 + "canonical_bson": "18000000136400000000A0CA17726DAE0F1E430100FE5F00",
5232 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000E+6140\"}}"
5233 + },
5234 + {
5235 + "description": "[decq612] fold-down full sequence",
5236 + "canonical_bson": "18000000136400000000106102253E5ECE4F200000FE5F00",
5237 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000000E+6139\"}}"
5238 + },
5239 + {
5240 + "description": "[decq614] fold-down full sequence",
5241 + "canonical_bson": "18000000136400000000E83C80D09F3C2E3B030000FE5F00",
5242 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000E+6138\"}}"
5243 + },
5244 + {
5245 + "description": "[decq616] fold-down full sequence",
5246 + "canonical_bson": "18000000136400000000E4D20CC8DCD2B752000000FE5F00",
5247 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000E+6137\"}}"
5248 + },
5249 + {
5250 + "description": "[decq618] fold-down full sequence",
5251 + "canonical_bson": "180000001364000000004A48011416954508000000FE5F00",
5252 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000E+6136\"}}"
5253 + },
5254 + {
5255 + "description": "[decq620] fold-down full sequence",
5256 + "canonical_bson": "18000000136400000000A1EDCCCE1BC2D300000000FE5F00",
5257 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000E+6135\"}}"
5258 + },
5259 + {
5260 + "description": "[decq622] fold-down full sequence",
5261 + "canonical_bson": "18000000136400000080F64AE1C7022D1500000000FE5F00",
5262 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000E+6134\"}}"
5263 + },
5264 + {
5265 + "description": "[decq624] fold-down full sequence",
5266 + "canonical_bson": "18000000136400000040B2BAC9E0191E0200000000FE5F00",
5267 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000E+6133\"}}"
5268 + },
5269 + {
5270 + "description": "[decq626] fold-down full sequence",
5271 + "canonical_bson": "180000001364000000A0DEC5ADC935360000000000FE5F00",
5272 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000E+6132\"}}"
5273 + },
5274 + {
5275 + "description": "[decq628] fold-down full sequence",
5276 + "canonical_bson": "18000000136400000010632D5EC76B050000000000FE5F00",
5277 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000E+6131\"}}"
5278 + },
5279 + {
5280 + "description": "[decq630] fold-down full sequence",
5281 + "canonical_bson": "180000001364000000E8890423C78A000000000000FE5F00",
5282 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000E+6130\"}}"
5283 + },
5284 + {
5285 + "description": "[decq632] fold-down full sequence",
5286 + "canonical_bson": "18000000136400000064A7B3B6E00D000000000000FE5F00",
5287 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000E+6129\"}}"
5288 + },
5289 + {
5290 + "description": "[decq634] fold-down full sequence",
5291 + "canonical_bson": "1800000013640000008A5D78456301000000000000FE5F00",
5292 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000E+6128\"}}"
5293 + },
5294 + {
5295 + "description": "[decq636] fold-down full sequence",
5296 + "canonical_bson": "180000001364000000C16FF2862300000000000000FE5F00",
5297 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000E+6127\"}}"
5298 + },
5299 + {
5300 + "description": "[decq638] fold-down full sequence",
5301 + "canonical_bson": "180000001364000080C6A47E8D0300000000000000FE5F00",
5302 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000E+6126\"}}"
5303 + },
5304 + {
5305 + "description": "[decq640] fold-down full sequence",
5306 + "canonical_bson": "1800000013640000407A10F35A0000000000000000FE5F00",
5307 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000E+6125\"}}"
5308 + },
5309 + {
5310 + "description": "[decq642] fold-down full sequence",
5311 + "canonical_bson": "1800000013640000A0724E18090000000000000000FE5F00",
5312 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000E+6124\"}}"
5313 + },
5314 + {
5315 + "description": "[decq644] fold-down full sequence",
5316 + "canonical_bson": "180000001364000010A5D4E8000000000000000000FE5F00",
5317 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000E+6123\"}}"
5318 + },
5319 + {
5320 + "description": "[decq646] fold-down full sequence",
5321 + "canonical_bson": "1800000013640000E8764817000000000000000000FE5F00",
5322 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000E+6122\"}}"
5323 + },
5324 + {
5325 + "description": "[decq648] fold-down full sequence",
5326 + "canonical_bson": "1800000013640000E40B5402000000000000000000FE5F00",
5327 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000E+6121\"}}"
5328 + },
5329 + {
5330 + "description": "[decq650] fold-down full sequence",
5331 + "canonical_bson": "1800000013640000CA9A3B00000000000000000000FE5F00",
5332 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000E+6120\"}}"
5333 + },
5334 + {
5335 + "description": "[decq652] fold-down full sequence",
5336 + "canonical_bson": "1800000013640000E1F50500000000000000000000FE5F00",
5337 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000E+6119\"}}"
5338 + },
5339 + {
5340 + "description": "[decq654] fold-down full sequence",
5341 + "canonical_bson": "180000001364008096980000000000000000000000FE5F00",
5342 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000E+6118\"}}"
5343 + },
5344 + {
5345 + "description": "[decq656] fold-down full sequence",
5346 + "canonical_bson": "1800000013640040420F0000000000000000000000FE5F00",
5347 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000E+6117\"}}"
5348 + },
5349 + {
5350 + "description": "[decq658] fold-down full sequence",
5351 + "canonical_bson": "18000000136400A086010000000000000000000000FE5F00",
5352 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000E+6116\"}}"
5353 + },
5354 + {
5355 + "description": "[decq660] fold-down full sequence",
5356 + "canonical_bson": "180000001364001027000000000000000000000000FE5F00",
5357 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000E+6115\"}}"
5358 + },
5359 + {
5360 + "description": "[decq662] fold-down full sequence",
5361 + "canonical_bson": "18000000136400E803000000000000000000000000FE5F00",
5362 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000E+6114\"}}"
5363 + },
5364 + {
5365 + "description": "[decq664] fold-down full sequence",
5366 + "canonical_bson": "180000001364006400000000000000000000000000FE5F00",
5367 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+6113\"}}"
5368 + },
5369 + {
5370 + "description": "[decq666] fold-down full sequence",
5371 + "canonical_bson": "180000001364000A00000000000000000000000000FE5F00",
5372 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6112\"}}"
5373 + },
5374 + {
5375 + "description": "[decq060] fold-downs (more below)",
5376 + "canonical_bson": "180000001364000100000000000000000000000000403000",
5377 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1\"}}"
5378 + },
5379 + {
5380 + "description": "[decq670] fold-down full sequence",
5381 + "canonical_bson": "180000001364000100000000000000000000000000FC5F00",
5382 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6110\"}}"
5383 + },
5384 + {
5385 + "description": "[decq668] fold-down full sequence",
5386 + "canonical_bson": "180000001364000100000000000000000000000000FE5F00",
5387 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6111\"}}"
5388 + },
5389 + {
5390 + "description": "[decq072] Nmin and below",
5391 + "canonical_bson": "180000001364000100000000000000000000000000420000",
5392 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6143\"}}"
5393 + },
5394 + {
5395 + "description": "[decq076] Nmin and below",
5396 + "canonical_bson": "18000000136400010000000A5BC138938D44C64D31000000",
5397 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000001E-6143\"}}"
5398 + },
5399 + {
5400 + "description": "[decq036] fold-downs (more below)",
5401 + "canonical_bson": "18000000136400000000807F1BCF85B27059C8A43CFE5F00",
5402 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.230000000000000000000000000000000E+6144\"}}"
5403 + },
5404 + {
5405 + "description": "[decq062] fold-downs (more below)",
5406 + "canonical_bson": "180000001364007B000000000000000000000000003C3000",
5407 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.23\"}}"
5408 + },
5409 + {
5410 + "description": "[decq034] Nmax and similar",
5411 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3CFE5F00",
5412 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.234567890123456789012345678901234E+6144\"}}"
5413 + },
5414 + {
5415 + "description": "[decq441] exponent lengths",
5416 + "canonical_bson": "180000001364000700000000000000000000000000403000",
5417 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7\"}}"
5418 + },
5419 + {
5420 + "description": "[decq449] exponent lengths",
5421 + "canonical_bson": "1800000013640007000000000000000000000000001E5F00",
5422 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+5999\"}}"
5423 + },
5424 + {
5425 + "description": "[decq447] exponent lengths",
5426 + "canonical_bson": "1800000013640007000000000000000000000000000E3800",
5427 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+999\"}}"
5428 + },
5429 + {
5430 + "description": "[decq445] exponent lengths",
5431 + "canonical_bson": "180000001364000700000000000000000000000000063100",
5432 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+99\"}}"
5433 + },
5434 + {
5435 + "description": "[decq443] exponent lengths",
5436 + "canonical_bson": "180000001364000700000000000000000000000000523000",
5437 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+9\"}}"
5438 + },
5439 + {
5440 + "description": "[decq842] VG testcase",
5441 + "canonical_bson": "180000001364000000FED83F4E7C9FE4E269E38A5BCD1700",
5442 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7.049000000000010795488000000000000E-3097\"}}"
5443 + },
5444 + {
5445 + "description": "[decq841] VG testcase",
5446 + "canonical_bson": "180000001364000000203B9DB5056F000000000000002400",
5447 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"8.000000000000000000E-1550\"}}"
5448 + },
5449 + {
5450 + "description": "[decq840] VG testcase",
5451 + "canonical_bson": "180000001364003C17258419D710C42F0000000000002400",
5452 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"8.81125000000001349436E-1548\"}}"
5453 + },
5454 + {
5455 + "description": "[decq701] Selected DPD codes",
5456 + "canonical_bson": "180000001364000900000000000000000000000000403000",
5457 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9\"}}"
5458 + },
5459 + {
5460 + "description": "[decq032] Nmax and similar",
5461 + "canonical_bson": "18000000136400FFFFFFFF638E8D37C087ADBE09EDFF5F00",
5462 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9.999999999999999999999999999999999E+6144\"}}"
5463 + },
5464 + {
5465 + "description": "[decq702] Selected DPD codes",
5466 + "canonical_bson": "180000001364000A00000000000000000000000000403000",
5467 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10\"}}"
5468 + },
5469 + {
5470 + "description": "[decq057] fold-downs (more below)",
5471 + "canonical_bson": "180000001364000C00000000000000000000000000403000",
5472 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12\"}}"
5473 + },
5474 + {
5475 + "description": "[decq703] Selected DPD codes",
5476 + "canonical_bson": "180000001364001300000000000000000000000000403000",
5477 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"19\"}}"
5478 + },
5479 + {
5480 + "description": "[decq704] Selected DPD codes",
5481 + "canonical_bson": "180000001364001400000000000000000000000000403000",
5482 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"20\"}}"
5483 + },
5484 + {
5485 + "description": "[decq705] Selected DPD codes",
5486 + "canonical_bson": "180000001364001D00000000000000000000000000403000",
5487 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"29\"}}"
5488 + },
5489 + {
5490 + "description": "[decq706] Selected DPD codes",
5491 + "canonical_bson": "180000001364001E00000000000000000000000000403000",
5492 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"30\"}}"
5493 + },
5494 + {
5495 + "description": "[decq707] Selected DPD codes",
5496 + "canonical_bson": "180000001364002700000000000000000000000000403000",
5497 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"39\"}}"
5498 + },
5499 + {
5500 + "description": "[decq708] Selected DPD codes",
5501 + "canonical_bson": "180000001364002800000000000000000000000000403000",
5502 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"40\"}}"
5503 + },
5504 + {
5505 + "description": "[decq709] Selected DPD codes",
5506 + "canonical_bson": "180000001364003100000000000000000000000000403000",
5507 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"49\"}}"
5508 + },
5509 + {
5510 + "description": "[decq710] Selected DPD codes",
5511 + "canonical_bson": "180000001364003200000000000000000000000000403000",
5512 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"50\"}}"
5513 + },
5514 + {
5515 + "description": "[decq711] Selected DPD codes",
5516 + "canonical_bson": "180000001364003B00000000000000000000000000403000",
5517 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"59\"}}"
5518 + },
5519 + {
5520 + "description": "[decq712] Selected DPD codes",
5521 + "canonical_bson": "180000001364003C00000000000000000000000000403000",
5522 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"60\"}}"
5523 + },
5524 + {
5525 + "description": "[decq713] Selected DPD codes",
5526 + "canonical_bson": "180000001364004500000000000000000000000000403000",
5527 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"69\"}}"
5528 + },
5529 + {
5530 + "description": "[decq714] Selected DPD codes",
5531 + "canonical_bson": "180000001364004600000000000000000000000000403000",
5532 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"70\"}}"
5533 + },
5534 + {
5535 + "description": "[decq715] Selected DPD codes",
5536 + "canonical_bson": "180000001364004700000000000000000000000000403000",
5537 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"71\"}}"
5538 + },
5539 + {
5540 + "description": "[decq716] Selected DPD codes",
5541 + "canonical_bson": "180000001364004800000000000000000000000000403000",
5542 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"72\"}}"
5543 + },
5544 + {
5545 + "description": "[decq717] Selected DPD codes",
5546 + "canonical_bson": "180000001364004900000000000000000000000000403000",
5547 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"73\"}}"
5548 + },
5549 + {
5550 + "description": "[decq718] Selected DPD codes",
5551 + "canonical_bson": "180000001364004A00000000000000000000000000403000",
5552 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"74\"}}"
5553 + },
5554 + {
5555 + "description": "[decq719] Selected DPD codes",
5556 + "canonical_bson": "180000001364004B00000000000000000000000000403000",
5557 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"75\"}}"
5558 + },
5559 + {
5560 + "description": "[decq720] Selected DPD codes",
5561 + "canonical_bson": "180000001364004C00000000000000000000000000403000",
5562 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"76\"}}"
5563 + },
5564 + {
5565 + "description": "[decq721] Selected DPD codes",
5566 + "canonical_bson": "180000001364004D00000000000000000000000000403000",
5567 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"77\"}}"
5568 + },
5569 + {
5570 + "description": "[decq722] Selected DPD codes",
5571 + "canonical_bson": "180000001364004E00000000000000000000000000403000",
5572 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"78\"}}"
5573 + },
5574 + {
5575 + "description": "[decq723] Selected DPD codes",
5576 + "canonical_bson": "180000001364004F00000000000000000000000000403000",
5577 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"79\"}}"
5578 + },
5579 + {
5580 + "description": "[decq056] fold-downs (more below)",
5581 + "canonical_bson": "180000001364007B00000000000000000000000000403000",
5582 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"123\"}}"
5583 + },
5584 + {
5585 + "description": "[decq064] fold-downs (more below)",
5586 + "canonical_bson": "1800000013640039300000000000000000000000003C3000",
5587 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"123.45\"}}"
5588 + },
5589 + {
5590 + "description": "[decq732] Selected DPD codes",
5591 + "canonical_bson": "180000001364000802000000000000000000000000403000",
5592 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"520\"}}"
5593 + },
5594 + {
5595 + "description": "[decq733] Selected DPD codes",
5596 + "canonical_bson": "180000001364000902000000000000000000000000403000",
5597 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"521\"}}"
5598 + },
5599 + {
5600 + "description": "[decq740] DPD: one of each of the huffman groups",
5601 + "canonical_bson": "180000001364000903000000000000000000000000403000",
5602 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"777\"}}"
5603 + },
5604 + {
5605 + "description": "[decq741] DPD: one of each of the huffman groups",
5606 + "canonical_bson": "180000001364000A03000000000000000000000000403000",
5607 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"778\"}}"
5608 + },
5609 + {
5610 + "description": "[decq742] DPD: one of each of the huffman groups",
5611 + "canonical_bson": "180000001364001303000000000000000000000000403000",
5612 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"787\"}}"
5613 + },
5614 + {
5615 + "description": "[decq746] DPD: one of each of the huffman groups",
5616 + "canonical_bson": "180000001364001F03000000000000000000000000403000",
5617 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"799\"}}"
5618 + },
5619 + {
5620 + "description": "[decq743] DPD: one of each of the huffman groups",
5621 + "canonical_bson": "180000001364006D03000000000000000000000000403000",
5622 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"877\"}}"
5623 + },
5624 + {
5625 + "description": "[decq753] DPD all-highs cases (includes the 24 redundant codes)",
5626 + "canonical_bson": "180000001364007803000000000000000000000000403000",
5627 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"888\"}}"
5628 + },
5629 + {
5630 + "description": "[decq754] DPD all-highs cases (includes the 24 redundant codes)",
5631 + "canonical_bson": "180000001364007903000000000000000000000000403000",
5632 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"889\"}}"
5633 + },
5634 + {
5635 + "description": "[decq760] DPD all-highs cases (includes the 24 redundant codes)",
5636 + "canonical_bson": "180000001364008203000000000000000000000000403000",
5637 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"898\"}}"
5638 + },
5639 + {
5640 + "description": "[decq764] DPD all-highs cases (includes the 24 redundant codes)",
5641 + "canonical_bson": "180000001364008303000000000000000000000000403000",
5642 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"899\"}}"
5643 + },
5644 + {
5645 + "description": "[decq745] DPD: one of each of the huffman groups",
5646 + "canonical_bson": "18000000136400D303000000000000000000000000403000",
5647 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"979\"}}"
5648 + },
5649 + {
5650 + "description": "[decq770] DPD all-highs cases (includes the 24 redundant codes)",
5651 + "canonical_bson": "18000000136400DC03000000000000000000000000403000",
5652 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"988\"}}"
5653 + },
5654 + {
5655 + "description": "[decq774] DPD all-highs cases (includes the 24 redundant codes)",
5656 + "canonical_bson": "18000000136400DD03000000000000000000000000403000",
5657 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"989\"}}"
5658 + },
5659 + {
5660 + "description": "[decq730] Selected DPD codes",
5661 + "canonical_bson": "18000000136400E203000000000000000000000000403000",
5662 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"994\"}}"
5663 + },
5664 + {
5665 + "description": "[decq731] Selected DPD codes",
5666 + "canonical_bson": "18000000136400E303000000000000000000000000403000",
5667 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"995\"}}"
5668 + },
5669 + {
5670 + "description": "[decq744] DPD: one of each of the huffman groups",
5671 + "canonical_bson": "18000000136400E503000000000000000000000000403000",
5672 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"997\"}}"
5673 + },
5674 + {
5675 + "description": "[decq780] DPD all-highs cases (includes the 24 redundant codes)",
5676 + "canonical_bson": "18000000136400E603000000000000000000000000403000",
5677 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"998\"}}"
5678 + },
5679 + {
5680 + "description": "[decq787] DPD all-highs cases (includes the 24 redundant codes)",
5681 + "canonical_bson": "18000000136400E703000000000000000000000000403000",
5682 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"999\"}}"
5683 + },
5684 + {
5685 + "description": "[decq053] fold-downs (more below)",
5686 + "canonical_bson": "18000000136400D204000000000000000000000000403000",
5687 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1234\"}}"
5688 + },
5689 + {
5690 + "description": "[decq052] fold-downs (more below)",
5691 + "canonical_bson": "180000001364003930000000000000000000000000403000",
5692 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12345\"}}"
5693 + },
5694 + {
5695 + "description": "[decq792] Miscellaneous (testers' queries, etc.)",
5696 + "canonical_bson": "180000001364003075000000000000000000000000403000",
5697 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"30000\"}}"
5698 + },
5699 + {
5700 + "description": "[decq793] Miscellaneous (testers' queries, etc.)",
5701 + "canonical_bson": "1800000013640090940D0000000000000000000000403000",
5702 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"890000\"}}"
5703 + },
5704 + {
5705 + "description": "[decq824] values around [u]int32 edges (zeros done earlier)",
5706 + "canonical_bson": "18000000136400FEFFFF7F00000000000000000000403000",
5707 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2147483646\"}}"
5708 + },
5709 + {
5710 + "description": "[decq825] values around [u]int32 edges (zeros done earlier)",
5711 + "canonical_bson": "18000000136400FFFFFF7F00000000000000000000403000",
5712 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2147483647\"}}"
5713 + },
5714 + {
5715 + "description": "[decq826] values around [u]int32 edges (zeros done earlier)",
5716 + "canonical_bson": "180000001364000000008000000000000000000000403000",
5717 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2147483648\"}}"
5718 + },
5719 + {
5720 + "description": "[decq827] values around [u]int32 edges (zeros done earlier)",
5721 + "canonical_bson": "180000001364000100008000000000000000000000403000",
5722 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2147483649\"}}"
5723 + },
5724 + {
5725 + "description": "[decq828] values around [u]int32 edges (zeros done earlier)",
5726 + "canonical_bson": "18000000136400FEFFFFFF00000000000000000000403000",
5727 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4294967294\"}}"
5728 + },
5729 + {
5730 + "description": "[decq829] values around [u]int32 edges (zeros done earlier)",
5731 + "canonical_bson": "18000000136400FFFFFFFF00000000000000000000403000",
5732 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4294967295\"}}"
5733 + },
5734 + {
5735 + "description": "[decq830] values around [u]int32 edges (zeros done earlier)",
5736 + "canonical_bson": "180000001364000000000001000000000000000000403000",
5737 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4294967296\"}}"
5738 + },
5739 + {
5740 + "description": "[decq831] values around [u]int32 edges (zeros done earlier)",
5741 + "canonical_bson": "180000001364000100000001000000000000000000403000",
5742 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4294967297\"}}"
5743 + },
5744 + {
5745 + "description": "[decq022] Normality",
5746 + "canonical_bson": "18000000136400C7711CC7B548F377DC80A131C836403000",
5747 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1111111111111111111111111111111111\"}}"
5748 + },
5749 + {
5750 + "description": "[decq020] Normality",
5751 + "canonical_bson": "18000000136400F2AF967ED05C82DE3297FF6FDE3C403000",
5752 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1234567890123456789012345678901234\"}}"
5753 + },
5754 + {
5755 + "description": "[decq550] Specials",
5756 + "canonical_bson": "18000000136400FFFFFFFF638E8D37C087ADBE09ED413000",
5757 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9999999999999999999999999999999999\"}}"
5758 + }
5759 + ]
5760 +}
5761 +
5762 diff --git a/src/tests/spec/json/bson-corpus/decimal128-3.json b/src/tests/spec/json/bson-corpus/decimal128-3.json
5763 new file mode 100644
5764 index 0000000..9b01534
5765 --- /dev/null
5766 +++ b/src/tests/spec/json/bson-corpus/decimal128-3.json
5767 @@ -0,0 +1,1771 @@
5768 +{
5769 + "description": "Decimal128",
5770 + "bson_type": "0x13",
5771 + "test_key": "d",
5772 + "valid": [
5773 + {
5774 + "description": "[basx066] strings without E cannot generate E in result",
5775 + "canonical_bson": "18000000136400185C0ACE0000000000000000000038B000",
5776 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-00345678.5432\"}}",
5777 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-345678.5432\"}}"
5778 + },
5779 + {
5780 + "description": "[basx065] strings without E cannot generate E in result",
5781 + "canonical_bson": "18000000136400185C0ACE0000000000000000000038B000",
5782 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0345678.5432\"}}",
5783 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-345678.5432\"}}"
5784 + },
5785 + {
5786 + "description": "[basx064] strings without E cannot generate E in result",
5787 + "canonical_bson": "18000000136400185C0ACE0000000000000000000038B000",
5788 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-345678.5432\"}}"
5789 + },
5790 + {
5791 + "description": "[basx041] strings without E cannot generate E in result",
5792 + "canonical_bson": "180000001364004C0000000000000000000000000040B000",
5793 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-76\"}}"
5794 + },
5795 + {
5796 + "description": "[basx027] conform to rules and exponent will be in permitted range).",
5797 + "canonical_bson": "180000001364000F270000000000000000000000003AB000",
5798 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.999\"}}"
5799 + },
5800 + {
5801 + "description": "[basx026] conform to rules and exponent will be in permitted range).",
5802 + "canonical_bson": "180000001364009F230000000000000000000000003AB000",
5803 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.119\"}}"
5804 + },
5805 + {
5806 + "description": "[basx025] conform to rules and exponent will be in permitted range).",
5807 + "canonical_bson": "180000001364008F030000000000000000000000003CB000",
5808 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.11\"}}"
5809 + },
5810 + {
5811 + "description": "[basx024] conform to rules and exponent will be in permitted range).",
5812 + "canonical_bson": "180000001364005B000000000000000000000000003EB000",
5813 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.1\"}}"
5814 + },
5815 + {
5816 + "description": "[dqbsr531] negatives (Rounded)",
5817 + "canonical_bson": "1800000013640099761CC7B548F377DC80A131C836FEAF00",
5818 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.1111111111111111111111111111123450\"}}",
5819 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.111111111111111111111111111112345\"}}"
5820 + },
5821 + {
5822 + "description": "[basx022] conform to rules and exponent will be in permitted range).",
5823 + "canonical_bson": "180000001364000A000000000000000000000000003EB000",
5824 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.0\"}}"
5825 + },
5826 + {
5827 + "description": "[basx021] conform to rules and exponent will be in permitted range).",
5828 + "canonical_bson": "18000000136400010000000000000000000000000040B000",
5829 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1\"}}"
5830 + },
5831 + {
5832 + "description": "[basx601] Zeros",
5833 + "canonical_bson": "1800000013640000000000000000000000000000002E3000",
5834 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000000\"}}",
5835 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-9\"}}"
5836 + },
5837 + {
5838 + "description": "[basx622] Zeros",
5839 + "canonical_bson": "1800000013640000000000000000000000000000002EB000",
5840 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000000000\"}}",
5841 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-9\"}}"
5842 + },
5843 + {
5844 + "description": "[basx602] Zeros",
5845 + "canonical_bson": "180000001364000000000000000000000000000000303000",
5846 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000000\"}}",
5847 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-8\"}}"
5848 + },
5849 + {
5850 + "description": "[basx621] Zeros",
5851 + "canonical_bson": "18000000136400000000000000000000000000000030B000",
5852 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000000\"}}",
5853 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-8\"}}"
5854 + },
5855 + {
5856 + "description": "[basx603] Zeros",
5857 + "canonical_bson": "180000001364000000000000000000000000000000323000",
5858 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000000\"}}",
5859 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-7\"}}"
5860 + },
5861 + {
5862 + "description": "[basx620] Zeros",
5863 + "canonical_bson": "18000000136400000000000000000000000000000032B000",
5864 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0000000\"}}",
5865 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-7\"}}"
5866 + },
5867 + {
5868 + "description": "[basx604] Zeros",
5869 + "canonical_bson": "180000001364000000000000000000000000000000343000",
5870 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000\"}}"
5871 + },
5872 + {
5873 + "description": "[basx619] Zeros",
5874 + "canonical_bson": "18000000136400000000000000000000000000000034B000",
5875 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000000\"}}"
5876 + },
5877 + {
5878 + "description": "[basx605] Zeros",
5879 + "canonical_bson": "180000001364000000000000000000000000000000363000",
5880 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000\"}}"
5881 + },
5882 + {
5883 + "description": "[basx618] Zeros",
5884 + "canonical_bson": "18000000136400000000000000000000000000000036B000",
5885 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000\"}}"
5886 + },
5887 + {
5888 + "description": "[basx680] Zeros",
5889 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5890 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"000000.\"}}",
5891 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5892 + },
5893 + {
5894 + "description": "[basx606] Zeros",
5895 + "canonical_bson": "180000001364000000000000000000000000000000383000",
5896 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000\"}}"
5897 + },
5898 + {
5899 + "description": "[basx617] Zeros",
5900 + "canonical_bson": "18000000136400000000000000000000000000000038B000",
5901 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0000\"}}"
5902 + },
5903 + {
5904 + "description": "[basx681] Zeros",
5905 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5906 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00000.\"}}",
5907 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5908 + },
5909 + {
5910 + "description": "[basx686] Zeros",
5911 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5912 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+00000.\"}}",
5913 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5914 + },
5915 + {
5916 + "description": "[basx687] Zeros",
5917 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
5918 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-00000.\"}}",
5919 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
5920 + },
5921 + {
5922 + "description": "[basx019] conform to rules and exponent will be in permitted range).",
5923 + "canonical_bson": "1800000013640000000000000000000000000000003CB000",
5924 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-00.00\"}}",
5925 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00\"}}"
5926 + },
5927 + {
5928 + "description": "[basx607] Zeros",
5929 + "canonical_bson": "1800000013640000000000000000000000000000003A3000",
5930 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000\"}}"
5931 + },
5932 + {
5933 + "description": "[basx616] Zeros",
5934 + "canonical_bson": "1800000013640000000000000000000000000000003AB000",
5935 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000\"}}"
5936 + },
5937 + {
5938 + "description": "[basx682] Zeros",
5939 + "canonical_bson": "180000001364000000000000000000000000000000403000",
5940 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0000.\"}}",
5941 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
5942 + },
5943 + {
5944 + "description": "[basx155] Numbers with E",
5945 + "canonical_bson": "1800000013640000000000000000000000000000003A3000",
5946 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000e+0\"}}",
5947 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000\"}}"
5948 + },
5949 + {
5950 + "description": "[basx130] Numbers with E",
5951 + "canonical_bson": "180000001364000000000000000000000000000000383000",
5952 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000E-1\"}}",
5953 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000\"}}"
5954 + },
5955 + {
5956 + "description": "[basx290] some more negative zeros [systematic tests below]",
5957 + "canonical_bson": "18000000136400000000000000000000000000000038B000",
5958 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000E-1\"}}",
5959 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0000\"}}"
5960 + },
5961 + {
5962 + "description": "[basx131] Numbers with E",
5963 + "canonical_bson": "180000001364000000000000000000000000000000363000",
5964 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000E-2\"}}",
5965 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000\"}}"
5966 + },
5967 + {
5968 + "description": "[basx291] some more negative zeros [systematic tests below]",
5969 + "canonical_bson": "18000000136400000000000000000000000000000036B000",
5970 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000E-2\"}}",
5971 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000\"}}"
5972 + },
5973 + {
5974 + "description": "[basx132] Numbers with E",
5975 + "canonical_bson": "180000001364000000000000000000000000000000343000",
5976 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000E-3\"}}",
5977 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000\"}}"
5978 + },
5979 + {
5980 + "description": "[basx292] some more negative zeros [systematic tests below]",
5981 + "canonical_bson": "18000000136400000000000000000000000000000034B000",
5982 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000E-3\"}}",
5983 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000000\"}}"
5984 + },
5985 + {
5986 + "description": "[basx133] Numbers with E",
5987 + "canonical_bson": "180000001364000000000000000000000000000000323000",
5988 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000E-4\"}}",
5989 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-7\"}}"
5990 + },
5991 + {
5992 + "description": "[basx293] some more negative zeros [systematic tests below]",
5993 + "canonical_bson": "18000000136400000000000000000000000000000032B000",
5994 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000E-4\"}}",
5995 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-7\"}}"
5996 + },
5997 + {
5998 + "description": "[basx608] Zeros",
5999 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
6000 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
6001 + },
6002 + {
6003 + "description": "[basx615] Zeros",
6004 + "canonical_bson": "1800000013640000000000000000000000000000003CB000",
6005 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00\"}}"
6006 + },
6007 + {
6008 + "description": "[basx683] Zeros",
6009 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6010 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"000.\"}}",
6011 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6012 + },
6013 + {
6014 + "description": "[basx630] Zeros",
6015 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
6016 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+0\"}}",
6017 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
6018 + },
6019 + {
6020 + "description": "[basx670] Zeros",
6021 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
6022 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-0\"}}",
6023 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
6024 + },
6025 + {
6026 + "description": "[basx631] Zeros",
6027 + "canonical_bson": "1800000013640000000000000000000000000000003E3000",
6028 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+1\"}}",
6029 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}"
6030 + },
6031 + {
6032 + "description": "[basx671] Zeros",
6033 + "canonical_bson": "1800000013640000000000000000000000000000003A3000",
6034 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-1\"}}",
6035 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000\"}}"
6036 + },
6037 + {
6038 + "description": "[basx134] Numbers with E",
6039 + "canonical_bson": "180000001364000000000000000000000000000000383000",
6040 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-2\"}}",
6041 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000\"}}"
6042 + },
6043 + {
6044 + "description": "[basx294] some more negative zeros [systematic tests below]",
6045 + "canonical_bson": "18000000136400000000000000000000000000000038B000",
6046 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00E-2\"}}",
6047 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0000\"}}"
6048 + },
6049 + {
6050 + "description": "[basx632] Zeros",
6051 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6052 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+2\"}}",
6053 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6054 + },
6055 + {
6056 + "description": "[basx672] Zeros",
6057 + "canonical_bson": "180000001364000000000000000000000000000000383000",
6058 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-2\"}}",
6059 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000\"}}"
6060 + },
6061 + {
6062 + "description": "[basx135] Numbers with E",
6063 + "canonical_bson": "180000001364000000000000000000000000000000363000",
6064 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-3\"}}",
6065 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000\"}}"
6066 + },
6067 + {
6068 + "description": "[basx295] some more negative zeros [systematic tests below]",
6069 + "canonical_bson": "18000000136400000000000000000000000000000036B000",
6070 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00E-3\"}}",
6071 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000\"}}"
6072 + },
6073 + {
6074 + "description": "[basx633] Zeros",
6075 + "canonical_bson": "180000001364000000000000000000000000000000423000",
6076 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+3\"}}",
6077 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+1\"}}"
6078 + },
6079 + {
6080 + "description": "[basx673] Zeros",
6081 + "canonical_bson": "180000001364000000000000000000000000000000363000",
6082 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-3\"}}",
6083 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000\"}}"
6084 + },
6085 + {
6086 + "description": "[basx136] Numbers with E",
6087 + "canonical_bson": "180000001364000000000000000000000000000000343000",
6088 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-4\"}}",
6089 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000\"}}"
6090 + },
6091 + {
6092 + "description": "[basx674] Zeros",
6093 + "canonical_bson": "180000001364000000000000000000000000000000343000",
6094 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-4\"}}",
6095 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000\"}}"
6096 + },
6097 + {
6098 + "description": "[basx634] Zeros",
6099 + "canonical_bson": "180000001364000000000000000000000000000000443000",
6100 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+4\"}}",
6101 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+2\"}}"
6102 + },
6103 + {
6104 + "description": "[basx137] Numbers with E",
6105 + "canonical_bson": "180000001364000000000000000000000000000000323000",
6106 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-5\"}}",
6107 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-7\"}}"
6108 + },
6109 + {
6110 + "description": "[basx635] Zeros",
6111 + "canonical_bson": "180000001364000000000000000000000000000000463000",
6112 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+5\"}}",
6113 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+3\"}}"
6114 + },
6115 + {
6116 + "description": "[basx675] Zeros",
6117 + "canonical_bson": "180000001364000000000000000000000000000000323000",
6118 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-5\"}}",
6119 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-7\"}}"
6120 + },
6121 + {
6122 + "description": "[basx636] Zeros",
6123 + "canonical_bson": "180000001364000000000000000000000000000000483000",
6124 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+6\"}}",
6125 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+4\"}}"
6126 + },
6127 + {
6128 + "description": "[basx676] Zeros",
6129 + "canonical_bson": "180000001364000000000000000000000000000000303000",
6130 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-6\"}}",
6131 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-8\"}}"
6132 + },
6133 + {
6134 + "description": "[basx637] Zeros",
6135 + "canonical_bson": "1800000013640000000000000000000000000000004A3000",
6136 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+7\"}}",
6137 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+5\"}}"
6138 + },
6139 + {
6140 + "description": "[basx677] Zeros",
6141 + "canonical_bson": "1800000013640000000000000000000000000000002E3000",
6142 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-7\"}}",
6143 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-9\"}}"
6144 + },
6145 + {
6146 + "description": "[basx638] Zeros",
6147 + "canonical_bson": "1800000013640000000000000000000000000000004C3000",
6148 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+8\"}}",
6149 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6\"}}"
6150 + },
6151 + {
6152 + "description": "[basx678] Zeros",
6153 + "canonical_bson": "1800000013640000000000000000000000000000002C3000",
6154 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-8\"}}",
6155 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-10\"}}"
6156 + },
6157 + {
6158 + "description": "[basx149] Numbers with E",
6159 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6160 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"000E+9\"}}",
6161 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6162 + },
6163 + {
6164 + "description": "[basx639] Zeros",
6165 + "canonical_bson": "1800000013640000000000000000000000000000004E3000",
6166 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E+9\"}}",
6167 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+7\"}}"
6168 + },
6169 + {
6170 + "description": "[basx679] Zeros",
6171 + "canonical_bson": "1800000013640000000000000000000000000000002A3000",
6172 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00E-9\"}}",
6173 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-11\"}}"
6174 + },
6175 + {
6176 + "description": "[basx063] strings without E cannot generate E in result",
6177 + "canonical_bson": "18000000136400185C0ACE00000000000000000000383000",
6178 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+00345678.5432\"}}",
6179 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.5432\"}}"
6180 + },
6181 + {
6182 + "description": "[basx018] conform to rules and exponent will be in permitted range).",
6183 + "canonical_bson": "1800000013640000000000000000000000000000003EB000",
6184 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}"
6185 + },
6186 + {
6187 + "description": "[basx609] Zeros",
6188 + "canonical_bson": "1800000013640000000000000000000000000000003E3000",
6189 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}"
6190 + },
6191 + {
6192 + "description": "[basx614] Zeros",
6193 + "canonical_bson": "1800000013640000000000000000000000000000003EB000",
6194 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}"
6195 + },
6196 + {
6197 + "description": "[basx684] Zeros",
6198 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6199 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00.\"}}",
6200 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6201 + },
6202 + {
6203 + "description": "[basx640] Zeros",
6204 + "canonical_bson": "1800000013640000000000000000000000000000003E3000",
6205 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+0\"}}",
6206 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}"
6207 + },
6208 + {
6209 + "description": "[basx660] Zeros",
6210 + "canonical_bson": "1800000013640000000000000000000000000000003E3000",
6211 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-0\"}}",
6212 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}"
6213 + },
6214 + {
6215 + "description": "[basx641] Zeros",
6216 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6217 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+1\"}}",
6218 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6219 + },
6220 + {
6221 + "description": "[basx661] Zeros",
6222 + "canonical_bson": "1800000013640000000000000000000000000000003C3000",
6223 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-1\"}}",
6224 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00\"}}"
6225 + },
6226 + {
6227 + "description": "[basx296] some more negative zeros [systematic tests below]",
6228 + "canonical_bson": "1800000013640000000000000000000000000000003AB000",
6229 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0E-2\"}}",
6230 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000\"}}"
6231 + },
6232 + {
6233 + "description": "[basx642] Zeros",
6234 + "canonical_bson": "180000001364000000000000000000000000000000423000",
6235 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+2\"}}",
6236 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+1\"}}"
6237 + },
6238 + {
6239 + "description": "[basx662] Zeros",
6240 + "canonical_bson": "1800000013640000000000000000000000000000003A3000",
6241 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-2\"}}",
6242 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000\"}}"
6243 + },
6244 + {
6245 + "description": "[basx297] some more negative zeros [systematic tests below]",
6246 + "canonical_bson": "18000000136400000000000000000000000000000038B000",
6247 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0E-3\"}}",
6248 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0000\"}}"
6249 + },
6250 + {
6251 + "description": "[basx643] Zeros",
6252 + "canonical_bson": "180000001364000000000000000000000000000000443000",
6253 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+3\"}}",
6254 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+2\"}}"
6255 + },
6256 + {
6257 + "description": "[basx663] Zeros",
6258 + "canonical_bson": "180000001364000000000000000000000000000000383000",
6259 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-3\"}}",
6260 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000\"}}"
6261 + },
6262 + {
6263 + "description": "[basx644] Zeros",
6264 + "canonical_bson": "180000001364000000000000000000000000000000463000",
6265 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+4\"}}",
6266 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+3\"}}"
6267 + },
6268 + {
6269 + "description": "[basx664] Zeros",
6270 + "canonical_bson": "180000001364000000000000000000000000000000363000",
6271 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-4\"}}",
6272 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000\"}}"
6273 + },
6274 + {
6275 + "description": "[basx645] Zeros",
6276 + "canonical_bson": "180000001364000000000000000000000000000000483000",
6277 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+5\"}}",
6278 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+4\"}}"
6279 + },
6280 + {
6281 + "description": "[basx665] Zeros",
6282 + "canonical_bson": "180000001364000000000000000000000000000000343000",
6283 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-5\"}}",
6284 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000\"}}"
6285 + },
6286 + {
6287 + "description": "[basx646] Zeros",
6288 + "canonical_bson": "1800000013640000000000000000000000000000004A3000",
6289 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+6\"}}",
6290 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+5\"}}"
6291 + },
6292 + {
6293 + "description": "[basx666] Zeros",
6294 + "canonical_bson": "180000001364000000000000000000000000000000323000",
6295 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-6\"}}",
6296 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-7\"}}"
6297 + },
6298 + {
6299 + "description": "[basx647] Zeros",
6300 + "canonical_bson": "1800000013640000000000000000000000000000004C3000",
6301 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+7\"}}",
6302 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6\"}}"
6303 + },
6304 + {
6305 + "description": "[basx667] Zeros",
6306 + "canonical_bson": "180000001364000000000000000000000000000000303000",
6307 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-7\"}}",
6308 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-8\"}}"
6309 + },
6310 + {
6311 + "description": "[basx648] Zeros",
6312 + "canonical_bson": "1800000013640000000000000000000000000000004E3000",
6313 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+8\"}}",
6314 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+7\"}}"
6315 + },
6316 + {
6317 + "description": "[basx668] Zeros",
6318 + "canonical_bson": "1800000013640000000000000000000000000000002E3000",
6319 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-8\"}}",
6320 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-9\"}}"
6321 + },
6322 + {
6323 + "description": "[basx160] Numbers with E",
6324 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6325 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00E+9\"}}",
6326 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6327 + },
6328 + {
6329 + "description": "[basx161] Numbers with E",
6330 + "canonical_bson": "1800000013640000000000000000000000000000002E3000",
6331 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00E-9\"}}",
6332 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-9\"}}"
6333 + },
6334 + {
6335 + "description": "[basx649] Zeros",
6336 + "canonical_bson": "180000001364000000000000000000000000000000503000",
6337 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E+9\"}}",
6338 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+8\"}}"
6339 + },
6340 + {
6341 + "description": "[basx669] Zeros",
6342 + "canonical_bson": "1800000013640000000000000000000000000000002C3000",
6343 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0E-9\"}}",
6344 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-10\"}}"
6345 + },
6346 + {
6347 + "description": "[basx062] strings without E cannot generate E in result",
6348 + "canonical_bson": "18000000136400185C0ACE00000000000000000000383000",
6349 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0345678.5432\"}}",
6350 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.5432\"}}"
6351 + },
6352 + {
6353 + "description": "[basx001] conform to rules and exponent will be in permitted range).",
6354 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6355 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6356 + },
6357 + {
6358 + "description": "[basx017] conform to rules and exponent will be in permitted range).",
6359 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
6360 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
6361 + },
6362 + {
6363 + "description": "[basx611] Zeros",
6364 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6365 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.\"}}",
6366 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6367 + },
6368 + {
6369 + "description": "[basx613] Zeros",
6370 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
6371 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.\"}}",
6372 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
6373 + },
6374 + {
6375 + "description": "[basx685] Zeros",
6376 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6377 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.\"}}",
6378 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6379 + },
6380 + {
6381 + "description": "[basx688] Zeros",
6382 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6383 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0.\"}}",
6384 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6385 + },
6386 + {
6387 + "description": "[basx689] Zeros",
6388 + "canonical_bson": "18000000136400000000000000000000000000000040B000",
6389 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.\"}}",
6390 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0\"}}"
6391 + },
6392 + {
6393 + "description": "[basx650] Zeros",
6394 + "canonical_bson": "180000001364000000000000000000000000000000403000",
6395 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+0\"}}",
6396 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0\"}}"
6397 + },
6398 + {
6399 + "description": "[basx651] Zeros",
6400 + "canonical_bson": "180000001364000000000000000000000000000000423000",
6401 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+1\"}}"
6402 + },
6403 + {
6404 + "description": "[basx298] some more negative zeros [systematic tests below]",
6405 + "canonical_bson": "1800000013640000000000000000000000000000003CB000",
6406 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-2\"}}",
6407 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00\"}}"
6408 + },
6409 + {
6410 + "description": "[basx652] Zeros",
6411 + "canonical_bson": "180000001364000000000000000000000000000000443000",
6412 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+2\"}}"
6413 + },
6414 + {
6415 + "description": "[basx299] some more negative zeros [systematic tests below]",
6416 + "canonical_bson": "1800000013640000000000000000000000000000003AB000",
6417 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-3\"}}",
6418 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000\"}}"
6419 + },
6420 + {
6421 + "description": "[basx653] Zeros",
6422 + "canonical_bson": "180000001364000000000000000000000000000000463000",
6423 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+3\"}}"
6424 + },
6425 + {
6426 + "description": "[basx654] Zeros",
6427 + "canonical_bson": "180000001364000000000000000000000000000000483000",
6428 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+4\"}}"
6429 + },
6430 + {
6431 + "description": "[basx655] Zeros",
6432 + "canonical_bson": "1800000013640000000000000000000000000000004A3000",
6433 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+5\"}}"
6434 + },
6435 + {
6436 + "description": "[basx656] Zeros",
6437 + "canonical_bson": "1800000013640000000000000000000000000000004C3000",
6438 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6\"}}"
6439 + },
6440 + {
6441 + "description": "[basx657] Zeros",
6442 + "canonical_bson": "1800000013640000000000000000000000000000004E3000",
6443 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+7\"}}"
6444 + },
6445 + {
6446 + "description": "[basx658] Zeros",
6447 + "canonical_bson": "180000001364000000000000000000000000000000503000",
6448 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+8\"}}"
6449 + },
6450 + {
6451 + "description": "[basx138] Numbers with E",
6452 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6453 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0E+9\"}}",
6454 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6455 + },
6456 + {
6457 + "description": "[basx139] Numbers with E",
6458 + "canonical_bson": "18000000136400000000000000000000000000000052B000",
6459 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+9\"}}"
6460 + },
6461 + {
6462 + "description": "[basx144] Numbers with E",
6463 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6464 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6465 + },
6466 + {
6467 + "description": "[basx154] Numbers with E",
6468 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6469 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E9\"}}",
6470 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6471 + },
6472 + {
6473 + "description": "[basx659] Zeros",
6474 + "canonical_bson": "180000001364000000000000000000000000000000523000",
6475 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+9\"}}"
6476 + },
6477 + {
6478 + "description": "[basx042] strings without E cannot generate E in result",
6479 + "canonical_bson": "18000000136400FC040000000000000000000000003C3000",
6480 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+12.76\"}}",
6481 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}"
6482 + },
6483 + {
6484 + "description": "[basx143] Numbers with E",
6485 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6486 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+1E+009\"}}",
6487 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6488 + },
6489 + {
6490 + "description": "[basx061] strings without E cannot generate E in result",
6491 + "canonical_bson": "18000000136400185C0ACE00000000000000000000383000",
6492 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+345678.5432\"}}",
6493 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.5432\"}}"
6494 + },
6495 + {
6496 + "description": "[basx036] conform to rules and exponent will be in permitted range).",
6497 + "canonical_bson": "1800000013640015CD5B0700000000000000000000203000",
6498 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000000123456789\"}}",
6499 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.23456789E-8\"}}"
6500 + },
6501 + {
6502 + "description": "[basx035] conform to rules and exponent will be in permitted range).",
6503 + "canonical_bson": "1800000013640015CD5B0700000000000000000000223000",
6504 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000123456789\"}}",
6505 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.23456789E-7\"}}"
6506 + },
6507 + {
6508 + "description": "[basx034] conform to rules and exponent will be in permitted range).",
6509 + "canonical_bson": "1800000013640015CD5B0700000000000000000000243000",
6510 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000123456789\"}}"
6511 + },
6512 + {
6513 + "description": "[basx053] strings without E cannot generate E in result",
6514 + "canonical_bson": "180000001364003200000000000000000000000000323000",
6515 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000050\"}}"
6516 + },
6517 + {
6518 + "description": "[basx033] conform to rules and exponent will be in permitted range).",
6519 + "canonical_bson": "1800000013640015CD5B0700000000000000000000263000",
6520 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000123456789\"}}"
6521 + },
6522 + {
6523 + "description": "[basx016] conform to rules and exponent will be in permitted range).",
6524 + "canonical_bson": "180000001364000C000000000000000000000000003A3000",
6525 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.012\"}}"
6526 + },
6527 + {
6528 + "description": "[basx015] conform to rules and exponent will be in permitted range).",
6529 + "canonical_bson": "180000001364007B000000000000000000000000003A3000",
6530 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.123\"}}"
6531 + },
6532 + {
6533 + "description": "[basx037] conform to rules and exponent will be in permitted range).",
6534 + "canonical_bson": "1800000013640078DF0D8648700000000000000000223000",
6535 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.123456789012344\"}}"
6536 + },
6537 + {
6538 + "description": "[basx038] conform to rules and exponent will be in permitted range).",
6539 + "canonical_bson": "1800000013640079DF0D8648700000000000000000223000",
6540 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.123456789012345\"}}"
6541 + },
6542 + {
6543 + "description": "[basx250] Numbers with E",
6544 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
6545 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
6546 + },
6547 + {
6548 + "description": "[basx257] Numbers with E",
6549 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
6550 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-0\"}}",
6551 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
6552 + },
6553 + {
6554 + "description": "[basx256] Numbers with E",
6555 + "canonical_bson": "18000000136400F104000000000000000000000000363000",
6556 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-1\"}}",
6557 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.01265\"}}"
6558 + },
6559 + {
6560 + "description": "[basx258] Numbers with E",
6561 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
6562 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+1\"}}",
6563 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
6564 + },
6565 + {
6566 + "description": "[basx251] Numbers with E",
6567 + "canonical_bson": "18000000136400F104000000000000000000000000103000",
6568 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-20\"}}",
6569 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-21\"}}"
6570 + },
6571 + {
6572 + "description": "[basx263] Numbers with E",
6573 + "canonical_bson": "18000000136400F104000000000000000000000000603000",
6574 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+20\"}}",
6575 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+19\"}}"
6576 + },
6577 + {
6578 + "description": "[basx255] Numbers with E",
6579 + "canonical_bson": "18000000136400F104000000000000000000000000343000",
6580 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-2\"}}",
6581 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.001265\"}}"
6582 + },
6583 + {
6584 + "description": "[basx259] Numbers with E",
6585 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
6586 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+2\"}}",
6587 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
6588 + },
6589 + {
6590 + "description": "[basx254] Numbers with E",
6591 + "canonical_bson": "18000000136400F104000000000000000000000000323000",
6592 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-3\"}}",
6593 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0001265\"}}"
6594 + },
6595 + {
6596 + "description": "[basx260] Numbers with E",
6597 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
6598 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+3\"}}",
6599 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
6600 + },
6601 + {
6602 + "description": "[basx253] Numbers with E",
6603 + "canonical_bson": "18000000136400F104000000000000000000000000303000",
6604 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-4\"}}",
6605 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00001265\"}}"
6606 + },
6607 + {
6608 + "description": "[basx261] Numbers with E",
6609 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
6610 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+4\"}}",
6611 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
6612 + },
6613 + {
6614 + "description": "[basx252] Numbers with E",
6615 + "canonical_bson": "18000000136400F104000000000000000000000000283000",
6616 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E-8\"}}",
6617 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-9\"}}"
6618 + },
6619 + {
6620 + "description": "[basx262] Numbers with E",
6621 + "canonical_bson": "18000000136400F104000000000000000000000000483000",
6622 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265E+8\"}}",
6623 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+7\"}}"
6624 + },
6625 + {
6626 + "description": "[basx159] Numbers with E",
6627 + "canonical_bson": "1800000013640049000000000000000000000000002E3000",
6628 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.73e-7\"}}",
6629 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7.3E-8\"}}"
6630 + },
6631 + {
6632 + "description": "[basx004] conform to rules and exponent will be in permitted range).",
6633 + "canonical_bson": "1800000013640064000000000000000000000000003C3000",
6634 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00\"}}"
6635 + },
6636 + {
6637 + "description": "[basx003] conform to rules and exponent will be in permitted range).",
6638 + "canonical_bson": "180000001364000A000000000000000000000000003E3000",
6639 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0\"}}"
6640 + },
6641 + {
6642 + "description": "[basx002] conform to rules and exponent will be in permitted range).",
6643 + "canonical_bson": "180000001364000100000000000000000000000000403000",
6644 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1\"}}"
6645 + },
6646 + {
6647 + "description": "[basx148] Numbers with E",
6648 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6649 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+009\"}}",
6650 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6651 + },
6652 + {
6653 + "description": "[basx153] Numbers with E",
6654 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6655 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E009\"}}",
6656 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6657 + },
6658 + {
6659 + "description": "[basx141] Numbers with E",
6660 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6661 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1e+09\"}}",
6662 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6663 + },
6664 + {
6665 + "description": "[basx146] Numbers with E",
6666 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6667 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+09\"}}",
6668 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6669 + },
6670 + {
6671 + "description": "[basx151] Numbers with E",
6672 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6673 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1e09\"}}",
6674 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6675 + },
6676 + {
6677 + "description": "[basx142] Numbers with E",
6678 + "canonical_bson": "180000001364000100000000000000000000000000F43000",
6679 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+90\"}}"
6680 + },
6681 + {
6682 + "description": "[basx147] Numbers with E",
6683 + "canonical_bson": "180000001364000100000000000000000000000000F43000",
6684 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1e+90\"}}",
6685 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+90\"}}"
6686 + },
6687 + {
6688 + "description": "[basx152] Numbers with E",
6689 + "canonical_bson": "180000001364000100000000000000000000000000F43000",
6690 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E90\"}}",
6691 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+90\"}}"
6692 + },
6693 + {
6694 + "description": "[basx140] Numbers with E",
6695 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6696 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6697 + },
6698 + {
6699 + "description": "[basx150] Numbers with E",
6700 + "canonical_bson": "180000001364000100000000000000000000000000523000",
6701 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E9\"}}",
6702 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+9\"}}"
6703 + },
6704 + {
6705 + "description": "[basx014] conform to rules and exponent will be in permitted range).",
6706 + "canonical_bson": "18000000136400D2040000000000000000000000003A3000",
6707 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.234\"}}"
6708 + },
6709 + {
6710 + "description": "[basx170] Numbers with E",
6711 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
6712 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
6713 + },
6714 + {
6715 + "description": "[basx177] Numbers with E",
6716 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
6717 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-0\"}}",
6718 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
6719 + },
6720 + {
6721 + "description": "[basx176] Numbers with E",
6722 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
6723 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-1\"}}",
6724 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
6725 + },
6726 + {
6727 + "description": "[basx178] Numbers with E",
6728 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
6729 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+1\"}}",
6730 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
6731 + },
6732 + {
6733 + "description": "[basx171] Numbers with E",
6734 + "canonical_bson": "18000000136400F104000000000000000000000000123000",
6735 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-20\"}}"
6736 + },
6737 + {
6738 + "description": "[basx183] Numbers with E",
6739 + "canonical_bson": "18000000136400F104000000000000000000000000623000",
6740 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+20\"}}"
6741 + },
6742 + {
6743 + "description": "[basx175] Numbers with E",
6744 + "canonical_bson": "18000000136400F104000000000000000000000000363000",
6745 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-2\"}}",
6746 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.01265\"}}"
6747 + },
6748 + {
6749 + "description": "[basx179] Numbers with E",
6750 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
6751 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+2\"}}",
6752 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
6753 + },
6754 + {
6755 + "description": "[basx174] Numbers with E",
6756 + "canonical_bson": "18000000136400F104000000000000000000000000343000",
6757 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-3\"}}",
6758 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.001265\"}}"
6759 + },
6760 + {
6761 + "description": "[basx180] Numbers with E",
6762 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
6763 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+3\"}}",
6764 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
6765 + },
6766 + {
6767 + "description": "[basx173] Numbers with E",
6768 + "canonical_bson": "18000000136400F104000000000000000000000000323000",
6769 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-4\"}}",
6770 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0001265\"}}"
6771 + },
6772 + {
6773 + "description": "[basx181] Numbers with E",
6774 + "canonical_bson": "18000000136400F104000000000000000000000000423000",
6775 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+4\"}}"
6776 + },
6777 + {
6778 + "description": "[basx172] Numbers with E",
6779 + "canonical_bson": "18000000136400F1040000000000000000000000002A3000",
6780 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-8\"}}"
6781 + },
6782 + {
6783 + "description": "[basx182] Numbers with E",
6784 + "canonical_bson": "18000000136400F1040000000000000000000000004A3000",
6785 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+8\"}}"
6786 + },
6787 + {
6788 + "description": "[basx157] Numbers with E",
6789 + "canonical_bson": "180000001364000400000000000000000000000000523000",
6790 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4E+9\"}}"
6791 + },
6792 + {
6793 + "description": "[basx067] examples",
6794 + "canonical_bson": "180000001364000500000000000000000000000000343000",
6795 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-6\"}}",
6796 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000005\"}}"
6797 + },
6798 + {
6799 + "description": "[basx069] examples",
6800 + "canonical_bson": "180000001364000500000000000000000000000000323000",
6801 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-7\"}}"
6802 + },
6803 + {
6804 + "description": "[basx385] Engineering notation tests",
6805 + "canonical_bson": "180000001364000700000000000000000000000000403000",
6806 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E0\"}}",
6807 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7\"}}"
6808 + },
6809 + {
6810 + "description": "[basx365] Engineering notation tests",
6811 + "canonical_bson": "180000001364000700000000000000000000000000543000",
6812 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E10\"}}",
6813 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+10\"}}"
6814 + },
6815 + {
6816 + "description": "[basx405] Engineering notation tests",
6817 + "canonical_bson": "1800000013640007000000000000000000000000002C3000",
6818 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-10\"}}"
6819 + },
6820 + {
6821 + "description": "[basx363] Engineering notation tests",
6822 + "canonical_bson": "180000001364000700000000000000000000000000563000",
6823 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E11\"}}",
6824 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+11\"}}"
6825 + },
6826 + {
6827 + "description": "[basx407] Engineering notation tests",
6828 + "canonical_bson": "1800000013640007000000000000000000000000002A3000",
6829 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-11\"}}"
6830 + },
6831 + {
6832 + "description": "[basx361] Engineering notation tests",
6833 + "canonical_bson": "180000001364000700000000000000000000000000583000",
6834 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E12\"}}",
6835 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+12\"}}"
6836 + },
6837 + {
6838 + "description": "[basx409] Engineering notation tests",
6839 + "canonical_bson": "180000001364000700000000000000000000000000283000",
6840 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-12\"}}"
6841 + },
6842 + {
6843 + "description": "[basx411] Engineering notation tests",
6844 + "canonical_bson": "180000001364000700000000000000000000000000263000",
6845 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-13\"}}"
6846 + },
6847 + {
6848 + "description": "[basx383] Engineering notation tests",
6849 + "canonical_bson": "180000001364000700000000000000000000000000423000",
6850 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E1\"}}",
6851 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+1\"}}"
6852 + },
6853 + {
6854 + "description": "[basx387] Engineering notation tests",
6855 + "canonical_bson": "1800000013640007000000000000000000000000003E3000",
6856 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-1\"}}",
6857 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.7\"}}"
6858 + },
6859 + {
6860 + "description": "[basx381] Engineering notation tests",
6861 + "canonical_bson": "180000001364000700000000000000000000000000443000",
6862 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E2\"}}",
6863 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+2\"}}"
6864 + },
6865 + {
6866 + "description": "[basx389] Engineering notation tests",
6867 + "canonical_bson": "1800000013640007000000000000000000000000003C3000",
6868 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-2\"}}",
6869 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.07\"}}"
6870 + },
6871 + {
6872 + "description": "[basx379] Engineering notation tests",
6873 + "canonical_bson": "180000001364000700000000000000000000000000463000",
6874 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E3\"}}",
6875 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+3\"}}"
6876 + },
6877 + {
6878 + "description": "[basx391] Engineering notation tests",
6879 + "canonical_bson": "1800000013640007000000000000000000000000003A3000",
6880 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-3\"}}",
6881 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.007\"}}"
6882 + },
6883 + {
6884 + "description": "[basx377] Engineering notation tests",
6885 + "canonical_bson": "180000001364000700000000000000000000000000483000",
6886 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E4\"}}",
6887 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+4\"}}"
6888 + },
6889 + {
6890 + "description": "[basx393] Engineering notation tests",
6891 + "canonical_bson": "180000001364000700000000000000000000000000383000",
6892 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-4\"}}",
6893 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0007\"}}"
6894 + },
6895 + {
6896 + "description": "[basx375] Engineering notation tests",
6897 + "canonical_bson": "1800000013640007000000000000000000000000004A3000",
6898 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E5\"}}",
6899 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+5\"}}"
6900 + },
6901 + {
6902 + "description": "[basx395] Engineering notation tests",
6903 + "canonical_bson": "180000001364000700000000000000000000000000363000",
6904 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-5\"}}",
6905 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00007\"}}"
6906 + },
6907 + {
6908 + "description": "[basx373] Engineering notation tests",
6909 + "canonical_bson": "1800000013640007000000000000000000000000004C3000",
6910 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E6\"}}",
6911 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+6\"}}"
6912 + },
6913 + {
6914 + "description": "[basx397] Engineering notation tests",
6915 + "canonical_bson": "180000001364000700000000000000000000000000343000",
6916 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-6\"}}",
6917 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000007\"}}"
6918 + },
6919 + {
6920 + "description": "[basx371] Engineering notation tests",
6921 + "canonical_bson": "1800000013640007000000000000000000000000004E3000",
6922 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E7\"}}",
6923 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+7\"}}"
6924 + },
6925 + {
6926 + "description": "[basx399] Engineering notation tests",
6927 + "canonical_bson": "180000001364000700000000000000000000000000323000",
6928 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-7\"}}"
6929 + },
6930 + {
6931 + "description": "[basx369] Engineering notation tests",
6932 + "canonical_bson": "180000001364000700000000000000000000000000503000",
6933 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E8\"}}",
6934 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+8\"}}"
6935 + },
6936 + {
6937 + "description": "[basx401] Engineering notation tests",
6938 + "canonical_bson": "180000001364000700000000000000000000000000303000",
6939 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-8\"}}"
6940 + },
6941 + {
6942 + "description": "[basx367] Engineering notation tests",
6943 + "canonical_bson": "180000001364000700000000000000000000000000523000",
6944 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E9\"}}",
6945 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E+9\"}}"
6946 + },
6947 + {
6948 + "description": "[basx403] Engineering notation tests",
6949 + "canonical_bson": "1800000013640007000000000000000000000000002E3000",
6950 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"7E-9\"}}"
6951 + },
6952 + {
6953 + "description": "[basx007] conform to rules and exponent will be in permitted range).",
6954 + "canonical_bson": "1800000013640064000000000000000000000000003E3000",
6955 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.0\"}}"
6956 + },
6957 + {
6958 + "description": "[basx005] conform to rules and exponent will be in permitted range).",
6959 + "canonical_bson": "180000001364000A00000000000000000000000000403000",
6960 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10\"}}"
6961 + },
6962 + {
6963 + "description": "[basx165] Numbers with E",
6964 + "canonical_bson": "180000001364000A00000000000000000000000000523000",
6965 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10E+009\"}}",
6966 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+10\"}}"
6967 + },
6968 + {
6969 + "description": "[basx163] Numbers with E",
6970 + "canonical_bson": "180000001364000A00000000000000000000000000523000",
6971 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10E+09\"}}",
6972 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+10\"}}"
6973 + },
6974 + {
6975 + "description": "[basx325] Engineering notation tests",
6976 + "canonical_bson": "180000001364000A00000000000000000000000000403000",
6977 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e0\"}}",
6978 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10\"}}"
6979 + },
6980 + {
6981 + "description": "[basx305] Engineering notation tests",
6982 + "canonical_bson": "180000001364000A00000000000000000000000000543000",
6983 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e10\"}}",
6984 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+11\"}}"
6985 + },
6986 + {
6987 + "description": "[basx345] Engineering notation tests",
6988 + "canonical_bson": "180000001364000A000000000000000000000000002C3000",
6989 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-10\"}}",
6990 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-9\"}}"
6991 + },
6992 + {
6993 + "description": "[basx303] Engineering notation tests",
6994 + "canonical_bson": "180000001364000A00000000000000000000000000563000",
6995 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e11\"}}",
6996 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+12\"}}"
6997 + },
6998 + {
6999 + "description": "[basx347] Engineering notation tests",
7000 + "canonical_bson": "180000001364000A000000000000000000000000002A3000",
7001 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-11\"}}",
7002 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-10\"}}"
7003 + },
7004 + {
7005 + "description": "[basx301] Engineering notation tests",
7006 + "canonical_bson": "180000001364000A00000000000000000000000000583000",
7007 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e12\"}}",
7008 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+13\"}}"
7009 + },
7010 + {
7011 + "description": "[basx349] Engineering notation tests",
7012 + "canonical_bson": "180000001364000A00000000000000000000000000283000",
7013 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-12\"}}",
7014 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-11\"}}"
7015 + },
7016 + {
7017 + "description": "[basx351] Engineering notation tests",
7018 + "canonical_bson": "180000001364000A00000000000000000000000000263000",
7019 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-13\"}}",
7020 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-12\"}}"
7021 + },
7022 + {
7023 + "description": "[basx323] Engineering notation tests",
7024 + "canonical_bson": "180000001364000A00000000000000000000000000423000",
7025 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e1\"}}",
7026 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+2\"}}"
7027 + },
7028 + {
7029 + "description": "[basx327] Engineering notation tests",
7030 + "canonical_bson": "180000001364000A000000000000000000000000003E3000",
7031 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-1\"}}",
7032 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0\"}}"
7033 + },
7034 + {
7035 + "description": "[basx321] Engineering notation tests",
7036 + "canonical_bson": "180000001364000A00000000000000000000000000443000",
7037 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e2\"}}",
7038 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+3\"}}"
7039 + },
7040 + {
7041 + "description": "[basx329] Engineering notation tests",
7042 + "canonical_bson": "180000001364000A000000000000000000000000003C3000",
7043 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-2\"}}",
7044 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.10\"}}"
7045 + },
7046 + {
7047 + "description": "[basx319] Engineering notation tests",
7048 + "canonical_bson": "180000001364000A00000000000000000000000000463000",
7049 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e3\"}}",
7050 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+4\"}}"
7051 + },
7052 + {
7053 + "description": "[basx331] Engineering notation tests",
7054 + "canonical_bson": "180000001364000A000000000000000000000000003A3000",
7055 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-3\"}}",
7056 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.010\"}}"
7057 + },
7058 + {
7059 + "description": "[basx317] Engineering notation tests",
7060 + "canonical_bson": "180000001364000A00000000000000000000000000483000",
7061 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e4\"}}",
7062 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+5\"}}"
7063 + },
7064 + {
7065 + "description": "[basx333] Engineering notation tests",
7066 + "canonical_bson": "180000001364000A00000000000000000000000000383000",
7067 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-4\"}}",
7068 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0010\"}}"
7069 + },
7070 + {
7071 + "description": "[basx315] Engineering notation tests",
7072 + "canonical_bson": "180000001364000A000000000000000000000000004A3000",
7073 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e5\"}}",
7074 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6\"}}"
7075 + },
7076 + {
7077 + "description": "[basx335] Engineering notation tests",
7078 + "canonical_bson": "180000001364000A00000000000000000000000000363000",
7079 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-5\"}}",
7080 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00010\"}}"
7081 + },
7082 + {
7083 + "description": "[basx313] Engineering notation tests",
7084 + "canonical_bson": "180000001364000A000000000000000000000000004C3000",
7085 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e6\"}}",
7086 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+7\"}}"
7087 + },
7088 + {
7089 + "description": "[basx337] Engineering notation tests",
7090 + "canonical_bson": "180000001364000A00000000000000000000000000343000",
7091 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-6\"}}",
7092 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000010\"}}"
7093 + },
7094 + {
7095 + "description": "[basx311] Engineering notation tests",
7096 + "canonical_bson": "180000001364000A000000000000000000000000004E3000",
7097 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e7\"}}",
7098 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+8\"}}"
7099 + },
7100 + {
7101 + "description": "[basx339] Engineering notation tests",
7102 + "canonical_bson": "180000001364000A00000000000000000000000000323000",
7103 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-7\"}}",
7104 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000010\"}}"
7105 + },
7106 + {
7107 + "description": "[basx309] Engineering notation tests",
7108 + "canonical_bson": "180000001364000A00000000000000000000000000503000",
7109 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e8\"}}",
7110 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+9\"}}"
7111 + },
7112 + {
7113 + "description": "[basx341] Engineering notation tests",
7114 + "canonical_bson": "180000001364000A00000000000000000000000000303000",
7115 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-8\"}}",
7116 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-7\"}}"
7117 + },
7118 + {
7119 + "description": "[basx164] Numbers with E",
7120 + "canonical_bson": "180000001364000A00000000000000000000000000F43000",
7121 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e+90\"}}",
7122 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+91\"}}"
7123 + },
7124 + {
7125 + "description": "[basx162] Numbers with E",
7126 + "canonical_bson": "180000001364000A00000000000000000000000000523000",
7127 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10E+9\"}}",
7128 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+10\"}}"
7129 + },
7130 + {
7131 + "description": "[basx307] Engineering notation tests",
7132 + "canonical_bson": "180000001364000A00000000000000000000000000523000",
7133 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e9\"}}",
7134 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+10\"}}"
7135 + },
7136 + {
7137 + "description": "[basx343] Engineering notation tests",
7138 + "canonical_bson": "180000001364000A000000000000000000000000002E3000",
7139 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"10e-9\"}}",
7140 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-8\"}}"
7141 + },
7142 + {
7143 + "description": "[basx008] conform to rules and exponent will be in permitted range).",
7144 + "canonical_bson": "1800000013640065000000000000000000000000003E3000",
7145 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.1\"}}"
7146 + },
7147 + {
7148 + "description": "[basx009] conform to rules and exponent will be in permitted range).",
7149 + "canonical_bson": "1800000013640068000000000000000000000000003E3000",
7150 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.4\"}}"
7151 + },
7152 + {
7153 + "description": "[basx010] conform to rules and exponent will be in permitted range).",
7154 + "canonical_bson": "1800000013640069000000000000000000000000003E3000",
7155 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.5\"}}"
7156 + },
7157 + {
7158 + "description": "[basx011] conform to rules and exponent will be in permitted range).",
7159 + "canonical_bson": "180000001364006A000000000000000000000000003E3000",
7160 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.6\"}}"
7161 + },
7162 + {
7163 + "description": "[basx012] conform to rules and exponent will be in permitted range).",
7164 + "canonical_bson": "180000001364006D000000000000000000000000003E3000",
7165 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"10.9\"}}"
7166 + },
7167 + {
7168 + "description": "[basx013] conform to rules and exponent will be in permitted range).",
7169 + "canonical_bson": "180000001364006E000000000000000000000000003E3000",
7170 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"11.0\"}}"
7171 + },
7172 + {
7173 + "description": "[basx040] strings without E cannot generate E in result",
7174 + "canonical_bson": "180000001364000C00000000000000000000000000403000",
7175 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12\"}}"
7176 + },
7177 + {
7178 + "description": "[basx190] Numbers with E",
7179 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
7180 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
7181 + },
7182 + {
7183 + "description": "[basx197] Numbers with E",
7184 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
7185 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-0\"}}",
7186 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
7187 + },
7188 + {
7189 + "description": "[basx196] Numbers with E",
7190 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
7191 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-1\"}}",
7192 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
7193 + },
7194 + {
7195 + "description": "[basx198] Numbers with E",
7196 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
7197 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+1\"}}",
7198 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
7199 + },
7200 + {
7201 + "description": "[basx191] Numbers with E",
7202 + "canonical_bson": "18000000136400F104000000000000000000000000143000",
7203 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-20\"}}",
7204 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-19\"}}"
7205 + },
7206 + {
7207 + "description": "[basx203] Numbers with E",
7208 + "canonical_bson": "18000000136400F104000000000000000000000000643000",
7209 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+20\"}}",
7210 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+21\"}}"
7211 + },
7212 + {
7213 + "description": "[basx195] Numbers with E",
7214 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
7215 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-2\"}}",
7216 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
7217 + },
7218 + {
7219 + "description": "[basx199] Numbers with E",
7220 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
7221 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+2\"}}",
7222 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
7223 + },
7224 + {
7225 + "description": "[basx194] Numbers with E",
7226 + "canonical_bson": "18000000136400F104000000000000000000000000363000",
7227 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-3\"}}",
7228 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.01265\"}}"
7229 + },
7230 + {
7231 + "description": "[basx200] Numbers with E",
7232 + "canonical_bson": "18000000136400F104000000000000000000000000423000",
7233 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+3\"}}",
7234 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+4\"}}"
7235 + },
7236 + {
7237 + "description": "[basx193] Numbers with E",
7238 + "canonical_bson": "18000000136400F104000000000000000000000000343000",
7239 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-4\"}}",
7240 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.001265\"}}"
7241 + },
7242 + {
7243 + "description": "[basx201] Numbers with E",
7244 + "canonical_bson": "18000000136400F104000000000000000000000000443000",
7245 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+4\"}}",
7246 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+5\"}}"
7247 + },
7248 + {
7249 + "description": "[basx192] Numbers with E",
7250 + "canonical_bson": "18000000136400F1040000000000000000000000002C3000",
7251 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E-8\"}}",
7252 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-7\"}}"
7253 + },
7254 + {
7255 + "description": "[basx202] Numbers with E",
7256 + "canonical_bson": "18000000136400F1040000000000000000000000004C3000",
7257 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65E+8\"}}",
7258 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+9\"}}"
7259 + },
7260 + {
7261 + "description": "[basx044] strings without E cannot generate E in result",
7262 + "canonical_bson": "18000000136400FC040000000000000000000000003C3000",
7263 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"012.76\"}}",
7264 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}"
7265 + },
7266 + {
7267 + "description": "[basx042] strings without E cannot generate E in result",
7268 + "canonical_bson": "18000000136400FC040000000000000000000000003C3000",
7269 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}"
7270 + },
7271 + {
7272 + "description": "[basx046] strings without E cannot generate E in result",
7273 + "canonical_bson": "180000001364001100000000000000000000000000403000",
7274 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"17.\"}}",
7275 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"17\"}}"
7276 + },
7277 + {
7278 + "description": "[basx049] strings without E cannot generate E in result",
7279 + "canonical_bson": "180000001364002C00000000000000000000000000403000",
7280 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0044\"}}",
7281 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"44\"}}"
7282 + },
7283 + {
7284 + "description": "[basx048] strings without E cannot generate E in result",
7285 + "canonical_bson": "180000001364002C00000000000000000000000000403000",
7286 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"044\"}}",
7287 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"44\"}}"
7288 + },
7289 + {
7290 + "description": "[basx158] Numbers with E",
7291 + "canonical_bson": "180000001364002C00000000000000000000000000523000",
7292 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"44E+9\"}}",
7293 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"4.4E+10\"}}"
7294 + },
7295 + {
7296 + "description": "[basx068] examples",
7297 + "canonical_bson": "180000001364003200000000000000000000000000323000",
7298 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"50E-7\"}}",
7299 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000050\"}}"
7300 + },
7301 + {
7302 + "description": "[basx169] Numbers with E",
7303 + "canonical_bson": "180000001364006400000000000000000000000000523000",
7304 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"100e+009\"}}",
7305 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+11\"}}"
7306 + },
7307 + {
7308 + "description": "[basx167] Numbers with E",
7309 + "canonical_bson": "180000001364006400000000000000000000000000523000",
7310 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"100e+09\"}}",
7311 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+11\"}}"
7312 + },
7313 + {
7314 + "description": "[basx168] Numbers with E",
7315 + "canonical_bson": "180000001364006400000000000000000000000000F43000",
7316 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"100E+90\"}}",
7317 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+92\"}}"
7318 + },
7319 + {
7320 + "description": "[basx166] Numbers with E",
7321 + "canonical_bson": "180000001364006400000000000000000000000000523000",
7322 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"100e+9\"}}",
7323 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+11\"}}"
7324 + },
7325 + {
7326 + "description": "[basx210] Numbers with E",
7327 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
7328 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
7329 + },
7330 + {
7331 + "description": "[basx217] Numbers with E",
7332 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
7333 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-0\"}}",
7334 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
7335 + },
7336 + {
7337 + "description": "[basx216] Numbers with E",
7338 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
7339 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-1\"}}",
7340 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
7341 + },
7342 + {
7343 + "description": "[basx218] Numbers with E",
7344 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
7345 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+1\"}}",
7346 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
7347 + },
7348 + {
7349 + "description": "[basx211] Numbers with E",
7350 + "canonical_bson": "18000000136400F104000000000000000000000000163000",
7351 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-20\"}}",
7352 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-18\"}}"
7353 + },
7354 + {
7355 + "description": "[basx223] Numbers with E",
7356 + "canonical_bson": "18000000136400F104000000000000000000000000663000",
7357 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+20\"}}",
7358 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+22\"}}"
7359 + },
7360 + {
7361 + "description": "[basx215] Numbers with E",
7362 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
7363 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-2\"}}",
7364 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
7365 + },
7366 + {
7367 + "description": "[basx219] Numbers with E",
7368 + "canonical_bson": "18000000136400F104000000000000000000000000423000",
7369 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+2\"}}",
7370 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+4\"}}"
7371 + },
7372 + {
7373 + "description": "[basx214] Numbers with E",
7374 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
7375 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-3\"}}",
7376 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
7377 + },
7378 + {
7379 + "description": "[basx220] Numbers with E",
7380 + "canonical_bson": "18000000136400F104000000000000000000000000443000",
7381 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+3\"}}",
7382 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+5\"}}"
7383 + },
7384 + {
7385 + "description": "[basx213] Numbers with E",
7386 + "canonical_bson": "18000000136400F104000000000000000000000000363000",
7387 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-4\"}}",
7388 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.01265\"}}"
7389 + },
7390 + {
7391 + "description": "[basx221] Numbers with E",
7392 + "canonical_bson": "18000000136400F104000000000000000000000000463000",
7393 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+4\"}}",
7394 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+6\"}}"
7395 + },
7396 + {
7397 + "description": "[basx212] Numbers with E",
7398 + "canonical_bson": "18000000136400F1040000000000000000000000002E3000",
7399 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E-8\"}}",
7400 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000001265\"}}"
7401 + },
7402 + {
7403 + "description": "[basx222] Numbers with E",
7404 + "canonical_bson": "18000000136400F1040000000000000000000000004E3000",
7405 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5E+8\"}}",
7406 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+10\"}}"
7407 + },
7408 + {
7409 + "description": "[basx006] conform to rules and exponent will be in permitted range).",
7410 + "canonical_bson": "18000000136400E803000000000000000000000000403000",
7411 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000\"}}"
7412 + },
7413 + {
7414 + "description": "[basx230] Numbers with E",
7415 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
7416 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
7417 + },
7418 + {
7419 + "description": "[basx237] Numbers with E",
7420 + "canonical_bson": "18000000136400F104000000000000000000000000403000",
7421 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-0\"}}",
7422 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265\"}}"
7423 + },
7424 + {
7425 + "description": "[basx236] Numbers with E",
7426 + "canonical_bson": "18000000136400F1040000000000000000000000003E3000",
7427 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-1\"}}",
7428 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"126.5\"}}"
7429 + },
7430 + {
7431 + "description": "[basx238] Numbers with E",
7432 + "canonical_bson": "18000000136400F104000000000000000000000000423000",
7433 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+1\"}}",
7434 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+4\"}}"
7435 + },
7436 + {
7437 + "description": "[basx231] Numbers with E",
7438 + "canonical_bson": "18000000136400F104000000000000000000000000183000",
7439 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-20\"}}",
7440 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E-17\"}}"
7441 + },
7442 + {
7443 + "description": "[basx243] Numbers with E",
7444 + "canonical_bson": "18000000136400F104000000000000000000000000683000",
7445 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+20\"}}",
7446 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+23\"}}"
7447 + },
7448 + {
7449 + "description": "[basx235] Numbers with E",
7450 + "canonical_bson": "18000000136400F1040000000000000000000000003C3000",
7451 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-2\"}}",
7452 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.65\"}}"
7453 + },
7454 + {
7455 + "description": "[basx239] Numbers with E",
7456 + "canonical_bson": "18000000136400F104000000000000000000000000443000",
7457 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+2\"}}",
7458 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+5\"}}"
7459 + },
7460 + {
7461 + "description": "[basx234] Numbers with E",
7462 + "canonical_bson": "18000000136400F1040000000000000000000000003A3000",
7463 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-3\"}}",
7464 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265\"}}"
7465 + },
7466 + {
7467 + "description": "[basx240] Numbers with E",
7468 + "canonical_bson": "18000000136400F104000000000000000000000000463000",
7469 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+3\"}}",
7470 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+6\"}}"
7471 + },
7472 + {
7473 + "description": "[basx233] Numbers with E",
7474 + "canonical_bson": "18000000136400F104000000000000000000000000383000",
7475 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-4\"}}",
7476 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1265\"}}"
7477 + },
7478 + {
7479 + "description": "[basx241] Numbers with E",
7480 + "canonical_bson": "18000000136400F104000000000000000000000000483000",
7481 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+4\"}}",
7482 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+7\"}}"
7483 + },
7484 + {
7485 + "description": "[basx232] Numbers with E",
7486 + "canonical_bson": "18000000136400F104000000000000000000000000303000",
7487 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E-8\"}}",
7488 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00001265\"}}"
7489 + },
7490 + {
7491 + "description": "[basx242] Numbers with E",
7492 + "canonical_bson": "18000000136400F104000000000000000000000000503000",
7493 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1265E+8\"}}",
7494 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.265E+11\"}}"
7495 + },
7496 + {
7497 + "description": "[basx060] strings without E cannot generate E in result",
7498 + "canonical_bson": "18000000136400185C0ACE00000000000000000000383000",
7499 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.5432\"}}"
7500 + },
7501 + {
7502 + "description": "[basx059] strings without E cannot generate E in result",
7503 + "canonical_bson": "18000000136400F198670C08000000000000000000363000",
7504 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0345678.54321\"}}",
7505 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.54321\"}}"
7506 + },
7507 + {
7508 + "description": "[basx058] strings without E cannot generate E in result",
7509 + "canonical_bson": "180000001364006AF90B7C50000000000000000000343000",
7510 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"345678.543210\"}}"
7511 + },
7512 + {
7513 + "description": "[basx057] strings without E cannot generate E in result",
7514 + "canonical_bson": "180000001364006A19562522020000000000000000343000",
7515 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"2345678.543210\"}}"
7516 + },
7517 + {
7518 + "description": "[basx056] strings without E cannot generate E in result",
7519 + "canonical_bson": "180000001364006AB9C8733A0B0000000000000000343000",
7520 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12345678.543210\"}}"
7521 + },
7522 + {
7523 + "description": "[basx031] conform to rules and exponent will be in permitted range).",
7524 + "canonical_bson": "1800000013640040AF0D8648700000000000000000343000",
7525 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"123456789.000000\"}}"
7526 + },
7527 + {
7528 + "description": "[basx030] conform to rules and exponent will be in permitted range).",
7529 + "canonical_bson": "1800000013640080910F8648700000000000000000343000",
7530 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"123456789.123456\"}}"
7531 + },
7532 + {
7533 + "description": "[basx032] conform to rules and exponent will be in permitted range).",
7534 + "canonical_bson": "1800000013640080910F8648700000000000000000403000",
7535 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"123456789123456\"}}"
7536 + }
7537 + ]
7538 +}
7539 diff --git a/src/tests/spec/json/bson-corpus/decimal128-4.json b/src/tests/spec/json/bson-corpus/decimal128-4.json
7540 new file mode 100644
7541 index 0000000..0957019
7542 --- /dev/null
7543 +++ b/src/tests/spec/json/bson-corpus/decimal128-4.json
7544 @@ -0,0 +1,165 @@
7545 +{
7546 + "description": "Decimal128",
7547 + "bson_type": "0x13",
7548 + "test_key": "d",
7549 + "valid": [
7550 + {
7551 + "description": "[basx023] conform to rules and exponent will be in permitted range).",
7552 + "canonical_bson": "1800000013640001000000000000000000000000003EB000",
7553 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.1\"}}"
7554 + },
7555 +
7556 + {
7557 + "description": "[basx045] strings without E cannot generate E in result",
7558 + "canonical_bson": "1800000013640003000000000000000000000000003A3000",
7559 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+0.003\"}}",
7560 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.003\"}}"
7561 + },
7562 + {
7563 + "description": "[basx610] Zeros",
7564 + "canonical_bson": "1800000013640000000000000000000000000000003E3000",
7565 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".0\"}}",
7566 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0\"}}"
7567 + },
7568 + {
7569 + "description": "[basx612] Zeros",
7570 + "canonical_bson": "1800000013640000000000000000000000000000003EB000",
7571 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-.0\"}}",
7572 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.0\"}}"
7573 + },
7574 + {
7575 + "description": "[basx043] strings without E cannot generate E in result",
7576 + "canonical_bson": "18000000136400FC040000000000000000000000003C3000",
7577 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"+12.76\"}}",
7578 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"12.76\"}}"
7579 + },
7580 + {
7581 + "description": "[basx055] strings without E cannot generate E in result",
7582 + "canonical_bson": "180000001364000500000000000000000000000000303000",
7583 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000005\"}}",
7584 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-8\"}}"
7585 + },
7586 + {
7587 + "description": "[basx054] strings without E cannot generate E in result",
7588 + "canonical_bson": "180000001364000500000000000000000000000000323000",
7589 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0000005\"}}",
7590 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"5E-7\"}}"
7591 + },
7592 + {
7593 + "description": "[basx052] strings without E cannot generate E in result",
7594 + "canonical_bson": "180000001364000500000000000000000000000000343000",
7595 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000005\"}}"
7596 + },
7597 + {
7598 + "description": "[basx051] strings without E cannot generate E in result",
7599 + "canonical_bson": "180000001364000500000000000000000000000000363000",
7600 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"00.00005\"}}",
7601 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00005\"}}"
7602 + },
7603 + {
7604 + "description": "[basx050] strings without E cannot generate E in result",
7605 + "canonical_bson": "180000001364000500000000000000000000000000383000",
7606 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.0005\"}}"
7607 + },
7608 + {
7609 + "description": "[basx047] strings without E cannot generate E in result",
7610 + "canonical_bson": "1800000013640005000000000000000000000000003E3000",
7611 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".5\"}}",
7612 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.5\"}}"
7613 + },
7614 + {
7615 + "description": "[dqbsr431] check rounding modes heeded (Rounded)",
7616 + "canonical_bson": "1800000013640099761CC7B548F377DC80A131C836FE2F00",
7617 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.1111111111111111111111111111123450\"}}",
7618 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.111111111111111111111111111112345\"}}"
7619 + },
7620 + {
7621 + "description": "OK2",
7622 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FC2F00",
7623 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \".100000000000000000000000000000000000000000000000000000000000\"}}",
7624 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.1000000000000000000000000000000000\"}}"
7625 + }
7626 + ],
7627 + "parseErrors": [
7628 + {
7629 + "description": "[basx564] Near-specials (Conversion_syntax)",
7630 + "string": "Infi"
7631 + },
7632 + {
7633 + "description": "[basx565] Near-specials (Conversion_syntax)",
7634 + "string": "Infin"
7635 + },
7636 + {
7637 + "description": "[basx566] Near-specials (Conversion_syntax)",
7638 + "string": "Infini"
7639 + },
7640 + {
7641 + "description": "[basx567] Near-specials (Conversion_syntax)",
7642 + "string": "Infinit"
7643 + },
7644 + {
7645 + "description": "[basx568] Near-specials (Conversion_syntax)",
7646 + "string": "-Infinit"
7647 + },
7648 + {
7649 + "description": "[basx590] some baddies with dots and Es and dots and specials (Conversion_syntax)",
7650 + "string": ".Infinity"
7651 + },
7652 + {
7653 + "description": "[basx562] Near-specials (Conversion_syntax)",
7654 + "string": "NaNq"
7655 + },
7656 + {
7657 + "description": "[basx563] Near-specials (Conversion_syntax)",
7658 + "string": "NaNs"
7659 + },
7660 + {
7661 + "description": "[dqbas939] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
7662 + "string": "-7e10000"
7663 + },
7664 + {
7665 + "description": "[dqbsr534] negatives (Rounded & Inexact)",
7666 + "string": "-1.11111111111111111111111111111234650"
7667 + },
7668 + {
7669 + "description": "[dqbsr535] negatives (Rounded & Inexact)",
7670 + "string": "-1.11111111111111111111111111111234551"
7671 + },
7672 + {
7673 + "description": "[dqbsr533] negatives (Rounded & Inexact)",
7674 + "string": "-1.11111111111111111111111111111234550"
7675 + },
7676 + {
7677 + "description": "[dqbsr532] negatives (Rounded & Inexact)",
7678 + "string": "-1.11111111111111111111111111111234549"
7679 + },
7680 + {
7681 + "description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)",
7682 + "string": "1.11111111111111111111111111111234549"
7683 + },
7684 + {
7685 + "description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)",
7686 + "string": "1.11111111111111111111111111111234550"
7687 + },
7688 + {
7689 + "description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)",
7690 + "string": "1.11111111111111111111111111111234551"
7691 + },
7692 + {
7693 + "description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)",
7694 + "string": "1.11111111111111111111111111111234650"
7695 + },
7696 + {
7697 + "description": "[dqbas938] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
7698 + "string": "7e10000"
7699 + },
7700 + {
7701 + "description": "Inexact rounding#1",
7702 + "string": "100000000000000000000000000000000000000000000000000000000001"
7703 + },
7704 + {
7705 + "description": "Inexact rounding#2",
7706 + "string": "1E-6177"
7707 + }
7708 + ]
7709 +}
7710 diff --git a/src/tests/spec/json/bson-corpus/decimal128-5.json b/src/tests/spec/json/bson-corpus/decimal128-5.json
7711 new file mode 100644
7712 index 0000000..e976eae
7713 --- /dev/null
7714 +++ b/src/tests/spec/json/bson-corpus/decimal128-5.json
7715 @@ -0,0 +1,402 @@
7716 +{
7717 + "description": "Decimal128",
7718 + "bson_type": "0x13",
7719 + "test_key": "d",
7720 + "valid": [
7721 + {
7722 + "description": "[decq035] fold-downs (more below) (Clamped)",
7723 + "canonical_bson": "18000000136400000000807F1BCF85B27059C8A43CFE5F00",
7724 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.23E+6144\"}}",
7725 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.230000000000000000000000000000000E+6144\"}}"
7726 + },
7727 + {
7728 + "description": "[decq037] fold-downs (more below) (Clamped)",
7729 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FE5F00",
7730 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6144\"}}",
7731 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+6144\"}}"
7732 + },
7733 + {
7734 + "description": "[decq077] Nmin and below (Subnormal)",
7735 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04000000",
7736 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.100000000000000000000000000000000E-6143\"}}",
7737 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000000E-6144\"}}"
7738 + },
7739 + {
7740 + "description": "[decq078] Nmin and below (Subnormal)",
7741 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04000000",
7742 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000000E-6144\"}}"
7743 + },
7744 + {
7745 + "description": "[decq079] Nmin and below (Subnormal)",
7746 + "canonical_bson": "180000001364000A00000000000000000000000000000000",
7747 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000000000000000000000000000010E-6143\"}}",
7748 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-6175\"}}"
7749 + },
7750 + {
7751 + "description": "[decq080] Nmin and below (Subnormal)",
7752 + "canonical_bson": "180000001364000A00000000000000000000000000000000",
7753 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E-6175\"}}"
7754 + },
7755 + {
7756 + "description": "[decq081] Nmin and below (Subnormal)",
7757 + "canonical_bson": "180000001364000100000000000000000000000000020000",
7758 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.00000000000000000000000000000001E-6143\"}}",
7759 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6175\"}}"
7760 + },
7761 + {
7762 + "description": "[decq082] Nmin and below (Subnormal)",
7763 + "canonical_bson": "180000001364000100000000000000000000000000020000",
7764 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6175\"}}"
7765 + },
7766 + {
7767 + "description": "[decq083] Nmin and below (Subnormal)",
7768 + "canonical_bson": "180000001364000100000000000000000000000000000000",
7769 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0.000000000000000000000000000000001E-6143\"}}",
7770 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6176\"}}"
7771 + },
7772 + {
7773 + "description": "[decq084] Nmin and below (Subnormal)",
7774 + "canonical_bson": "180000001364000100000000000000000000000000000000",
7775 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6176\"}}"
7776 + },
7777 + {
7778 + "description": "[decq090] underflows cannot be tested for simple copies, check edge cases (Subnormal)",
7779 + "canonical_bson": "180000001364000100000000000000000000000000000000",
7780 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1e-6176\"}}",
7781 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E-6176\"}}"
7782 + },
7783 + {
7784 + "description": "[decq100] underflows cannot be tested for simple copies, check edge cases (Subnormal)",
7785 + "canonical_bson": "18000000136400FFFFFFFF095BC138938D44C64D31000000",
7786 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"999999999999999999999999999999999e-6176\"}}",
7787 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"9.99999999999999999999999999999999E-6144\"}}"
7788 + },
7789 + {
7790 + "description": "[decq130] fold-downs (more below) (Clamped)",
7791 + "canonical_bson": "18000000136400000000807F1BCF85B27059C8A43CFEDF00",
7792 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.23E+6144\"}}",
7793 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.230000000000000000000000000000000E+6144\"}}"
7794 + },
7795 + {
7796 + "description": "[decq132] fold-downs (more below) (Clamped)",
7797 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FEDF00",
7798 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E+6144\"}}",
7799 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.000000000000000000000000000000000E+6144\"}}"
7800 + },
7801 + {
7802 + "description": "[decq177] Nmin and below (Subnormal)",
7803 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04008000",
7804 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.100000000000000000000000000000000E-6143\"}}",
7805 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.00000000000000000000000000000000E-6144\"}}"
7806 + },
7807 + {
7808 + "description": "[decq178] Nmin and below (Subnormal)",
7809 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04008000",
7810 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.00000000000000000000000000000000E-6144\"}}"
7811 + },
7812 + {
7813 + "description": "[decq179] Nmin and below (Subnormal)",
7814 + "canonical_bson": "180000001364000A00000000000000000000000000008000",
7815 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000000000000000000000000000000010E-6143\"}}",
7816 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.0E-6175\"}}"
7817 + },
7818 + {
7819 + "description": "[decq180] Nmin and below (Subnormal)",
7820 + "canonical_bson": "180000001364000A00000000000000000000000000008000",
7821 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1.0E-6175\"}}"
7822 + },
7823 + {
7824 + "description": "[decq181] Nmin and below (Subnormal)",
7825 + "canonical_bson": "180000001364000100000000000000000000000000028000",
7826 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.00000000000000000000000000000001E-6143\"}}",
7827 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6175\"}}"
7828 + },
7829 + {
7830 + "description": "[decq182] Nmin and below (Subnormal)",
7831 + "canonical_bson": "180000001364000100000000000000000000000000028000",
7832 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6175\"}}"
7833 + },
7834 + {
7835 + "description": "[decq183] Nmin and below (Subnormal)",
7836 + "canonical_bson": "180000001364000100000000000000000000000000008000",
7837 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0.000000000000000000000000000000001E-6143\"}}",
7838 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6176\"}}"
7839 + },
7840 + {
7841 + "description": "[decq184] Nmin and below (Subnormal)",
7842 + "canonical_bson": "180000001364000100000000000000000000000000008000",
7843 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6176\"}}"
7844 + },
7845 + {
7846 + "description": "[decq190] underflow edge cases (Subnormal)",
7847 + "canonical_bson": "180000001364000100000000000000000000000000008000",
7848 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1e-6176\"}}",
7849 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-1E-6176\"}}"
7850 + },
7851 + {
7852 + "description": "[decq200] underflow edge cases (Subnormal)",
7853 + "canonical_bson": "18000000136400FFFFFFFF095BC138938D44C64D31008000",
7854 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-999999999999999999999999999999999e-6176\"}}",
7855 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-9.99999999999999999999999999999999E-6144\"}}"
7856 + },
7857 + {
7858 + "description": "[decq400] zeros (Clamped)",
7859 + "canonical_bson": "180000001364000000000000000000000000000000000000",
7860 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-8000\"}}",
7861 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}"
7862 + },
7863 + {
7864 + "description": "[decq401] zeros (Clamped)",
7865 + "canonical_bson": "180000001364000000000000000000000000000000000000",
7866 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6177\"}}",
7867 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}"
7868 + },
7869 + {
7870 + "description": "[decq414] clamped zeros... (Clamped)",
7871 + "canonical_bson": "180000001364000000000000000000000000000000FE5F00",
7872 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6112\"}}",
7873 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}"
7874 + },
7875 + {
7876 + "description": "[decq416] clamped zeros... (Clamped)",
7877 + "canonical_bson": "180000001364000000000000000000000000000000FE5F00",
7878 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6144\"}}",
7879 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}"
7880 + },
7881 + {
7882 + "description": "[decq418] clamped zeros... (Clamped)",
7883 + "canonical_bson": "180000001364000000000000000000000000000000FE5F00",
7884 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+8000\"}}",
7885 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}"
7886 + },
7887 + {
7888 + "description": "[decq420] negative zeros (Clamped)",
7889 + "canonical_bson": "180000001364000000000000000000000000000000008000",
7890 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-8000\"}}",
7891 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}"
7892 + },
7893 + {
7894 + "description": "[decq421] negative zeros (Clamped)",
7895 + "canonical_bson": "180000001364000000000000000000000000000000008000",
7896 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6177\"}}",
7897 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}"
7898 + },
7899 + {
7900 + "description": "[decq434] clamped zeros... (Clamped)",
7901 + "canonical_bson": "180000001364000000000000000000000000000000FEDF00",
7902 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6112\"}}",
7903 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}"
7904 + },
7905 + {
7906 + "description": "[decq436] clamped zeros... (Clamped)",
7907 + "canonical_bson": "180000001364000000000000000000000000000000FEDF00",
7908 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6144\"}}",
7909 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}"
7910 + },
7911 + {
7912 + "description": "[decq438] clamped zeros... (Clamped)",
7913 + "canonical_bson": "180000001364000000000000000000000000000000FEDF00",
7914 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+8000\"}}",
7915 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}"
7916 + },
7917 + {
7918 + "description": "[decq601] fold-down full sequence (Clamped)",
7919 + "canonical_bson": "18000000136400000000000A5BC138938D44C64D31FE5F00",
7920 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6144\"}}",
7921 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+6144\"}}"
7922 + },
7923 + {
7924 + "description": "[decq603] fold-down full sequence (Clamped)",
7925 + "canonical_bson": "180000001364000000000081EFAC855B416D2DEE04FE5F00",
7926 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6143\"}}",
7927 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000000E+6143\"}}"
7928 + },
7929 + {
7930 + "description": "[decq605] fold-down full sequence (Clamped)",
7931 + "canonical_bson": "1800000013640000000080264B91C02220BE377E00FE5F00",
7932 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6142\"}}",
7933 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000000000E+6142\"}}"
7934 + },
7935 + {
7936 + "description": "[decq607] fold-down full sequence (Clamped)",
7937 + "canonical_bson": "1800000013640000000040EAED7446D09C2C9F0C00FE5F00",
7938 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6141\"}}",
7939 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000E+6141\"}}"
7940 + },
7941 + {
7942 + "description": "[decq609] fold-down full sequence (Clamped)",
7943 + "canonical_bson": "18000000136400000000A0CA17726DAE0F1E430100FE5F00",
7944 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6140\"}}",
7945 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000000E+6140\"}}"
7946 + },
7947 + {
7948 + "description": "[decq611] fold-down full sequence (Clamped)",
7949 + "canonical_bson": "18000000136400000000106102253E5ECE4F200000FE5F00",
7950 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6139\"}}",
7951 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000000E+6139\"}}"
7952 + },
7953 + {
7954 + "description": "[decq613] fold-down full sequence (Clamped)",
7955 + "canonical_bson": "18000000136400000000E83C80D09F3C2E3B030000FE5F00",
7956 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6138\"}}",
7957 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000E+6138\"}}"
7958 + },
7959 + {
7960 + "description": "[decq615] fold-down full sequence (Clamped)",
7961 + "canonical_bson": "18000000136400000000E4D20CC8DCD2B752000000FE5F00",
7962 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6137\"}}",
7963 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000000E+6137\"}}"
7964 + },
7965 + {
7966 + "description": "[decq617] fold-down full sequence (Clamped)",
7967 + "canonical_bson": "180000001364000000004A48011416954508000000FE5F00",
7968 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6136\"}}",
7969 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000000E+6136\"}}"
7970 + },
7971 + {
7972 + "description": "[decq619] fold-down full sequence (Clamped)",
7973 + "canonical_bson": "18000000136400000000A1EDCCCE1BC2D300000000FE5F00",
7974 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6135\"}}",
7975 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000E+6135\"}}"
7976 + },
7977 + {
7978 + "description": "[decq621] fold-down full sequence (Clamped)",
7979 + "canonical_bson": "18000000136400000080F64AE1C7022D1500000000FE5F00",
7980 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6134\"}}",
7981 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000000E+6134\"}}"
7982 + },
7983 + {
7984 + "description": "[decq623] fold-down full sequence (Clamped)",
7985 + "canonical_bson": "18000000136400000040B2BAC9E0191E0200000000FE5F00",
7986 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6133\"}}",
7987 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000000E+6133\"}}"
7988 + },
7989 + {
7990 + "description": "[decq625] fold-down full sequence (Clamped)",
7991 + "canonical_bson": "180000001364000000A0DEC5ADC935360000000000FE5F00",
7992 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6132\"}}",
7993 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000E+6132\"}}"
7994 + },
7995 + {
7996 + "description": "[decq627] fold-down full sequence (Clamped)",
7997 + "canonical_bson": "18000000136400000010632D5EC76B050000000000FE5F00",
7998 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6131\"}}",
7999 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000000E+6131\"}}"
8000 + },
8001 + {
8002 + "description": "[decq629] fold-down full sequence (Clamped)",
8003 + "canonical_bson": "180000001364000000E8890423C78A000000000000FE5F00",
8004 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6130\"}}",
8005 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000000E+6130\"}}"
8006 + },
8007 + {
8008 + "description": "[decq631] fold-down full sequence (Clamped)",
8009 + "canonical_bson": "18000000136400000064A7B3B6E00D000000000000FE5F00",
8010 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6129\"}}",
8011 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000E+6129\"}}"
8012 + },
8013 + {
8014 + "description": "[decq633] fold-down full sequence (Clamped)",
8015 + "canonical_bson": "1800000013640000008A5D78456301000000000000FE5F00",
8016 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6128\"}}",
8017 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000000E+6128\"}}"
8018 + },
8019 + {
8020 + "description": "[decq635] fold-down full sequence (Clamped)",
8021 + "canonical_bson": "180000001364000000C16FF2862300000000000000FE5F00",
8022 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6127\"}}",
8023 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000000E+6127\"}}"
8024 + },
8025 + {
8026 + "description": "[decq637] fold-down full sequence (Clamped)",
8027 + "canonical_bson": "180000001364000080C6A47E8D0300000000000000FE5F00",
8028 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6126\"}}",
8029 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000E+6126\"}}"
8030 + },
8031 + {
8032 + "description": "[decq639] fold-down full sequence (Clamped)",
8033 + "canonical_bson": "1800000013640000407A10F35A0000000000000000FE5F00",
8034 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6125\"}}",
8035 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000000E+6125\"}}"
8036 + },
8037 + {
8038 + "description": "[decq641] fold-down full sequence (Clamped)",
8039 + "canonical_bson": "1800000013640000A0724E18090000000000000000FE5F00",
8040 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6124\"}}",
8041 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000000E+6124\"}}"
8042 + },
8043 + {
8044 + "description": "[decq643] fold-down full sequence (Clamped)",
8045 + "canonical_bson": "180000001364000010A5D4E8000000000000000000FE5F00",
8046 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6123\"}}",
8047 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000E+6123\"}}"
8048 + },
8049 + {
8050 + "description": "[decq645] fold-down full sequence (Clamped)",
8051 + "canonical_bson": "1800000013640000E8764817000000000000000000FE5F00",
8052 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6122\"}}",
8053 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000000E+6122\"}}"
8054 + },
8055 + {
8056 + "description": "[decq647] fold-down full sequence (Clamped)",
8057 + "canonical_bson": "1800000013640000E40B5402000000000000000000FE5F00",
8058 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6121\"}}",
8059 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000000E+6121\"}}"
8060 + },
8061 + {
8062 + "description": "[decq649] fold-down full sequence (Clamped)",
8063 + "canonical_bson": "1800000013640000CA9A3B00000000000000000000FE5F00",
8064 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6120\"}}",
8065 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000E+6120\"}}"
8066 + },
8067 + {
8068 + "description": "[decq651] fold-down full sequence (Clamped)",
8069 + "canonical_bson": "1800000013640000E1F50500000000000000000000FE5F00",
8070 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6119\"}}",
8071 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000000E+6119\"}}"
8072 + },
8073 + {
8074 + "description": "[decq653] fold-down full sequence (Clamped)",
8075 + "canonical_bson": "180000001364008096980000000000000000000000FE5F00",
8076 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6118\"}}",
8077 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000000E+6118\"}}"
8078 + },
8079 + {
8080 + "description": "[decq655] fold-down full sequence (Clamped)",
8081 + "canonical_bson": "1800000013640040420F0000000000000000000000FE5F00",
8082 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6117\"}}",
8083 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000E+6117\"}}"
8084 + },
8085 + {
8086 + "description": "[decq657] fold-down full sequence (Clamped)",
8087 + "canonical_bson": "18000000136400A086010000000000000000000000FE5F00",
8088 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6116\"}}",
8089 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00000E+6116\"}}"
8090 + },
8091 + {
8092 + "description": "[decq659] fold-down full sequence (Clamped)",
8093 + "canonical_bson": "180000001364001027000000000000000000000000FE5F00",
8094 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6115\"}}",
8095 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0000E+6115\"}}"
8096 + },
8097 + {
8098 + "description": "[decq661] fold-down full sequence (Clamped)",
8099 + "canonical_bson": "18000000136400E803000000000000000000000000FE5F00",
8100 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6114\"}}",
8101 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000E+6114\"}}"
8102 + },
8103 + {
8104 + "description": "[decq663] fold-down full sequence (Clamped)",
8105 + "canonical_bson": "180000001364006400000000000000000000000000FE5F00",
8106 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6113\"}}",
8107 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.00E+6113\"}}"
8108 + },
8109 + {
8110 + "description": "[decq665] fold-down full sequence (Clamped)",
8111 + "canonical_bson": "180000001364000A00000000000000000000000000FE5F00",
8112 + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1E+6112\"}}",
8113 + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.0E+6112\"}}"
8114 + }
8115 + ]
8116 +}
8117 +
8118 diff --git a/src/tests/spec/json/bson-corpus/decimal128-6.json b/src/tests/spec/json/bson-corpus/decimal128-6.json
8119 new file mode 100644
8120 index 0000000..eba6764
8121 --- /dev/null
8122 +++ b/src/tests/spec/json/bson-corpus/decimal128-6.json
8123 @@ -0,0 +1,131 @@
8124 +{
8125 + "description": "Decimal128",
8126 + "bson_type": "0x13",
8127 + "test_key": "d",
8128 + "parseErrors": [
8129 + {
8130 + "description": "Incomplete Exponent",
8131 + "string": "1e"
8132 + },
8133 + {
8134 + "description": "Exponent at the beginning",
8135 + "string": "E01"
8136 + },
8137 + {
8138 + "description": "Just a decimal place",
8139 + "string": "."
8140 + },
8141 + {
8142 + "description": "2 decimal places",
8143 + "string": "..3"
8144 + },
8145 + {
8146 + "description": "2 decimal places",
8147 + "string": ".13.3"
8148 + },
8149 + {
8150 + "description": "2 decimal places",
8151 + "string": "1..3"
8152 + },
8153 + {
8154 + "description": "2 decimal places",
8155 + "string": "1.3.4"
8156 + },
8157 + {
8158 + "description": "2 decimal places",
8159 + "string": "1.34."
8160 + },
8161 + {
8162 + "description": "Decimal with no digits",
8163 + "string": ".e"
8164 + },
8165 + {
8166 + "description": "2 signs",
8167 + "string": "+-32.4"
8168 + },
8169 + {
8170 + "description": "2 signs",
8171 + "string": "-+32.4"
8172 + },
8173 + {
8174 + "description": "2 negative signs",
8175 + "string": "--32.4"
8176 + },
8177 + {
8178 + "description": "2 negative signs",
8179 + "string": "-32.-4"
8180 + },
8181 + {
8182 + "description": "End in negative sign",
8183 + "string": "32.0-"
8184 + },
8185 + {
8186 + "description": "2 negative signs",
8187 + "string": "32.4E--21"
8188 + },
8189 + {
8190 + "description": "2 negative signs",
8191 + "string": "32.4E-2-1"
8192 + },
8193 + {
8194 + "description": "2 signs",
8195 + "string": "32.4E+-21"
8196 + },
8197 + {
8198 + "description": "Empty string",
8199 + "string": ""
8200 + },
8201 + {
8202 + "description": "leading white space positive number",
8203 + "string": " 1"
8204 + },
8205 + {
8206 + "description": "leading white space negative number",
8207 + "string": " -1"
8208 + },
8209 + {
8210 + "description": "trailing white space",
8211 + "string": "1 "
8212 + },
8213 + {
8214 + "description": "Invalid",
8215 + "string": "E"
8216 + },
8217 + {
8218 + "description": "Invalid",
8219 + "string": "invalid"
8220 + },
8221 + {
8222 + "description": "Invalid",
8223 + "string": "i"
8224 + },
8225 + {
8226 + "description": "Invalid",
8227 + "string": "in"
8228 + },
8229 + {
8230 + "description": "Invalid",
8231 + "string": "-in"
8232 + },
8233 + {
8234 + "description": "Invalid",
8235 + "string": "Na"
8236 + },
8237 + {
8238 + "description": "Invalid",
8239 + "string": "-Na"
8240 + },
8241 + {
8242 + "description": "Invalid",
8243 + "string": "1.23abc"
8244 + },
8245 + {
8246 + "description": "Invalid",
8247 + "string": "1.23abcE+02"
8248 + },
8249 + {
8250 + "description": "Invalid",
8251 + "string": "1.23E+0aabs2"
8252 + }
8253 + ]
8254 +}
8255 diff --git a/src/tests/spec/json/bson-corpus/decimal128-7.json b/src/tests/spec/json/bson-corpus/decimal128-7.json
8256 new file mode 100644
8257 index 0000000..0b78f12
8258 --- /dev/null
8259 +++ b/src/tests/spec/json/bson-corpus/decimal128-7.json
8260 @@ -0,0 +1,327 @@
8261 +{
8262 + "description": "Decimal128",
8263 + "bson_type": "0x13",
8264 + "test_key": "d",
8265 + "parseErrors": [
8266 + {
8267 + "description": "[basx572] Near-specials (Conversion_syntax)",
8268 + "string": "-9Inf"
8269 + },
8270 + {
8271 + "description": "[basx516] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8272 + "string": "-1-"
8273 + },
8274 + {
8275 + "description": "[basx533] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8276 + "string": "0000.."
8277 + },
8278 + {
8279 + "description": "[basx534] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8280 + "string": ".0000."
8281 + },
8282 + {
8283 + "description": "[basx535] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8284 + "string": "00..00"
8285 + },
8286 + {
8287 + "description": "[basx569] Near-specials (Conversion_syntax)",
8288 + "string": "0Inf"
8289 + },
8290 + {
8291 + "description": "[basx571] Near-specials (Conversion_syntax)",
8292 + "string": "-0Inf"
8293 + },
8294 + {
8295 + "description": "[basx575] Near-specials (Conversion_syntax)",
8296 + "string": "0sNaN"
8297 + },
8298 + {
8299 + "description": "[basx503] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8300 + "string": "++1"
8301 + },
8302 + {
8303 + "description": "[basx504] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8304 + "string": "--1"
8305 + },
8306 + {
8307 + "description": "[basx505] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8308 + "string": "-+1"
8309 + },
8310 + {
8311 + "description": "[basx506] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8312 + "string": "+-1"
8313 + },
8314 + {
8315 + "description": "[basx510] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8316 + "string": " +1"
8317 + },
8318 + {
8319 + "description": "[basx513] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8320 + "string": " + 1"
8321 + },
8322 + {
8323 + "description": "[basx514] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8324 + "string": " - 1"
8325 + },
8326 + {
8327 + "description": "[basx501] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8328 + "string": "."
8329 + },
8330 + {
8331 + "description": "[basx502] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8332 + "string": ".."
8333 + },
8334 + {
8335 + "description": "[basx519] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8336 + "string": ""
8337 + },
8338 + {
8339 + "description": "[basx525] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8340 + "string": "e100"
8341 + },
8342 + {
8343 + "description": "[basx549] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8344 + "string": "e+1"
8345 + },
8346 + {
8347 + "description": "[basx577] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8348 + "string": ".e+1"
8349 + },
8350 + {
8351 + "description": "[basx578] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8352 + "string": "+.e+1"
8353 + },
8354 + {
8355 + "description": "[basx581] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8356 + "string": "E+1"
8357 + },
8358 + {
8359 + "description": "[basx582] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8360 + "string": ".E+1"
8361 + },
8362 + {
8363 + "description": "[basx583] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8364 + "string": "+.E+1"
8365 + },
8366 + {
8367 + "description": "[basx579] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8368 + "string": "-.e+"
8369 + },
8370 + {
8371 + "description": "[basx580] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8372 + "string": "-.e"
8373 + },
8374 + {
8375 + "description": "[basx584] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8376 + "string": "-.E+"
8377 + },
8378 + {
8379 + "description": "[basx585] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8380 + "string": "-.E"
8381 + },
8382 + {
8383 + "description": "[basx589] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8384 + "string": "+.Inf"
8385 + },
8386 + {
8387 + "description": "[basx586] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8388 + "string": ".NaN"
8389 + },
8390 + {
8391 + "description": "[basx587] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8392 + "string": "-.NaN"
8393 + },
8394 + {
8395 + "description": "[basx545] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8396 + "string": "ONE"
8397 + },
8398 + {
8399 + "description": "[basx561] Near-specials (Conversion_syntax)",
8400 + "string": "qNaN"
8401 + },
8402 + {
8403 + "description": "[basx573] Near-specials (Conversion_syntax)",
8404 + "string": "-sNa"
8405 + },
8406 + {
8407 + "description": "[basx588] some baddies with dots and Es and dots and specials (Conversion_syntax)",
8408 + "string": "+.sNaN"
8409 + },
8410 + {
8411 + "description": "[basx544] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8412 + "string": "ten"
8413 + },
8414 + {
8415 + "description": "[basx527] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8416 + "string": "u0b65"
8417 + },
8418 + {
8419 + "description": "[basx526] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8420 + "string": "u0e5a"
8421 + },
8422 + {
8423 + "description": "[basx515] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8424 + "string": "x"
8425 + },
8426 + {
8427 + "description": "[basx574] Near-specials (Conversion_syntax)",
8428 + "string": "xNaN"
8429 + },
8430 + {
8431 + "description": "[basx530] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8432 + "string": ".123.5"
8433 + },
8434 + {
8435 + "description": "[basx500] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8436 + "string": "1..2"
8437 + },
8438 + {
8439 + "description": "[basx542] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8440 + "string": "1e1.0"
8441 + },
8442 + {
8443 + "description": "[basx553] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8444 + "string": "1E+1.2.3"
8445 + },
8446 + {
8447 + "description": "[basx543] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8448 + "string": "1e123e"
8449 + },
8450 + {
8451 + "description": "[basx552] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8452 + "string": "1E+1.2"
8453 + },
8454 + {
8455 + "description": "[basx546] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8456 + "string": "1e.1"
8457 + },
8458 + {
8459 + "description": "[basx547] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8460 + "string": "1e1."
8461 + },
8462 + {
8463 + "description": "[basx554] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8464 + "string": "1E++1"
8465 + },
8466 + {
8467 + "description": "[basx555] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8468 + "string": "1E--1"
8469 + },
8470 + {
8471 + "description": "[basx556] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8472 + "string": "1E+-1"
8473 + },
8474 + {
8475 + "description": "[basx557] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8476 + "string": "1E-+1"
8477 + },
8478 + {
8479 + "description": "[basx558] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8480 + "string": "1E'1"
8481 + },
8482 + {
8483 + "description": "[basx559] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8484 + "string": "1E\"1"
8485 + },
8486 + {
8487 + "description": "[basx520] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8488 + "string": "1e-"
8489 + },
8490 + {
8491 + "description": "[basx560] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8492 + "string": "1E"
8493 + },
8494 + {
8495 + "description": "[basx548] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8496 + "string": "1ee"
8497 + },
8498 + {
8499 + "description": "[basx551] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8500 + "string": "1.2.1"
8501 + },
8502 + {
8503 + "description": "[basx550] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8504 + "string": "1.23.4"
8505 + },
8506 + {
8507 + "description": "[basx529] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8508 + "string": "1.34.5"
8509 + },
8510 + {
8511 + "description": "[basx531] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8512 + "string": "01.35."
8513 + },
8514 + {
8515 + "description": "[basx532] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8516 + "string": "01.35-"
8517 + },
8518 + {
8519 + "description": "[basx518] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8520 + "string": "3+"
8521 + },
8522 + {
8523 + "description": "[basx521] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8524 + "string": "7e99999a"
8525 + },
8526 + {
8527 + "description": "[basx570] Near-specials (Conversion_syntax)",
8528 + "string": "9Inf"
8529 + },
8530 + {
8531 + "description": "[basx512] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8532 + "string": "12 "
8533 + },
8534 + {
8535 + "description": "[basx517] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8536 + "string": "12-"
8537 + },
8538 + {
8539 + "description": "[basx507] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8540 + "string": "12e"
8541 + },
8542 + {
8543 + "description": "[basx508] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8544 + "string": "12e++"
8545 + },
8546 + {
8547 + "description": "[basx509] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8548 + "string": "12f4"
8549 + },
8550 + {
8551 + "description": "[basx536] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8552 + "string": "111e*123"
8553 + },
8554 + {
8555 + "description": "[basx537] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8556 + "string": "111e123-"
8557 + },
8558 + {
8559 + "description": "[basx540] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8560 + "string": "111e1*23"
8561 + },
8562 + {
8563 + "description": "[basx538] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8564 + "string": "111e+12+"
8565 + },
8566 + {
8567 + "description": "[basx539] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8568 + "string": "111e1-3-"
8569 + },
8570 + {
8571 + "description": "[basx541] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8572 + "string": "111E1e+3"
8573 + },
8574 + {
8575 + "description": "[basx528] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8576 + "string": "123,65"
8577 + },
8578 + {
8579 + "description": "[basx523] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8580 + "string": "7e12356789012x"
8581 + },
8582 + {
8583 + "description": "[basx522] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
8584 + "string": "7e123567890x"
8585 + }
8586 + ]
8587 +}
8588 diff --git a/src/tests/spec/json/bson-corpus/document.json b/src/tests/spec/json/bson-corpus/document.json
8589 new file mode 100644
8590 index 0000000..698e7ae
8591 --- /dev/null
8592 +++ b/src/tests/spec/json/bson-corpus/document.json
8593 @@ -0,0 +1,60 @@
8594 +{
8595 + "description": "Document type (sub-documents)",
8596 + "bson_type": "0x03",
8597 + "test_key": "x",
8598 + "valid": [
8599 + {
8600 + "description": "Empty subdoc",
8601 + "canonical_bson": "0D000000037800050000000000",
8602 + "canonical_extjson": "{\"x\" : {}}"
8603 + },
8604 + {
8605 + "description": "Empty-string key subdoc",
8606 + "canonical_bson": "150000000378000D00000002000200000062000000",
8607 + "canonical_extjson": "{\"x\" : {\"\" : \"b\"}}"
8608 + },
8609 + {
8610 + "description": "Single-character key subdoc",
8611 + "canonical_bson": "160000000378000E0000000261000200000062000000",
8612 + "canonical_extjson": "{\"x\" : {\"a\" : \"b\"}}"
8613 + },
8614 + {
8615 + "description": "Dollar-prefixed key in sub-document",
8616 + "canonical_bson": "170000000378000F000000022461000200000062000000",
8617 + "canonical_extjson": "{\"x\" : {\"$a\" : \"b\"}}"
8618 + },
8619 + {
8620 + "description": "Dollar as key in sub-document",
8621 + "canonical_bson": "160000000378000E0000000224000200000061000000",
8622 + "canonical_extjson": "{\"x\" : {\"$\" : \"a\"}}"
8623 + },
8624 + {
8625 + "description": "Dotted key in sub-document",
8626 + "canonical_bson": "180000000378001000000002612E62000200000063000000",
8627 + "canonical_extjson": "{\"x\" : {\"a.b\" : \"c\"}}"
8628 + },
8629 + {
8630 + "description": "Dot as key in sub-document",
8631 + "canonical_bson": "160000000378000E000000022E000200000061000000",
8632 + "canonical_extjson": "{\"x\" : {\".\" : \"a\"}}"
8633 + }
8634 + ],
8635 + "decodeErrors": [
8636 + {
8637 + "description": "Subdocument length too long: eats outer terminator",
8638 + "bson": "1800000003666F6F000F0000001062617200FFFFFF7F0000"
8639 + },
8640 + {
8641 + "description": "Subdocument length too short: leaks terminator",
8642 + "bson": "1500000003666F6F000A0000000862617200010000"
8643 + },
8644 + {
8645 + "description": "Invalid subdocument: bad string length in field",
8646 + "bson": "1C00000003666F6F001200000002626172000500000062617A000000"
8647 + },
8648 + {
8649 + "description": "Null byte in sub-document key",
8650 + "bson": "150000000378000D00000010610000010000000000"
8651 + }
8652 + ]
8653 +}
8654 diff --git a/src/tests/spec/json/bson-corpus/double.json b/src/tests/spec/json/bson-corpus/double.json
8655 new file mode 100644
8656 index 0000000..d5b8fb3
8657 --- /dev/null
8658 +++ b/src/tests/spec/json/bson-corpus/double.json
8659 @@ -0,0 +1,87 @@
8660 +{
8661 + "description": "Double type",
8662 + "bson_type": "0x01",
8663 + "test_key": "d",
8664 + "valid": [
8665 + {
8666 + "description": "+1.0",
8667 + "canonical_bson": "10000000016400000000000000F03F00",
8668 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.0\"}}",
8669 + "relaxed_extjson": "{\"d\" : 1.0}"
8670 + },
8671 + {
8672 + "description": "-1.0",
8673 + "canonical_bson": "10000000016400000000000000F0BF00",
8674 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.0\"}}",
8675 + "relaxed_extjson": "{\"d\" : -1.0}"
8676 + },
8677 + {
8678 + "description": "+1.0001220703125",
8679 + "canonical_bson": "10000000016400000000008000F03F00",
8680 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.0001220703125\"}}",
8681 + "relaxed_extjson": "{\"d\" : 1.0001220703125}"
8682 + },
8683 + {
8684 + "description": "-1.0001220703125",
8685 + "canonical_bson": "10000000016400000000008000F0BF00",
8686 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.0001220703125\"}}",
8687 + "relaxed_extjson": "{\"d\" : -1.0001220703125}"
8688 + },
8689 + {
8690 + "description": "1.2345678921232E+18",
8691 + "canonical_bson": "100000000164002a1bf5f41022b14300",
8692 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"1.2345678921232E+18\"}}",
8693 + "relaxed_extjson": "{\"d\" : 1.2345678921232E+18}"
8694 + },
8695 + {
8696 + "description": "-1.2345678921232E+18",
8697 + "canonical_bson": "100000000164002a1bf5f41022b1c300",
8698 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-1.2345678921232E+18\"}}",
8699 + "relaxed_extjson": "{\"d\" : -1.2345678921232E+18}"
8700 + },
8701 + {
8702 + "description": "0.0",
8703 + "canonical_bson": "10000000016400000000000000000000",
8704 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"0.0\"}}",
8705 + "relaxed_extjson": "{\"d\" : 0.0}"
8706 + },
8707 + {
8708 + "description": "-0.0",
8709 + "canonical_bson": "10000000016400000000000000008000",
8710 + "canonical_extjson": "{\"d\" : {\"$numberDouble\": \"-0.0\"}}",
8711 + "relaxed_extjson": "{\"d\" : -0.0}"
8712 + },
8713 + {
8714 + "description": "NaN",
8715 + "canonical_bson": "10000000016400000000000000F87F00",
8716 + "canonical_extjson": "{\"d\": {\"$numberDouble\": \"NaN\"}}",
8717 + "relaxed_extjson": "{\"d\": {\"$numberDouble\": \"NaN\"}}",
8718 + "lossy": true
8719 + },
8720 + {
8721 + "description": "NaN with payload",
8722 + "canonical_bson": "10000000016400120000000000F87F00",
8723 + "canonical_extjson": "{\"d\": {\"$numberDouble\": \"NaN\"}}",
8724 + "relaxed_extjson": "{\"d\": {\"$numberDouble\": \"NaN\"}}",
8725 + "lossy": true
8726 + },
8727 + {
8728 + "description": "Inf",
8729 + "canonical_bson": "10000000016400000000000000F07F00",
8730 + "canonical_extjson": "{\"d\": {\"$numberDouble\": \"Infinity\"}}",
8731 + "relaxed_extjson": "{\"d\": {\"$numberDouble\": \"Infinity\"}}"
8732 + },
8733 + {
8734 + "description": "-Inf",
8735 + "canonical_bson": "10000000016400000000000000F0FF00",
8736 + "canonical_extjson": "{\"d\": {\"$numberDouble\": \"-Infinity\"}}",
8737 + "relaxed_extjson": "{\"d\": {\"$numberDouble\": \"-Infinity\"}}"
8738 + }
8739 + ],
8740 + "decodeErrors": [
8741 + {
8742 + "description": "double truncated",
8743 + "bson": "0B0000000164000000F03F00"
8744 + }
8745 + ]
8746 +}
8747 diff --git a/src/tests/spec/json/bson-corpus/int32.json b/src/tests/spec/json/bson-corpus/int32.json
8748 new file mode 100644
8749 index 0000000..1353fc3
8750 --- /dev/null
8751 +++ b/src/tests/spec/json/bson-corpus/int32.json
8752 @@ -0,0 +1,43 @@
8753 +{
8754 + "description": "Int32 type",
8755 + "bson_type": "0x10",
8756 + "test_key": "i",
8757 + "valid": [
8758 + {
8759 + "description": "MinValue",
8760 + "canonical_bson": "0C0000001069000000008000",
8761 + "canonical_extjson": "{\"i\" : {\"$numberInt\": \"-2147483648\"}}",
8762 + "relaxed_extjson": "{\"i\" : -2147483648}"
8763 + },
8764 + {
8765 + "description": "MaxValue",
8766 + "canonical_bson": "0C000000106900FFFFFF7F00",
8767 + "canonical_extjson": "{\"i\" : {\"$numberInt\": \"2147483647\"}}",
8768 + "relaxed_extjson": "{\"i\" : 2147483647}"
8769 + },
8770 + {
8771 + "description": "-1",
8772 + "canonical_bson": "0C000000106900FFFFFFFF00",
8773 + "canonical_extjson": "{\"i\" : {\"$numberInt\": \"-1\"}}",
8774 + "relaxed_extjson": "{\"i\" : -1}"
8775 + },
8776 + {
8777 + "description": "0",
8778 + "canonical_bson": "0C0000001069000000000000",
8779 + "canonical_extjson": "{\"i\" : {\"$numberInt\": \"0\"}}",
8780 + "relaxed_extjson": "{\"i\" : 0}"
8781 + },
8782 + {
8783 + "description": "1",
8784 + "canonical_bson": "0C0000001069000100000000",
8785 + "canonical_extjson": "{\"i\" : {\"$numberInt\": \"1\"}}",
8786 + "relaxed_extjson": "{\"i\" : 1}"
8787 + }
8788 + ],
8789 + "decodeErrors": [
8790 + {
8791 + "description": "Bad int32 field length",
8792 + "bson": "090000001061000500"
8793 + }
8794 + ]
8795 +}
8796 diff --git a/src/tests/spec/json/bson-corpus/int64.json b/src/tests/spec/json/bson-corpus/int64.json
8797 new file mode 100644
8798 index 0000000..91f4abf
8799 --- /dev/null
8800 +++ b/src/tests/spec/json/bson-corpus/int64.json
8801 @@ -0,0 +1,43 @@
8802 +{
8803 + "description": "Int64 type",
8804 + "bson_type": "0x12",
8805 + "test_key": "a",
8806 + "valid": [
8807 + {
8808 + "description": "MinValue",
8809 + "canonical_bson": "10000000126100000000000000008000",
8810 + "canonical_extjson": "{\"a\" : {\"$numberLong\" : \"-9223372036854775808\"}}",
8811 + "relaxed_extjson": "{\"a\" : -9223372036854775808}"
8812 + },
8813 + {
8814 + "description": "MaxValue",
8815 + "canonical_bson": "10000000126100FFFFFFFFFFFFFF7F00",
8816 + "canonical_extjson": "{\"a\" : {\"$numberLong\" : \"9223372036854775807\"}}",
8817 + "relaxed_extjson": "{\"a\" : 9223372036854775807}"
8818 + },
8819 + {
8820 + "description": "-1",
8821 + "canonical_bson": "10000000126100FFFFFFFFFFFFFFFF00",
8822 + "canonical_extjson": "{\"a\" : {\"$numberLong\" : \"-1\"}}",
8823 + "relaxed_extjson": "{\"a\" : -1}"
8824 + },
8825 + {
8826 + "description": "0",
8827 + "canonical_bson": "10000000126100000000000000000000",
8828 + "canonical_extjson": "{\"a\" : {\"$numberLong\" : \"0\"}}",
8829 + "relaxed_extjson": "{\"a\" : 0}"
8830 + },
8831 + {
8832 + "description": "1",
8833 + "canonical_bson": "10000000126100010000000000000000",
8834 + "canonical_extjson": "{\"a\" : {\"$numberLong\" : \"1\"}}",
8835 + "relaxed_extjson": "{\"a\" : 1}"
8836 + }
8837 + ],
8838 + "decodeErrors": [
8839 + {
8840 + "description": "int64 field truncated",
8841 + "bson": "0C0000001261001234567800"
8842 + }
8843 + ]
8844 +}
8845 diff --git a/src/tests/spec/json/bson-corpus/maxkey.json b/src/tests/spec/json/bson-corpus/maxkey.json
8846 new file mode 100644
8847 index 0000000..67cad6d
8848 --- /dev/null
8849 +++ b/src/tests/spec/json/bson-corpus/maxkey.json
8850 @@ -0,0 +1,12 @@
8851 +{
8852 + "description": "Maxkey type",
8853 + "bson_type": "0x7F",
8854 + "test_key": "a",
8855 + "valid": [
8856 + {
8857 + "description": "Maxkey",
8858 + "canonical_bson": "080000007F610000",
8859 + "canonical_extjson": "{\"a\" : {\"$maxKey\" : 1}}"
8860 + }
8861 + ]
8862 +}
8863 diff --git a/src/tests/spec/json/bson-corpus/minkey.json b/src/tests/spec/json/bson-corpus/minkey.json
8864 new file mode 100644
8865 index 0000000..8adee45
8866 --- /dev/null
8867 +++ b/src/tests/spec/json/bson-corpus/minkey.json
8868 @@ -0,0 +1,12 @@
8869 +{
8870 + "description": "Minkey type",
8871 + "bson_type": "0xFF",
8872 + "test_key": "a",
8873 + "valid": [
8874 + {
8875 + "description": "Minkey",
8876 + "canonical_bson": "08000000FF610000",
8877 + "canonical_extjson": "{\"a\" : {\"$minKey\" : 1}}"
8878 + }
8879 + ]
8880 +}
8881 diff --git a/src/tests/spec/json/bson-corpus/multi-type-deprecated.json b/src/tests/spec/json/bson-corpus/multi-type-deprecated.json
8882 new file mode 100644
8883 index 0000000..665f388
8884 --- /dev/null
8885 +++ b/src/tests/spec/json/bson-corpus/multi-type-deprecated.json
8886 @@ -0,0 +1,15 @@
8887 +{
8888 + "description": "Multiple types within the same document",
8889 + "bson_type": "0x00",
8890 + "deprecated": true,
8891 + "valid": [
8892 + {
8893 + "description": "All BSON types",
8894 + "canonical_bson": "38020000075F69640057E193D7A9CC81B4027498B50E53796D626F6C000700000073796D626F6C0002537472696E670007000000737472696E670010496E743332002A00000012496E743634002A0000000000000001446F75626C6500000000000000F0BF0542696E617279001000000003A34C38F7C3ABEDC8A37814A992AB8DB60542696E61727955736572446566696E656400050000008001020304050D436F6465000E00000066756E6374696F6E2829207B7D000F436F64655769746853636F7065001B0000000E00000066756E6374696F6E2829207B7D00050000000003537562646F63756D656E74001200000002666F6F0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696D657374616D7000010000002A0000000B5265676578007061747465726E0000094461746574696D6545706F6368000000000000000000094461746574696D65506F73697469766500FFFFFF7F00000000094461746574696D654E656761746976650000000080FFFFFFFF085472756500010846616C736500000C4442506F696E746572000B000000636F6C6C656374696F6E0057E193D7A9CC81B4027498B1034442526566003D0000000224726566000B000000636F6C6C656374696F6E00072469640057FD71E96E32AB4225B723FB02246462000900000064617461626173650000FF4D696E6B6579007F4D61786B6579000A4E756C6C0006556E646566696E65640000",
8895 + "converted_bson": "48020000075f69640057e193d7a9cc81b4027498b50253796d626f6c000700000073796d626f6c0002537472696e670007000000737472696e670010496e743332002a00000012496e743634002a0000000000000001446f75626c6500000000000000f0bf0542696e617279001000000003a34c38f7c3abedc8a37814a992ab8db60542696e61727955736572446566696e656400050000008001020304050d436f6465000e00000066756e6374696f6e2829207b7d000f436f64655769746853636f7065001b0000000e00000066756e6374696f6e2829207b7d00050000000003537562646f63756d656e74001200000002666f6f0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696d657374616d7000010000002a0000000b5265676578007061747465726e0000094461746574696d6545706f6368000000000000000000094461746574696d65506f73697469766500ffffff7f00000000094461746574696d654e656761746976650000000080ffffffff085472756500010846616c73650000034442506f696e746572002b0000000224726566000b000000636f6c6c656374696f6e00072469640057e193d7a9cc81b4027498b100034442526566003d0000000224726566000b000000636f6c6c656374696f6e00072469640057fd71e96e32ab4225b723fb02246462000900000064617461626173650000ff4d696e6b6579007f4d61786b6579000a4e756c6c000a556e646566696e65640000",
8896 + "canonical_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": {\"$symbol\": \"symbol\"}, \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$dbPointer\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": {\"$undefined\": true}}",
8897 + "converted_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": \"symbol\", \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": null}"
8898 + }
8899 + ]
8900 +}
8901 +
8902 diff --git a/src/tests/spec/json/bson-corpus/multi-type.json b/src/tests/spec/json/bson-corpus/multi-type.json
8903 new file mode 100644
8904 index 0000000..1e1d557
8905 --- /dev/null
8906 +++ b/src/tests/spec/json/bson-corpus/multi-type.json
8907 @@ -0,0 +1,11 @@
8908 +{
8909 + "description": "Multiple types within the same document",
8910 + "bson_type": "0x00",
8911 + "valid": [
8912 + {
8913 + "description": "All BSON types",
8914 + "canonical_bson": "F4010000075F69640057E193D7A9CC81B4027498B502537472696E670007000000737472696E670010496E743332002A00000012496E743634002A0000000000000001446F75626C6500000000000000F0BF0542696E617279001000000003A34C38F7C3ABEDC8A37814A992AB8DB60542696E61727955736572446566696E656400050000008001020304050D436F6465000E00000066756E6374696F6E2829207B7D000F436F64655769746853636F7065001B0000000E00000066756E6374696F6E2829207B7D00050000000003537562646F63756D656E74001200000002666F6F0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696D657374616D7000010000002A0000000B5265676578007061747465726E0000094461746574696D6545706F6368000000000000000000094461746574696D65506F73697469766500FFFFFF7F00000000094461746574696D654E656761746976650000000080FFFFFFFF085472756500010846616C73650000034442526566003D0000000224726566000B000000636F6C6C656374696F6E00072469640057FD71E96E32AB4225B723FB02246462000900000064617461626173650000FF4D696E6B6579007F4D61786B6579000A4E756C6C0000",
8915 + "canonical_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null}"
8916 + }
8917 + ]
8918 +}
8919 diff --git a/src/tests/spec/json/bson-corpus/null.json b/src/tests/spec/json/bson-corpus/null.json
8920 new file mode 100644
8921 index 0000000..f9b2694
8922 --- /dev/null
8923 +++ b/src/tests/spec/json/bson-corpus/null.json
8924 @@ -0,0 +1,12 @@
8925 +{
8926 + "description": "Null type",
8927 + "bson_type": "0x0A",
8928 + "test_key": "a",
8929 + "valid": [
8930 + {
8931 + "description": "Null",
8932 + "canonical_bson": "080000000A610000",
8933 + "canonical_extjson": "{\"a\" : null}"
8934 + }
8935 + ]
8936 +}
8937 diff --git a/src/tests/spec/json/bson-corpus/oid.json b/src/tests/spec/json/bson-corpus/oid.json
8938 new file mode 100644
8939 index 0000000..14e9caf
8940 --- /dev/null
8941 +++ b/src/tests/spec/json/bson-corpus/oid.json
8942 @@ -0,0 +1,28 @@
8943 +{
8944 + "description": "ObjectId",
8945 + "bson_type": "0x07",
8946 + "test_key": "a",
8947 + "valid": [
8948 + {
8949 + "description": "All zeroes",
8950 + "canonical_bson": "1400000007610000000000000000000000000000",
8951 + "canonical_extjson": "{\"a\" : {\"$oid\" : \"000000000000000000000000\"}}"
8952 + },
8953 + {
8954 + "description": "All ones",
8955 + "canonical_bson": "14000000076100FFFFFFFFFFFFFFFFFFFFFFFF00",
8956 + "canonical_extjson": "{\"a\" : {\"$oid\" : \"ffffffffffffffffffffffff\"}}"
8957 + },
8958 + {
8959 + "description": "Random",
8960 + "canonical_bson": "1400000007610056E1FC72E0C917E9C471416100",
8961 + "canonical_extjson": "{\"a\" : {\"$oid\" : \"56e1fc72e0c917e9c4714161\"}}"
8962 + }
8963 + ],
8964 + "decodeErrors": [
8965 + {
8966 + "description": "OID truncated",
8967 + "bson": "1200000007610056E1FC72E0C917E9C471"
8968 + }
8969 + ]
8970 +}
8971 diff --git a/src/tests/spec/json/bson-corpus/regex.json b/src/tests/spec/json/bson-corpus/regex.json
8972 new file mode 100644
8973 index 0000000..2238021
8974 --- /dev/null
8975 +++ b/src/tests/spec/json/bson-corpus/regex.json
8976 @@ -0,0 +1,65 @@
8977 +{
8978 + "description": "Regular Expression type",
8979 + "bson_type": "0x0B",
8980 + "test_key": "a",
8981 + "valid": [
8982 + {
8983 + "description": "empty regex with no options",
8984 + "canonical_bson": "0A0000000B6100000000",
8985 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"\", \"options\" : \"\"}}}"
8986 + },
8987 + {
8988 + "description": "regex without options",
8989 + "canonical_bson": "0D0000000B6100616263000000",
8990 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"\"}}}"
8991 + },
8992 + {
8993 + "description": "regex with options",
8994 + "canonical_bson": "0F0000000B610061626300696D0000",
8995 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}"
8996 + },
8997 + {
8998 + "description": "regex with options (keys reversed)",
8999 + "canonical_bson": "0F0000000B610061626300696D0000",
9000 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"im\"}}}",
9001 + "degenerate_extjson": "{\"a\" : {\"$regularExpression\" : {\"options\" : \"im\", \"pattern\": \"abc\"}}}"
9002 + },
9003 + {
9004 + "description": "regex with slash",
9005 + "canonical_bson": "110000000B610061622F636400696D0000",
9006 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab/cd\", \"options\" : \"im\"}}}"
9007 + },
9008 + {
9009 + "description": "flags not alphabetized",
9010 + "degenerate_bson": "100000000B6100616263006D69780000",
9011 + "canonical_bson": "100000000B610061626300696D780000",
9012 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"imx\"}}}",
9013 + "degenerate_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"abc\", \"options\" : \"mix\"}}}"
9014 + },
9015 + {
9016 + "description" : "Required escapes",
9017 + "canonical_bson" : "100000000B610061625C226162000000",
9018 + "canonical_extjson": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"ab\\\\\\\"ab\", \"options\" : \"\"}}}"
9019 + },
9020 + {
9021 + "description" : "Regular expression as value of $regex query operator",
9022 + "canonical_bson" : "180000000B247265676578007061747465726E0069780000",
9023 + "canonical_extjson": "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"ix\"}}}"
9024 + },
9025 + {
9026 + "description" : "Regular expression as value of $regex query operator with $options",
9027 + "canonical_bson" : "270000000B247265676578007061747465726E000002246F7074696F6E73000300000069780000",
9028 + "canonical_extjson": "{\"$regex\" : {\"$regularExpression\" : { \"pattern\": \"pattern\", \"options\" : \"\"}}, \"$options\" : \"ix\"}"
9029 + }
9030 + ],
9031 + "decodeErrors": [
9032 + {
9033 + "description": "Null byte in pattern string",
9034 + "bson": "0F0000000B610061006300696D0000"
9035 + },
9036 + {
9037 + "description": "Null byte in flags string",
9038 + "bson": "100000000B61006162630069006D0000"
9039 + }
9040 + ]
9041 +}
9042 diff --git a/src/tests/spec/json/bson-corpus/string.json b/src/tests/spec/json/bson-corpus/string.json
9043 new file mode 100644
9044 index 0000000..148334d
9045 --- /dev/null
9046 +++ b/src/tests/spec/json/bson-corpus/string.json
9047 @@ -0,0 +1,72 @@
9048 +{
9049 + "description": "String",
9050 + "bson_type": "0x02",
9051 + "test_key": "a",
9052 + "valid": [
9053 + {
9054 + "description": "Empty string",
9055 + "canonical_bson": "0D000000026100010000000000",
9056 + "canonical_extjson": "{\"a\" : \"\"}"
9057 + },
9058 + {
9059 + "description": "Single character",
9060 + "canonical_bson": "0E00000002610002000000620000",
9061 + "canonical_extjson": "{\"a\" : \"b\"}"
9062 + },
9063 + {
9064 + "description": "Multi-character",
9065 + "canonical_bson": "190000000261000D0000006162616261626162616261620000",
9066 + "canonical_extjson": "{\"a\" : \"abababababab\"}"
9067 + },
9068 + {
9069 + "description": "two-byte UTF-8 (\u00e9)",
9070 + "canonical_bson": "190000000261000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
9071 + "canonical_extjson": "{\"a\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}"
9072 + },
9073 + {
9074 + "description": "three-byte UTF-8 (\u2606)",
9075 + "canonical_bson": "190000000261000D000000E29886E29886E29886E298860000",
9076 + "canonical_extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}"
9077 + },
9078 + {
9079 + "description": "Embedded nulls",
9080 + "canonical_bson": "190000000261000D0000006162006261620062616261620000",
9081 + "canonical_extjson": "{\"a\" : \"ab\\u0000bab\\u0000babab\"}"
9082 + },
9083 + {
9084 + "description": "Required escapes",
9085 + "canonical_bson" : "320000000261002600000061625C220102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F61620000",
9086 + "canonical_extjson" : "{\"a\":\"ab\\\\\\\"\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001fab\"}"
9087 + }
9088 + ],
9089 + "decodeErrors": [
9090 + {
9091 + "description": "bad string length: 0 (but no 0x00 either)",
9092 + "bson": "0C0000000261000000000000"
9093 + },
9094 + {
9095 + "description": "bad string length: -1",
9096 + "bson": "0C000000026100FFFFFFFF00"
9097 + },
9098 + {
9099 + "description": "bad string length: eats terminator",
9100 + "bson": "10000000026100050000006200620000"
9101 + },
9102 + {
9103 + "description": "bad string length: longer than rest of document",
9104 + "bson": "120000000200FFFFFF00666F6F6261720000"
9105 + },
9106 + {
9107 + "description": "string is not null-terminated",
9108 + "bson": "1000000002610004000000616263FF00"
9109 + },
9110 + {
9111 + "description": "empty string, but extra null",
9112 + "bson": "0E00000002610001000000000000"
9113 + },
9114 + {
9115 + "description": "invalid UTF-8",
9116 + "bson": "0E00000002610002000000E90000"
9117 + }
9118 + ]
9119 +}
9120 diff --git a/src/tests/spec/json/bson-corpus/symbol.json b/src/tests/spec/json/bson-corpus/symbol.json
9121 new file mode 100644
9122 index 0000000..3dd3577
9123 --- /dev/null
9124 +++ b/src/tests/spec/json/bson-corpus/symbol.json
9125 @@ -0,0 +1,80 @@
9126 +{
9127 + "description": "Symbol",
9128 + "bson_type": "0x0E",
9129 + "deprecated": true,
9130 + "test_key": "a",
9131 + "valid": [
9132 + {
9133 + "description": "Empty string",
9134 + "canonical_bson": "0D0000000E6100010000000000",
9135 + "canonical_extjson": "{\"a\": {\"$symbol\": \"\"}}",
9136 + "converted_bson": "0D000000026100010000000000",
9137 + "converted_extjson": "{\"a\": \"\"}"
9138 + },
9139 + {
9140 + "description": "Single character",
9141 + "canonical_bson": "0E0000000E610002000000620000",
9142 + "canonical_extjson": "{\"a\": {\"$symbol\": \"b\"}}",
9143 + "converted_bson": "0E00000002610002000000620000",
9144 + "converted_extjson": "{\"a\": \"b\"}"
9145 + },
9146 + {
9147 + "description": "Multi-character",
9148 + "canonical_bson": "190000000E61000D0000006162616261626162616261620000",
9149 + "canonical_extjson": "{\"a\": {\"$symbol\": \"abababababab\"}}",
9150 + "converted_bson": "190000000261000D0000006162616261626162616261620000",
9151 + "converted_extjson": "{\"a\": \"abababababab\"}"
9152 + },
9153 + {
9154 + "description": "two-byte UTF-8 (\u00e9)",
9155 + "canonical_bson": "190000000E61000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
9156 + "canonical_extjson": "{\"a\": {\"$symbol\": \"éééééé\"}}",
9157 + "converted_bson": "190000000261000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
9158 + "converted_extjson": "{\"a\": \"éééééé\"}"
9159 + },
9160 + {
9161 + "description": "three-byte UTF-8 (\u2606)",
9162 + "canonical_bson": "190000000E61000D000000E29886E29886E29886E298860000",
9163 + "canonical_extjson": "{\"a\": {\"$symbol\": \"☆☆☆☆\"}}",
9164 + "converted_bson": "190000000261000D000000E29886E29886E29886E298860000",
9165 + "converted_extjson": "{\"a\": \"☆☆☆☆\"}"
9166 + },
9167 + {
9168 + "description": "Embedded nulls",
9169 + "canonical_bson": "190000000E61000D0000006162006261620062616261620000",
9170 + "canonical_extjson": "{\"a\": {\"$symbol\": \"ab\\u0000bab\\u0000babab\"}}",
9171 + "converted_bson": "190000000261000D0000006162006261620062616261620000",
9172 + "converted_extjson": "{\"a\": \"ab\\u0000bab\\u0000babab\"}"
9173 + }
9174 + ],
9175 + "decodeErrors": [
9176 + {
9177 + "description": "bad symbol length: 0 (but no 0x00 either)",
9178 + "bson": "0C0000000E61000000000000"
9179 + },
9180 + {
9181 + "description": "bad symbol length: -1",
9182 + "bson": "0C0000000E6100FFFFFFFF00"
9183 + },
9184 + {
9185 + "description": "bad symbol length: eats terminator",
9186 + "bson": "100000000E6100050000006200620000"
9187 + },
9188 + {
9189 + "description": "bad symbol length: longer than rest of document",
9190 + "bson": "120000000E00FFFFFF00666F6F6261720000"
9191 + },
9192 + {
9193 + "description": "symbol is not null-terminated",
9194 + "bson": "100000000E610004000000616263FF00"
9195 + },
9196 + {
9197 + "description": "empty symbol, but extra null",
9198 + "bson": "0E0000000E610001000000000000"
9199 + },
9200 + {
9201 + "description": "invalid UTF-8",
9202 + "bson": "0E0000000E610002000000E90000"
9203 + }
9204 + ]
9205 +}
9206 diff --git a/src/tests/spec/json/bson-corpus/timestamp.json b/src/tests/spec/json/bson-corpus/timestamp.json
9207 new file mode 100644
9208 index 0000000..6f46564
9209 --- /dev/null
9210 +++ b/src/tests/spec/json/bson-corpus/timestamp.json
9211 @@ -0,0 +1,34 @@
9212 +{
9213 + "description": "Timestamp type",
9214 + "bson_type": "0x11",
9215 + "test_key": "a",
9216 + "valid": [
9217 + {
9218 + "description": "Timestamp: (123456789, 42)",
9219 + "canonical_bson": "100000001161002A00000015CD5B0700",
9220 + "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 123456789, \"i\" : 42} } }"
9221 + },
9222 + {
9223 + "description": "Timestamp: (123456789, 42) (keys reversed)",
9224 + "canonical_bson": "100000001161002A00000015CD5B0700",
9225 + "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 123456789, \"i\" : 42} } }",
9226 + "degenerate_extjson": "{\"a\" : {\"$timestamp\" : {\"i\" : 42, \"t\" : 123456789} } }"
9227 + },
9228 + {
9229 + "description": "Timestamp with high-order bit set on both seconds and increment",
9230 + "canonical_bson": "10000000116100FFFFFFFFFFFFFFFF00",
9231 + "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4294967295, \"i\" : 4294967295} } }"
9232 + },
9233 + {
9234 + "description": "Timestamp with high-order bit set on both seconds and increment (not UINT32_MAX)",
9235 + "canonical_bson": "1000000011610000286BEE00286BEE00",
9236 + "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4000000000, \"i\" : 4000000000} } }"
9237 + }
9238 + ],
9239 + "decodeErrors": [
9240 + {
9241 + "description": "Truncated timestamp field",
9242 + "bson": "0f0000001161002A00000015CD5B00"
9243 + }
9244 + ]
9245 +}
9246 diff --git a/src/tests/spec/json/bson-corpus/top.json b/src/tests/spec/json/bson-corpus/top.json
9247 new file mode 100644
9248 index 0000000..9c649b5
9249 --- /dev/null
9250 +++ b/src/tests/spec/json/bson-corpus/top.json
9251 @@ -0,0 +1,266 @@
9252 +{
9253 + "description": "Top-level document validity",
9254 + "bson_type": "0x00",
9255 + "valid": [
9256 + {
9257 + "description": "Dollar-prefixed key in top-level document",
9258 + "canonical_bson": "0F00000010246B6579002A00000000",
9259 + "canonical_extjson": "{\"$key\": {\"$numberInt\": \"42\"}}"
9260 + },
9261 + {
9262 + "description": "Dollar as key in top-level document",
9263 + "canonical_bson": "0E00000002240002000000610000",
9264 + "canonical_extjson": "{\"$\": \"a\"}"
9265 + },
9266 + {
9267 + "description": "Dotted key in top-level document",
9268 + "canonical_bson": "1000000002612E620002000000630000",
9269 + "canonical_extjson": "{\"a.b\": \"c\"}"
9270 + },
9271 + {
9272 + "description": "Dot as key in top-level document",
9273 + "canonical_bson": "0E000000022E0002000000610000",
9274 + "canonical_extjson": "{\".\": \"a\"}"
9275 + }
9276 + ],
9277 + "decodeErrors": [
9278 + {
9279 + "description": "An object size that's too small to even include the object size, but is a well-formed, empty object",
9280 + "bson": "0100000000"
9281 + },
9282 + {
9283 + "description": "An object size that's only enough for the object size, but is a well-formed, empty object",
9284 + "bson": "0400000000"
9285 + },
9286 + {
9287 + "description": "One object, with length shorter than size (missing EOO)",
9288 + "bson": "05000000"
9289 + },
9290 + {
9291 + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0x01",
9292 + "bson": "0500000001"
9293 + },
9294 + {
9295 + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0xff",
9296 + "bson": "05000000FF"
9297 + },
9298 + {
9299 + "description": "One object, sized correctly, with a spot for an EOO, but the EOO is 0x70",
9300 + "bson": "0500000070"
9301 + },
9302 + {
9303 + "description": "Byte count is zero (with non-zero input length)",
9304 + "bson": "00000000000000000000"
9305 + },
9306 + {
9307 + "description": "Stated length exceeds byte count, with truncated document",
9308 + "bson": "1200000002666F6F0004000000626172"
9309 + },
9310 + {
9311 + "description": "Stated length less than byte count, with garbage after envelope",
9312 + "bson": "1200000002666F6F00040000006261720000DEADBEEF"
9313 + },
9314 + {
9315 + "description": "Stated length exceeds byte count, with valid envelope",
9316 + "bson": "1300000002666F6F00040000006261720000"
9317 + },
9318 + {
9319 + "description": "Stated length less than byte count, with valid envelope",
9320 + "bson": "1100000002666F6F00040000006261720000"
9321 + },
9322 + {
9323 + "description": "Invalid BSON type low range",
9324 + "bson": "07000000000000"
9325 + },
9326 + {
9327 + "description": "Invalid BSON type high range",
9328 + "bson": "07000000800000"
9329 + },
9330 + {
9331 + "description": "Document truncated mid-key",
9332 + "bson": "1200000002666F"
9333 + },
9334 + {
9335 + "description": "Null byte in document key",
9336 + "bson": "0D000000107800000100000000"
9337 + }
9338 + ],
9339 + "parseErrors": [
9340 + {
9341 + "description" : "Bad $regularExpression (extra field)",
9342 + "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}"
9343 + },
9344 + {
9345 + "description" : "Bad $regularExpression (missing options field)",
9346 + "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\"}}}"
9347 + },
9348 + {
9349 + "description": "Bad $regularExpression (pattern is number, not string)",
9350 + "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"options\" : \"\"}}}"
9351 + },
9352 + {
9353 + "description": "Bad $regularExpression (options are number, not string)",
9354 + "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"options\" : 0}}}"
9355 + },
9356 + {
9357 + "description" : "Bad $regularExpression (missing pattern field)",
9358 + "string" : "{\"a\" : {\"$regularExpression\": {\"options\":\"ix\"}}}"
9359 + },
9360 + {
9361 + "description": "Bad $oid (number, not string)",
9362 + "string": "{\"a\" : {\"$oid\" : 42}}"
9363 + },
9364 + {
9365 + "description": "Bad $oid (extra field)",
9366 + "string": "{\"a\" : {\"$oid\" : \"56e1fc72e0c917e9c4714161\", \"unrelated\": true}}"
9367 + },
9368 + {
9369 + "description": "Bad $numberInt (number, not string)",
9370 + "string": "{\"a\" : {\"$numberInt\" : 42}}"
9371 + },
9372 + {
9373 + "description": "Bad $numberInt (extra field)",
9374 + "string": "{\"a\" : {\"$numberInt\" : \"42\", \"unrelated\": true}}"
9375 + },
9376 + {
9377 + "description": "Bad $numberLong (number, not string)",
9378 + "string": "{\"a\" : {\"$numberLong\" : 42}}"
9379 + },
9380 + {
9381 + "description": "Bad $numberLong (extra field)",
9382 + "string": "{\"a\" : {\"$numberLong\" : \"42\", \"unrelated\": true}}"
9383 + },
9384 + {
9385 + "description": "Bad $numberDouble (number, not string)",
9386 + "string": "{\"a\" : {\"$numberDouble\" : 42}}"
9387 + },
9388 + {
9389 + "description": "Bad $numberDouble (extra field)",
9390 + "string": "{\"a\" : {\"$numberDouble\" : \".1\", \"unrelated\": true}}"
9391 + },
9392 + {
9393 + "description": "Bad $numberDecimal (number, not string)",
9394 + "string": "{\"a\" : {\"$numberDecimal\" : 42}}"
9395 + },
9396 + {
9397 + "description": "Bad $numberDecimal (extra field)",
9398 + "string": "{\"a\" : {\"$numberDecimal\" : \".1\", \"unrelated\": true}}"
9399 + },
9400 + {
9401 + "description": "Bad $binary (binary is number, not string)",
9402 + "string": "{\"x\" : {\"$binary\" : {\"base64\" : 0, \"subType\" : \"00\"}}}"
9403 + },
9404 + {
9405 + "description": "Bad $binary (type is number, not string)",
9406 + "string": "{\"x\" : {\"$binary\" : {\"base64\" : \"\", \"subType\" : 0}}}"
9407 + },
9408 + {
9409 + "description": "Bad $binary (missing $type)",
9410 + "string": "{\"x\" : {\"$binary\" : {\"base64\" : \"//8=\"}}}"
9411 + },
9412 + {
9413 + "description": "Bad $binary (missing $binary)",
9414 + "string": "{\"x\" : {\"$binary\" : {\"subType\" : \"00\"}}}"
9415 + },
9416 + {
9417 + "description": "Bad $binary (extra field)",
9418 + "string": "{\"x\" : {\"$binary\" : {\"base64\" : \"//8=\", \"subType\" : 0, \"unrelated\": true}}}"
9419 + },
9420 + {
9421 + "description": "Bad $code (type is number, not string)",
9422 + "string": "{\"a\" : {\"$code\" : 42}}"
9423 + },
9424 + {
9425 + "description": "Bad $code (type is number, not string) when $scope is also present",
9426 + "string": "{\"a\" : {\"$code\" : 42, \"$scope\" : {}}}"
9427 + },
9428 + {
9429 + "description": "Bad $code (extra field)",
9430 + "string": "{\"a\" : {\"$code\" : \"\", \"unrelated\": true}}"
9431 + },
9432 + {
9433 + "description": "Bad $code with $scope (scope is number, not doc)",
9434 + "string": "{\"x\" : {\"$code\" : \"\", \"$scope\" : 42}}"
9435 + },
9436 + {
9437 + "description": "Bad $timestamp (type is number, not doc)",
9438 + "string": "{\"a\" : {\"$timestamp\" : 42} }"
9439 + },
9440 + {
9441 + "description": "Bad $timestamp ('t' type is string, not number)",
9442 + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : 42} } }"
9443 + },
9444 + {
9445 + "description": "Bad $timestamp ('i' type is string, not number)",
9446 + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : 123456789, \"i\" : \"42\"} } }"
9447 + },
9448 + {
9449 + "description": "Bad $timestamp (extra field at same level as $timestamp)",
9450 + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\"}, \"unrelated\": true } }"
9451 + },
9452 + {
9453 + "description": "Bad $timestamp (extra field at same level as t and i)",
9454 + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\", \"i\" : \"42\", \"unrelated\": true} } }"
9455 + },
9456 + {
9457 + "description": "Bad $timestamp (missing t)",
9458 + "string": "{\"a\" : {\"$timestamp\" : {\"i\" : \"42\"} } }"
9459 + },
9460 + {
9461 + "description": "Bad $timestamp (missing i)",
9462 + "string": "{\"a\" : {\"$timestamp\" : {\"t\" : \"123456789\"} } }"
9463 + },
9464 + {
9465 + "description": "Bad $date (number, not string or hash)",
9466 + "string": "{\"a\" : {\"$date\" : 42}}"
9467 + },
9468 + {
9469 + "description": "Bad $date (extra field)",
9470 + "string": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}, \"unrelated\": true}}"
9471 + },
9472 + {
9473 + "description": "Bad $minKey (boolean, not integer)",
9474 + "string": "{\"a\" : {\"$minKey\" : true}}"
9475 + },
9476 + {
9477 + "description": "Bad $minKey (wrong integer)",
9478 + "string": "{\"a\" : {\"$minKey\" : 0}}"
9479 + },
9480 + {
9481 + "description": "Bad $minKey (extra field)",
9482 + "string": "{\"a\" : {\"$minKey\" : 1, \"unrelated\": true}}"
9483 + },
9484 + {
9485 + "description": "Bad $maxKey (boolean, not integer)",
9486 + "string": "{\"a\" : {\"$maxKey\" : true}}"
9487 + },
9488 + {
9489 + "description": "Bad $maxKey (wrong integer)",
9490 + "string": "{\"a\" : {\"$maxKey\" : 0}}"
9491 + },
9492 + {
9493 + "description": "Bad $maxKey (extra field)",
9494 + "string": "{\"a\" : {\"$maxKey\" : 1, \"unrelated\": true}}"
9495 + },
9496 + {
9497 + "description": "Bad DBpointer (extra field)",
9498 + "string": "{\"a\": {\"$dbPointer\": {\"a\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"c\": {\"$numberInt\": \"2\"}, \"$ref\": \"b\"}}}"
9499 + },
9500 + {
9501 + "description" : "Null byte in document key",
9502 + "string" : "{\"a\\u0000\": 1 }"
9503 + },
9504 + {
9505 + "description" : "Null byte in sub-document key",
9506 + "string" : "{\"a\" : {\"b\\u0000\": 1 }}"
9507 + },
9508 + {
9509 + "description": "Null byte in $regularExpression pattern",
9510 + "string": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"b\\u0000\", \"options\" : \"i\"}}}"
9511 + },
9512 + {
9513 + "description": "Null byte in $regularExpression options",
9514 + "string": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"b\", \"options\" : \"i\\u0000\"}}}"
9515 + }
9516 + ]
9517 +}
9518 diff --git a/src/tests/spec/json/bson-corpus/undefined.json b/src/tests/spec/json/bson-corpus/undefined.json
9519 new file mode 100644
9520 index 0000000..285f068
9521 --- /dev/null
9522 +++ b/src/tests/spec/json/bson-corpus/undefined.json
9523 @@ -0,0 +1,15 @@
9524 +{
9525 + "description": "Undefined type (deprecated)",
9526 + "bson_type": "0x06",
9527 + "deprecated": true,
9528 + "test_key": "a",
9529 + "valid": [
9530 + {
9531 + "description": "Undefined",
9532 + "canonical_bson": "0800000006610000",
9533 + "canonical_extjson": "{\"a\" : {\"$undefined\" : true}}",
9534 + "converted_bson": "080000000A610000",
9535 + "converted_extjson": "{\"a\" : null}"
9536 + }
9537 + ]
9538 +}
9539 diff --git a/src/tests/spec/mod.rs b/src/tests/spec/mod.rs
9540 new file mode 100644
9541 index 0000000..36ff825
9542 --- /dev/null
9543 +++ b/src/tests/spec/mod.rs
9544 @@ -0,0 +1,51 @@
9545 +mod corpus;
9546 +
9547 +use std::{
9548 + any::type_name,
9549 + ffi::OsStr,
9550 + fs::{self, File},
9551 + path::PathBuf,
9552 +};
9553 +
9554 +use crate::RawDocumentBuf;
9555 +use serde::de::DeserializeOwned;
9556 +
9557 +pub(crate) fn run_spec_test<T, F>(spec: &[&str], run_test_file: F)
9558 +where
9559 + F: Fn(T),
9560 + T: DeserializeOwned,
9561 +{
9562 + let base_path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "src", "tests", "spec", "json"]
9563 + .iter()
9564 + .chain(spec.iter())
9565 + .collect();
9566 +
9567 + for entry in fs::read_dir(&base_path)
9568 + .unwrap_or_else(|e| panic!("Failed to read directory at {:?}: {}", base_path, e))
9569 + {
9570 + let path = entry.unwrap().path();
9571 + if path.extension() != Some(OsStr::new("json")) {
9572 + continue;
9573 + }
9574 +
9575 + let file = File::open(&path)
9576 + .unwrap_or_else(|e| panic!("Failed to open file at {:?}: {}", path, e));
9577 +
9578 + let test_bson: RawDocumentBuf = serde_json::from_reader(file).unwrap_or_else(|e| {
9579 + panic!(
9580 + "Failed to deserialize test JSON to BSON in {:?}: {}",
9581 + path, e
9582 + )
9583 + });
9584 + let test: T = crate::from_slice(test_bson.as_bytes()).unwrap_or_else(|e| {
9585 + panic!(
9586 + "Failed to deserialize test BSON to {} in {:?}: {}",
9587 + type_name::<T>(),
9588 + path,
9589 + e
9590 + )
9591 + });
9592 +
9593 + run_test_file(test)
9594 + }
9595 +}