bson 4.1.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +106 -7
  3. data/Rakefile +86 -43
  4. data/ext/bson/{native-endian.h → bson-endian.h} +14 -107
  5. data/ext/bson/bson-native.h +135 -0
  6. data/ext/bson/bytebuf.c +133 -0
  7. data/ext/bson/endian.c +117 -0
  8. data/ext/bson/extconf.rb +8 -3
  9. data/ext/bson/init.c +364 -0
  10. data/ext/bson/libbson-utf8.c +230 -0
  11. data/ext/bson/read.c +470 -0
  12. data/ext/bson/util.c +250 -0
  13. data/ext/bson/write.c +675 -0
  14. data/lib/bson/active_support.rb +19 -0
  15. data/lib/bson/array.rb +97 -30
  16. data/lib/bson/big_decimal.rb +77 -0
  17. data/lib/bson/binary.rb +510 -70
  18. data/lib/bson/boolean.rb +15 -4
  19. data/lib/bson/code.rb +25 -12
  20. data/lib/bson/code_with_scope.rb +41 -15
  21. data/lib/bson/config.rb +3 -28
  22. data/lib/bson/date.rb +16 -4
  23. data/lib/bson/date_time.rb +6 -4
  24. data/lib/bson/db_pointer.rb +110 -0
  25. data/lib/bson/dbref.rb +154 -0
  26. data/lib/bson/decimal128/builder.rb +456 -0
  27. data/lib/bson/decimal128.rb +272 -0
  28. data/lib/bson/document.rb +177 -7
  29. data/lib/bson/environment.rb +17 -2
  30. data/lib/bson/error/bson_decode_error.rb +11 -0
  31. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  32. data/lib/bson/error/illegal_key.rb +23 -0
  33. data/lib/bson/error/invalid_binary_type.rb +37 -0
  34. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  35. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  36. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  37. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  38. data/lib/bson/error/invalid_key.rb +24 -0
  39. data/lib/bson/error/invalid_object_id.rb +11 -0
  40. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  41. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  42. data/lib/bson/error/unserializable_class.rb +13 -0
  43. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  44. data/lib/bson/error/unsupported_type.rb +11 -0
  45. data/lib/bson/error.rb +22 -0
  46. data/lib/bson/ext_json.rb +389 -0
  47. data/lib/bson/false_class.rb +6 -4
  48. data/lib/bson/float.rb +43 -7
  49. data/lib/bson/hash.rb +152 -37
  50. data/lib/bson/int32.rb +104 -6
  51. data/lib/bson/int64.rb +111 -8
  52. data/lib/bson/integer.rb +43 -9
  53. data/lib/bson/json.rb +3 -1
  54. data/lib/bson/max_key.rb +21 -10
  55. data/lib/bson/min_key.rb +21 -10
  56. data/lib/bson/nil_class.rb +7 -3
  57. data/lib/bson/object.rb +25 -17
  58. data/lib/bson/object_id.rb +98 -113
  59. data/lib/bson/open_struct.rb +59 -0
  60. data/lib/bson/regexp.rb +129 -56
  61. data/lib/bson/registry.rb +7 -10
  62. data/lib/bson/specialized.rb +8 -4
  63. data/lib/bson/string.rb +12 -32
  64. data/lib/bson/symbol.rb +107 -11
  65. data/lib/bson/time.rb +68 -7
  66. data/lib/bson/time_with_zone.rb +67 -0
  67. data/lib/bson/timestamp.rb +50 -10
  68. data/lib/bson/true_class.rb +6 -4
  69. data/lib/bson/undefined.rb +28 -2
  70. data/lib/bson/vector.rb +44 -0
  71. data/lib/bson/version.rb +6 -14
  72. data/lib/bson.rb +22 -12
  73. data/spec/README.md +14 -0
  74. data/spec/bson/array_spec.rb +38 -62
  75. data/spec/bson/big_decimal_spec.rb +328 -0
  76. data/spec/bson/binary_spec.rb +199 -53
  77. data/spec/bson/binary_uuid_spec.rb +190 -0
  78. data/spec/bson/boolean_spec.rb +2 -1
  79. data/spec/bson/byte_buffer_read_spec.rb +198 -0
  80. data/spec/bson/byte_buffer_spec.rb +122 -381
  81. data/spec/bson/byte_buffer_write_spec.rb +855 -0
  82. data/spec/bson/code_spec.rb +6 -4
  83. data/spec/bson/code_with_scope_spec.rb +6 -4
  84. data/spec/bson/config_spec.rb +1 -35
  85. data/spec/bson/date_spec.rb +2 -1
  86. data/spec/bson/date_time_spec.rb +55 -1
  87. data/spec/bson/dbref_legacy_spec.rb +186 -0
  88. data/spec/bson/dbref_spec.rb +487 -0
  89. data/spec/bson/decimal128_spec.rb +1840 -0
  90. data/spec/bson/document_as_spec.rb +61 -0
  91. data/spec/bson/document_spec.rb +205 -32
  92. data/spec/bson/ext_json_parse_spec.rb +346 -0
  93. data/spec/bson/false_class_spec.rb +9 -1
  94. data/spec/bson/float_spec.rb +42 -1
  95. data/spec/bson/hash_as_spec.rb +58 -0
  96. data/spec/bson/hash_spec.rb +318 -66
  97. data/spec/bson/int32_spec.rb +248 -1
  98. data/spec/bson/int64_spec.rb +308 -1
  99. data/spec/bson/integer_spec.rb +61 -3
  100. data/spec/bson/json_spec.rb +2 -1
  101. data/spec/bson/max_key_spec.rb +6 -4
  102. data/spec/bson/min_key_spec.rb +6 -4
  103. data/spec/bson/nil_class_spec.rb +2 -1
  104. data/spec/bson/object_id_spec.rb +95 -5
  105. data/spec/bson/object_spec.rb +3 -2
  106. data/spec/bson/open_struct_spec.rb +87 -0
  107. data/spec/bson/raw_spec.rb +594 -0
  108. data/spec/bson/regexp_spec.rb +61 -8
  109. data/spec/bson/registry_spec.rb +3 -2
  110. data/spec/bson/string_spec.rb +26 -33
  111. data/spec/bson/symbol_raw_spec.rb +70 -0
  112. data/spec/bson/symbol_spec.rb +77 -20
  113. data/spec/bson/time_spec.rb +206 -2
  114. data/spec/bson/time_with_zone_spec.rb +69 -0
  115. data/spec/bson/timestamp_spec.rb +58 -2
  116. data/spec/bson/true_class_spec.rb +9 -1
  117. data/spec/bson/undefined_spec.rb +28 -1
  118. data/spec/bson/vector_spec.rb +33 -0
  119. data/spec/bson_spec.rb +2 -1
  120. data/spec/runners/binary_vector.rb +78 -0
  121. data/spec/runners/common_driver.rb +348 -0
  122. data/spec/runners/corpus.rb +191 -0
  123. data/spec/runners/corpus_legacy.rb +248 -0
  124. data/spec/shared/LICENSE +20 -0
  125. data/spec/shared/bin/get-mongodb-download-url +17 -0
  126. data/spec/shared/bin/s3-copy +45 -0
  127. data/spec/shared/bin/s3-upload +69 -0
  128. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  129. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  130. data/spec/shared/lib/mrss/constraints.rb +378 -0
  131. data/spec/shared/lib/mrss/docker_runner.rb +298 -0
  132. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  133. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  134. data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
  135. data/spec/shared/lib/mrss/release/candidate.rb +281 -0
  136. data/spec/shared/lib/mrss/release/product_data.rb +144 -0
  137. data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
  138. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  139. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  140. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  141. data/spec/shared/lib/mrss/utils.rb +37 -0
  142. data/spec/shared/lib/tasks/candidate.rake +64 -0
  143. data/spec/shared/share/Dockerfile.erb +251 -0
  144. data/spec/shared/share/haproxy-1.conf +16 -0
  145. data/spec/shared/share/haproxy-2.conf +17 -0
  146. data/spec/shared/shlib/config.sh +27 -0
  147. data/spec/shared/shlib/distro.sh +84 -0
  148. data/spec/shared/shlib/server.sh +423 -0
  149. data/spec/shared/shlib/set_env.sh +110 -0
  150. data/spec/spec_helper.rb +61 -1
  151. data/spec/spec_tests/binary_vector_spec.rb +82 -0
  152. data/spec/spec_tests/common_driver_spec.rb +84 -0
  153. data/spec/spec_tests/corpus_legacy_spec.rb +72 -0
  154. data/spec/spec_tests/corpus_spec.rb +134 -0
  155. data/spec/spec_tests/data/binary_vector/README.md +61 -0
  156. data/spec/spec_tests/data/binary_vector/float32.json +65 -0
  157. data/spec/spec_tests/data/binary_vector/int8.json +57 -0
  158. data/spec/spec_tests/data/binary_vector/packed_bit.json +83 -0
  159. data/spec/spec_tests/data/corpus/README.md +15 -0
  160. data/spec/spec_tests/data/corpus/array.json +49 -0
  161. data/spec/spec_tests/data/corpus/binary.json +153 -0
  162. data/spec/spec_tests/data/corpus/boolean.json +27 -0
  163. data/spec/spec_tests/data/corpus/code.json +67 -0
  164. data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
  165. data/spec/spec_tests/data/corpus/datetime.json +42 -0
  166. data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
  167. data/spec/spec_tests/data/corpus/dbref.json +51 -0
  168. data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
  169. data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
  170. data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
  171. data/spec/spec_tests/data/corpus/decimal128-4.json +165 -0
  172. data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
  173. data/spec/spec_tests/data/corpus/decimal128-6.json +131 -0
  174. data/spec/spec_tests/data/corpus/decimal128-7.json +327 -0
  175. data/spec/spec_tests/data/corpus/document.json +60 -0
  176. data/spec/spec_tests/data/corpus/double.json +87 -0
  177. data/spec/spec_tests/data/corpus/int32.json +43 -0
  178. data/spec/spec_tests/data/corpus/int64.json +43 -0
  179. data/spec/spec_tests/data/corpus/maxkey.json +12 -0
  180. data/spec/spec_tests/data/corpus/minkey.json +12 -0
  181. data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
  182. data/spec/spec_tests/data/corpus/multi-type.json +11 -0
  183. data/spec/spec_tests/data/corpus/null.json +12 -0
  184. data/spec/spec_tests/data/corpus/oid.json +28 -0
  185. data/spec/spec_tests/data/corpus/regex.json +65 -0
  186. data/spec/spec_tests/data/corpus/string.json +72 -0
  187. data/spec/spec_tests/data/corpus/symbol.json +80 -0
  188. data/spec/spec_tests/data/corpus/timestamp.json +34 -0
  189. data/spec/spec_tests/data/corpus/top.json +262 -0
  190. data/spec/spec_tests/data/corpus/undefined.json +15 -0
  191. data/spec/spec_tests/data/corpus_legacy/array.json +49 -0
  192. data/spec/spec_tests/data/corpus_legacy/binary.json +69 -0
  193. data/spec/spec_tests/data/corpus_legacy/boolean.json +27 -0
  194. data/spec/spec_tests/data/corpus_legacy/code.json +67 -0
  195. data/spec/spec_tests/data/corpus_legacy/code_w_scope.json +78 -0
  196. data/spec/spec_tests/data/corpus_legacy/document.json +36 -0
  197. data/spec/spec_tests/data/corpus_legacy/double.json +69 -0
  198. data/spec/spec_tests/data/corpus_legacy/failures/datetime.json +31 -0
  199. data/spec/spec_tests/data/corpus_legacy/failures/dbpointer.json +42 -0
  200. data/spec/spec_tests/data/corpus_legacy/failures/int64.json +38 -0
  201. data/spec/spec_tests/data/corpus_legacy/failures/symbol.json +62 -0
  202. data/spec/spec_tests/data/corpus_legacy/int32.json +38 -0
  203. data/spec/spec_tests/data/corpus_legacy/maxkey.json +12 -0
  204. data/spec/spec_tests/data/corpus_legacy/minkey.json +12 -0
  205. data/spec/spec_tests/data/corpus_legacy/null.json +12 -0
  206. data/spec/spec_tests/data/corpus_legacy/oid.json +28 -0
  207. data/spec/spec_tests/data/corpus_legacy/regex.json +37 -0
  208. data/spec/spec_tests/data/corpus_legacy/string.json +67 -0
  209. data/spec/spec_tests/data/corpus_legacy/timestamp.json +18 -0
  210. data/spec/spec_tests/data/corpus_legacy/top.json +62 -0
  211. data/spec/spec_tests/data/corpus_legacy/undefined.json +13 -0
  212. data/spec/spec_tests/data/decimal128/decimal128-1.json +363 -0
  213. data/spec/spec_tests/data/decimal128/decimal128-2.json +793 -0
  214. data/spec/spec_tests/data/decimal128/decimal128-3.json +1771 -0
  215. data/spec/spec_tests/data/decimal128/decimal128-4.json +165 -0
  216. data/spec/spec_tests/data/decimal128/decimal128-5.json +402 -0
  217. data/spec/spec_tests/data/decimal128/decimal128-6.json +131 -0
  218. data/spec/spec_tests/data/decimal128/decimal128-7.json +327 -0
  219. data/spec/support/shared_examples.rb +32 -11
  220. data/spec/support/spec_config.rb +17 -0
  221. data/spec/support/utils.rb +58 -0
  222. metadata +284 -45
  223. checksums.yaml.gz.sig +0 -3
  224. data/ext/bson/native.c +0 -722
  225. data.tar.gz.sig +0 -0
  226. metadata.gz.sig +0 -0
@@ -0,0 +1,153 @@
1
+ {
2
+ "description": "Binary type",
3
+ "bson_type": "0x05",
4
+ "test_key": "x",
5
+ "valid": [
6
+ {
7
+ "description": "subtype 0x00 (Zero-length)",
8
+ "canonical_bson": "0D000000057800000000000000",
9
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}"
10
+ },
11
+ {
12
+ "description": "subtype 0x00 (Zero-length, keys reversed)",
13
+ "canonical_bson": "0D000000057800000000000000",
14
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}",
15
+ "degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}"
16
+ },
17
+ {
18
+ "description": "subtype 0x00",
19
+ "canonical_bson": "0F0000000578000200000000FFFF00",
20
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}"
21
+ },
22
+ {
23
+ "description": "subtype 0x01",
24
+ "canonical_bson": "0F0000000578000200000001FFFF00",
25
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}"
26
+ },
27
+ {
28
+ "description": "subtype 0x02",
29
+ "canonical_bson": "13000000057800060000000202000000FFFF00",
30
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}"
31
+ },
32
+ {
33
+ "description": "subtype 0x03",
34
+ "canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
35
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}"
36
+ },
37
+ {
38
+ "description": "subtype 0x04",
39
+ "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
40
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
41
+ },
42
+ {
43
+ "description": "subtype 0x04 UUID",
44
+ "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
45
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
46
+ "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
47
+ },
48
+ {
49
+ "description": "subtype 0x05",
50
+ "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
51
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}"
52
+ },
53
+ {
54
+ "description": "subtype 0x07",
55
+ "canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
56
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
57
+ },
58
+ {
59
+ "description": "subtype 0x08",
60
+ "canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
61
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
62
+ },
63
+ {
64
+ "description": "subtype 0x80",
65
+ "canonical_bson": "0F0000000578000200000080FFFF00",
66
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}"
67
+ },
68
+ {
69
+ "description": "$type query operator (conflicts with legacy $binary form with $type field)",
70
+ "canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000",
71
+ "canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}"
72
+ },
73
+ {
74
+ "description": "$type query operator (conflicts with legacy $binary form with $type field)",
75
+ "canonical_bson": "180000000378001000000010247479706500020000000000",
76
+ "canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}"
77
+ },
78
+ {
79
+ "description": "subtype 0x09 Vector FLOAT32",
80
+ "canonical_bson": "170000000578000A0000000927000000FE420000E04000",
81
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwAAAP5CAADgQA==\", \"subType\": \"09\"}}}"
82
+ },
83
+ {
84
+ "description": "subtype 0x09 Vector INT8",
85
+ "canonical_bson": "11000000057800040000000903007F0700",
86
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwB/Bw==\", \"subType\": \"09\"}}}"
87
+ },
88
+ {
89
+ "description": "subtype 0x09 Vector PACKED_BIT",
90
+ "canonical_bson": "11000000057800040000000910007F0700",
91
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAB/Bw==\", \"subType\": \"09\"}}}"
92
+ },
93
+ {
94
+ "description": "subtype 0x09 Vector (Zero-length) FLOAT32",
95
+ "canonical_bson": "0F0000000578000200000009270000",
96
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwA=\", \"subType\": \"09\"}}}"
97
+ },
98
+ {
99
+ "description": "subtype 0x09 Vector (Zero-length) INT8",
100
+ "canonical_bson": "0F0000000578000200000009030000",
101
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwA=\", \"subType\": \"09\"}}}"
102
+ },
103
+ {
104
+ "description": "subtype 0x09 Vector (Zero-length) PACKED_BIT",
105
+ "canonical_bson": "0F0000000578000200000009100000",
106
+ "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAA=\", \"subType\": \"09\"}}}"
107
+ }
108
+ ],
109
+ "decodeErrors": [
110
+ {
111
+ "description": "Length longer than document",
112
+ "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
113
+ },
114
+ {
115
+ "description": "Negative length",
116
+ "bson": "0D000000057800FFFFFFFF0000"
117
+ },
118
+ {
119
+ "description": "subtype 0x02 length too long ",
120
+ "bson": "13000000057800060000000203000000FFFF00"
121
+ },
122
+ {
123
+ "description": "subtype 0x02 length too short",
124
+ "bson": "13000000057800060000000201000000FFFF00"
125
+ },
126
+ {
127
+ "description": "subtype 0x02 length negative one",
128
+ "bson": "130000000578000600000002FFFFFFFFFFFF00"
129
+ }
130
+ ],
131
+ "parseErrors": [
132
+ {
133
+ "description": "$uuid wrong type",
134
+ "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
135
+ },
136
+ {
137
+ "description": "$uuid invalid value--too short",
138
+ "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
139
+ },
140
+ {
141
+ "description": "$uuid invalid value--too long",
142
+ "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}"
143
+ },
144
+ {
145
+ "description": "$uuid invalid value--misplaced hyphens",
146
+ "string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}"
147
+ },
148
+ {
149
+ "description": "$uuid invalid value--too many hyphens",
150
+ "string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}"
151
+ }
152
+ ]
153
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "description": "Boolean",
3
+ "bson_type": "0x08",
4
+ "test_key": "b",
5
+ "valid": [
6
+ {
7
+ "description": "True",
8
+ "canonical_bson": "090000000862000100",
9
+ "canonical_extjson": "{\"b\" : true}"
10
+ },
11
+ {
12
+ "description": "False",
13
+ "canonical_bson": "090000000862000000",
14
+ "canonical_extjson": "{\"b\" : false}"
15
+ }
16
+ ],
17
+ "decodeErrors": [
18
+ {
19
+ "description": "Invalid boolean value of 2",
20
+ "bson": "090000000862000200"
21
+ },
22
+ {
23
+ "description": "Invalid boolean value of -1",
24
+ "bson": "09000000086200FF00"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,67 @@
1
+ {
2
+ "description": "Javascript Code",
3
+ "bson_type": "0x0D",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty string",
8
+ "canonical_bson": "0D0000000D6100010000000000",
9
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\"}}"
10
+ },
11
+ {
12
+ "description": "Single character",
13
+ "canonical_bson": "0E0000000D610002000000620000",
14
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"b\"}}"
15
+ },
16
+ {
17
+ "description": "Multi-character",
18
+ "canonical_bson": "190000000D61000D0000006162616261626162616261620000",
19
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"abababababab\"}}"
20
+ },
21
+ {
22
+ "description": "two-byte UTF-8 (\u00e9)",
23
+ "canonical_bson": "190000000D61000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
24
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}}"
25
+ },
26
+ {
27
+ "description": "three-byte UTF-8 (\u2606)",
28
+ "canonical_bson": "190000000D61000D000000E29886E29886E29886E298860000",
29
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u2606\\u2606\\u2606\\u2606\"}}"
30
+ },
31
+ {
32
+ "description": "Embedded nulls",
33
+ "canonical_bson": "190000000D61000D0000006162006261620062616261620000",
34
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"ab\\u0000bab\\u0000babab\"}}"
35
+ }
36
+ ],
37
+ "decodeErrors": [
38
+ {
39
+ "description": "bad code string length: 0 (but no 0x00 either)",
40
+ "bson": "0C0000000D61000000000000"
41
+ },
42
+ {
43
+ "description": "bad code string length: -1",
44
+ "bson": "0C0000000D6100FFFFFFFF00"
45
+ },
46
+ {
47
+ "description": "bad code string length: eats terminator",
48
+ "bson": "100000000D6100050000006200620000"
49
+ },
50
+ {
51
+ "description": "bad code string length: longer than rest of document",
52
+ "bson": "120000000D00FFFFFF00666F6F6261720000"
53
+ },
54
+ {
55
+ "description": "code string is not null-terminated",
56
+ "bson": "100000000D610004000000616263FF00"
57
+ },
58
+ {
59
+ "description": "empty code string, but extra null",
60
+ "bson": "0E0000000D610001000000000000"
61
+ },
62
+ {
63
+ "description": "invalid UTF-8",
64
+ "bson": "0E0000000D610002000000E90000"
65
+ }
66
+ ]
67
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "description": "Javascript Code with Scope",
3
+ "bson_type": "0x0F",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty code string, empty scope",
8
+ "canonical_bson": "160000000F61000E0000000100000000050000000000",
9
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {}}}"
10
+ },
11
+ {
12
+ "description": "Non-empty code string, empty scope",
13
+ "canonical_bson": "1A0000000F610012000000050000006162636400050000000000",
14
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {}}}"
15
+ },
16
+ {
17
+ "description": "Empty code string, non-empty scope",
18
+ "canonical_bson": "1D0000000F61001500000001000000000C000000107800010000000000",
19
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {\"x\" : {\"$numberInt\": \"1\"}}}}"
20
+ },
21
+ {
22
+ "description": "Non-empty code string and non-empty scope",
23
+ "canonical_bson": "210000000F6100190000000500000061626364000C000000107800010000000000",
24
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {\"x\" : {\"$numberInt\": \"1\"}}}}"
25
+ },
26
+ {
27
+ "description": "Unicode and embedded null in code string, empty scope",
28
+ "canonical_bson": "1A0000000F61001200000005000000C3A9006400050000000000",
29
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u0000d\", \"$scope\" : {}}}"
30
+ }
31
+ ],
32
+ "decodeErrors": [
33
+ {
34
+ "description": "field length zero",
35
+ "bson": "280000000F6100000000000500000061626364001300000010780001000000107900010000000000"
36
+ },
37
+ {
38
+ "description": "field length negative",
39
+ "bson": "280000000F6100FFFFFFFF0500000061626364001300000010780001000000107900010000000000"
40
+ },
41
+ {
42
+ "description": "field length too short (less than minimum size)",
43
+ "bson": "160000000F61000D0000000100000000050000000000"
44
+ },
45
+ {
46
+ "description": "field length too short (truncates scope)",
47
+ "bson": "280000000F61001F0000000500000061626364001300000010780001000000107900010000000000"
48
+ },
49
+ {
50
+ "description": "field length too long (clips outer doc)",
51
+ "bson": "280000000F6100210000000500000061626364001300000010780001000000107900010000000000"
52
+ },
53
+ {
54
+ "description": "field length too long (longer than outer doc)",
55
+ "bson": "280000000F6100FF0000000500000061626364001300000010780001000000107900010000000000"
56
+ },
57
+ {
58
+ "description": "bad code string: length too short",
59
+ "bson": "280000000F6100200000000400000061626364001300000010780001000000107900010000000000"
60
+ },
61
+ {
62
+ "description": "bad code string: length too long (clips scope)",
63
+ "bson": "280000000F6100200000000600000061626364001300000010780001000000107900010000000000"
64
+ },
65
+ {
66
+ "description": "bad code string: negative length",
67
+ "bson": "280000000F610020000000FFFFFFFF61626364001300000010780001000000107900010000000000"
68
+ },
69
+ {
70
+ "description": "bad code string: length longer than field",
71
+ "bson": "280000000F610020000000FF00000061626364001300000010780001000000107900010000000000"
72
+ },
73
+ {
74
+ "description": "bad scope doc (field has bad string length)",
75
+ "bson": "1C0000000F001500000001000000000C000000020000000000000000"
76
+ }
77
+ ]
78
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "description": "DateTime",
3
+ "bson_type": "0x09",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "epoch",
8
+ "canonical_bson": "10000000096100000000000000000000",
9
+ "relaxed_extjson": "{\"a\" : {\"$date\" : \"1970-01-01T00:00:00Z\"}}",
10
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"0\"}}}"
11
+ },
12
+ {
13
+ "description": "positive ms",
14
+ "canonical_bson": "10000000096100C5D8D6CC3B01000000",
15
+ "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.501Z\"}}",
16
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330501\"}}}"
17
+ },
18
+ {
19
+ "description": "negative",
20
+ "canonical_bson": "10000000096100C33CE7B9BDFFFFFF00",
21
+ "relaxed_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"-284643869501\"}}}",
22
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"-284643869501\"}}}"
23
+ },
24
+ {
25
+ "description" : "Y10K",
26
+ "canonical_bson" : "1000000009610000DC1FD277E6000000",
27
+ "canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}"
28
+ },
29
+ {
30
+ "description": "leading zero ms",
31
+ "canonical_bson": "10000000096100D1D6D6CC3B01000000",
32
+ "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}",
33
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}"
34
+ }
35
+ ],
36
+ "decodeErrors": [
37
+ {
38
+ "description": "datetime field truncated",
39
+ "bson": "0C0000000961001234567800"
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "description": "DBPointer type (deprecated)",
3
+ "bson_type": "0x0C",
4
+ "deprecated": true,
5
+ "test_key": "a",
6
+ "valid": [
7
+ {
8
+ "description": "DBpointer",
9
+ "canonical_bson": "1A0000000C610002000000620056E1FC72E0C917E9C471416100",
10
+ "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
11
+ "converted_bson": "2a00000003610022000000022472656600020000006200072469640056e1fc72e0c917e9c47141610000",
12
+ "converted_extjson": "{\"a\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
13
+ },
14
+ {
15
+ "description": "DBpointer with opposite key order",
16
+ "canonical_bson": "1A0000000C610002000000620056E1FC72E0C917E9C471416100",
17
+ "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
18
+ "degenerate_extjson": "{\"a\": {\"$dbPointer\": {\"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"$ref\": \"b\"}}}",
19
+ "converted_bson": "2a00000003610022000000022472656600020000006200072469640056e1fc72e0c917e9c47141610000",
20
+ "converted_extjson": "{\"a\": {\"$ref\": \"b\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
21
+ },
22
+ {
23
+ "description": "With two-byte UTF-8",
24
+ "canonical_bson": "1B0000000C610003000000C3A90056E1FC72E0C917E9C471416100",
25
+ "canonical_extjson": "{\"a\": {\"$dbPointer\": {\"$ref\": \"é\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}}",
26
+ "converted_bson": "2B0000000361002300000002247265660003000000C3A900072469640056E1FC72E0C917E9C47141610000",
27
+ "converted_extjson": "{\"a\": {\"$ref\": \"é\", \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}}}"
28
+ }
29
+ ],
30
+ "decodeErrors": [
31
+ {
32
+ "description": "String with negative length",
33
+ "bson": "1A0000000C6100FFFFFFFF620056E1FC72E0C917E9C471416100"
34
+ },
35
+ {
36
+ "description": "String with zero length",
37
+ "bson": "1A0000000C610000000000620056E1FC72E0C917E9C471416100"
38
+ },
39
+ {
40
+ "description": "String not null terminated",
41
+ "bson": "1A0000000C610002000000626256E1FC72E0C917E9C471416100"
42
+ },
43
+ {
44
+ "description": "short OID (less than minimum length for field)",
45
+ "bson": "160000000C61000300000061620056E1FC72E0C91700"
46
+ },
47
+ {
48
+ "description": "short OID (greater than minimum, but truncated)",
49
+ "bson": "1A0000000C61000300000061620056E1FC72E0C917E9C4716100"
50
+ },
51
+ {
52
+ "description": "String with bad UTF-8",
53
+ "bson": "1A0000000C610002000000E90056E1FC72E0C917E9C471416100"
54
+ }
55
+ ]
56
+ }
@@ -0,0 +1,51 @@
1
+ {
2
+ "description": "Document type (DBRef sub-documents)",
3
+ "bson_type": "0x03",
4
+ "valid": [
5
+ {
6
+ "description": "DBRef",
7
+ "canonical_bson": "37000000036462726566002b0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0000",
8
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
9
+ },
10
+ {
11
+ "description": "DBRef with database",
12
+ "canonical_bson": "4300000003646272656600370000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e0224646200030000006462000000",
13
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": \"db\"}}"
14
+ },
15
+ {
16
+ "description": "DBRef with database and additional fields",
17
+ "canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e0010246964002a00000002246462000300000064620002666f6f0004000000626172000000",
18
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$numberInt\": \"42\"}, \"$db\": \"db\", \"foo\": \"bar\"}}"
19
+ },
20
+ {
21
+ "description": "DBRef with additional fields",
22
+ "canonical_bson": "4400000003646272656600380000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e02666f6f0004000000626172000000",
23
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"foo\": \"bar\"}}"
24
+ },
25
+ {
26
+ "description": "Document with key names similar to those of a DBRef",
27
+ "canonical_bson": "3e0000000224726566000c0000006e6f742d612d646272656600072469640058921b3e6e32ab156a22b59e022462616e616e6100050000007065656c0000",
28
+ "canonical_extjson": "{\"$ref\": \"not-a-dbref\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$banana\": \"peel\"}"
29
+ },
30
+ {
31
+ "description": "DBRef with additional dollar-prefixed and dotted fields",
32
+ "canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000",
33
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"a.b\": {\"$numberInt\": \"1\"}, \"$c\": {\"$numberInt\": \"1\"}}}"
34
+ },
35
+ {
36
+ "description": "Sub-document resembles DBRef but $id is missing",
37
+ "canonical_bson": "26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000",
38
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\"}}"
39
+ },
40
+ {
41
+ "description": "Sub-document resembles DBRef but $ref is not a string",
42
+ "canonical_bson": "2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000",
43
+ "canonical_extjson": "{\"dbref\": {\"$ref\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}"
44
+ },
45
+ {
46
+ "description": "Sub-document resembles DBRef but $db is not a string",
47
+ "canonical_bson": "4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000",
48
+ "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": {\"$numberInt\": \"1\"}}}"
49
+ }
50
+ ]
51
+ }