bson 4.7.1 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -2
  3. data.tar.gz.sig +0 -0
  4. data/README.md +5 -1
  5. data/ext/bson/bson-native.h +14 -4
  6. data/ext/bson/init.c +25 -2
  7. data/ext/bson/read.c +61 -15
  8. data/ext/bson/util.c +40 -0
  9. data/ext/bson/write.c +17 -13
  10. data/lib/bson.rb +3 -0
  11. data/lib/bson/array.rb +21 -3
  12. data/lib/bson/binary.rb +41 -3
  13. data/lib/bson/boolean.rb +3 -1
  14. data/lib/bson/code.rb +15 -1
  15. data/lib/bson/code_with_scope.rb +17 -3
  16. data/lib/bson/db_pointer.rb +104 -0
  17. data/lib/bson/decimal128.rb +15 -1
  18. data/lib/bson/error.rb +17 -0
  19. data/lib/bson/ext_json.rb +374 -0
  20. data/lib/bson/float.rb +47 -1
  21. data/lib/bson/hash.rb +23 -3
  22. data/lib/bson/int32.rb +21 -1
  23. data/lib/bson/int64.rb +28 -3
  24. data/lib/bson/integer.rb +34 -0
  25. data/lib/bson/max_key.rb +12 -0
  26. data/lib/bson/min_key.rb +12 -0
  27. data/lib/bson/nil_class.rb +3 -1
  28. data/lib/bson/object.rb +27 -0
  29. data/lib/bson/object_id.rb +15 -1
  30. data/lib/bson/regexp.rb +19 -2
  31. data/lib/bson/specialized.rb +3 -1
  32. data/lib/bson/string.rb +3 -1
  33. data/lib/bson/symbol.rb +92 -3
  34. data/lib/bson/time.rb +28 -3
  35. data/lib/bson/timestamp.rb +15 -1
  36. data/lib/bson/undefined.rb +11 -0
  37. data/lib/bson/version.rb +1 -1
  38. data/spec/bson/binary_spec.rb +33 -3
  39. data/spec/bson/ext_json_parse_spec.rb +276 -0
  40. data/spec/bson/float_spec.rb +36 -0
  41. data/spec/bson/hash_spec.rb +70 -0
  42. data/spec/bson/int32_spec.rb +20 -0
  43. data/spec/bson/int64_spec.rb +38 -0
  44. data/spec/bson/integer_spec.rb +26 -0
  45. data/spec/bson/raw_spec.rb +22 -1
  46. data/spec/bson/symbol_raw_spec.rb +45 -0
  47. data/spec/bson/symbol_spec.rb +60 -0
  48. data/spec/{support → runners}/common_driver.rb +0 -0
  49. data/spec/runners/corpus.rb +182 -0
  50. data/spec/{support/corpus.rb → runners/corpus_legacy.rb} +40 -58
  51. data/spec/spec_helper.rb +9 -2
  52. data/spec/{bson/driver_bson_spec.rb → spec_tests/common_driver_spec.rb} +1 -0
  53. data/spec/{bson/corpus_spec.rb → spec_tests/corpus_legacy_spec.rb} +4 -4
  54. data/spec/spec_tests/corpus_spec.rb +124 -0
  55. data/spec/spec_tests/data/corpus/README.md +15 -0
  56. data/spec/spec_tests/data/corpus/array.json +49 -0
  57. data/spec/spec_tests/data/corpus/binary.json +85 -0
  58. data/spec/spec_tests/data/corpus/boolean.json +27 -0
  59. data/spec/spec_tests/data/corpus/code.json +67 -0
  60. data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
  61. data/spec/spec_tests/data/corpus/datetime.json +42 -0
  62. data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
  63. data/spec/spec_tests/data/corpus/dbref.json +31 -0
  64. data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
  65. data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
  66. data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
  67. data/spec/spec_tests/data/corpus/decimal128-4.json +117 -0
  68. data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
  69. data/spec/spec_tests/data/corpus/decimal128-6.json +119 -0
  70. data/spec/spec_tests/data/corpus/decimal128-7.json +323 -0
  71. data/spec/spec_tests/data/corpus/document.json +36 -0
  72. data/spec/spec_tests/data/corpus/double.json +87 -0
  73. data/spec/spec_tests/data/corpus/int32.json +43 -0
  74. data/spec/spec_tests/data/corpus/int64.json +43 -0
  75. data/spec/spec_tests/data/corpus/maxkey.json +12 -0
  76. data/spec/spec_tests/data/corpus/minkey.json +12 -0
  77. data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
  78. data/spec/spec_tests/data/corpus/multi-type.json +11 -0
  79. data/spec/spec_tests/data/corpus/null.json +12 -0
  80. data/spec/spec_tests/data/corpus/oid.json +28 -0
  81. data/spec/spec_tests/data/corpus/regex.json +65 -0
  82. data/spec/spec_tests/data/corpus/string.json +72 -0
  83. data/spec/spec_tests/data/corpus/symbol.json +80 -0
  84. data/spec/spec_tests/data/corpus/timestamp.json +24 -0
  85. data/spec/spec_tests/data/corpus/top.json +240 -0
  86. data/spec/spec_tests/data/corpus/undefined.json +15 -0
  87. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/array.json +0 -0
  88. data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/binary.json +0 -0
  89. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/boolean.json +0 -0
  90. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code.json +1 -1
  91. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code_w_scope.json +1 -1
  92. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/document.json +1 -1
  93. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/double.json +1 -1
  94. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/datetime.json +0 -0
  95. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/dbpointer.json +0 -0
  96. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/int64.json +0 -0
  97. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/symbol.json +0 -0
  98. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/int32.json +1 -1
  99. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/maxkey.json +1 -1
  100. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/minkey.json +1 -1
  101. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/null.json +1 -1
  102. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/oid.json +0 -0
  103. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/regex.json +1 -1
  104. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/string.json +0 -0
  105. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/timestamp.json +1 -1
  106. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/top.json +0 -0
  107. data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/undefined.json +0 -0
  108. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-1.json +0 -0
  109. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-2.json +0 -0
  110. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-3.json +0 -0
  111. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-4.json +0 -0
  112. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-5.json +0 -0
  113. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-6.json +0 -0
  114. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-7.json +0 -0
  115. metadata +170 -95
  116. metadata.gz.sig +2 -4
@@ -15,25 +15,19 @@
15
15
  require 'json'
16
16
 
17
17
  module BSON
18
- module Corpus
18
+ module CorpusLegacy
19
19
 
20
20
  # Represents a test from the driver BSON Corpus.
21
- #
22
- # @since 4.2.0
23
21
  class Spec
24
22
 
25
23
  # The spec description.
26
24
  #
27
25
  # @return [ String ] The spec description.
28
- #
29
- # @since 4.2.0
30
26
  attr_reader :description
31
27
 
32
28
  # The document key of the object to test.
33
29
  #
34
30
  # @return [ String ] The document key.
35
- #
36
- # @since 4.2.0
37
31
  attr_reader :test_key
38
32
 
39
33
  # Instantiate the new spec.
@@ -42,8 +36,6 @@ module BSON
42
36
  # Spec.new(file)
43
37
  #
44
38
  # @param [ String ] file The name of the json file.
45
- #
46
- # @since 4.2.0
47
39
  def initialize(file)
48
40
  @spec = ::JSON.parse(File.read(file))
49
41
  @valid = @spec['valid'] || []
@@ -57,13 +49,11 @@ module BSON
57
49
  # @example Get the list of valid tests.
58
50
  # spec.valid_tests
59
51
  #
60
- # @return [ Array<BSON::Corpus::Test> ] The list of valid Tests.
61
- #
62
- # @since 4.2.0
52
+ # @return [ Array<BSON::CorpusLegacy::Test> ] The list of valid Tests.
63
53
  def valid_tests
64
54
  @valid_tests ||=
65
55
  @valid.collect do |test|
66
- BSON::Corpus::Test.new(self, test)
56
+ BSON::CorpusLegacy::Test.new(self, test)
67
57
  end
68
58
  end
69
59
 
@@ -72,13 +62,11 @@ module BSON
72
62
  # @example Get the list of invalid tests.
73
63
  # spec.invalid_tests
74
64
  #
75
- # @return [ Array<BSON::Corpus::Test> ] The list of invalid Tests.
76
- #
77
- # @since 4.2.0
65
+ # @return [ Array<BSON::CorpusLegacy::Test> ] The list of invalid Tests.
78
66
  def invalid_tests
79
67
  @invalid_tests ||=
80
68
  @invalid.collect do |test|
81
- BSON::Corpus::Test.new(self, test)
69
+ BSON::CorpusLegacy::Test.new(self, test)
82
70
  end
83
71
  end
84
72
 
@@ -88,31 +76,23 @@ module BSON
88
76
  # spec.klass
89
77
  #
90
78
  # @return [ Class ] The object class.
91
- #
92
- # @since 4.2.0
93
79
  def klass
94
80
  @klass ||= BSON.const_get(description)
95
81
  end
96
82
  end
97
83
 
98
84
  # Represents a single BSON Corpus test.
99
- #
100
- # @since 4.2.0
101
85
  class Test
102
86
 
103
87
  # The test description.
104
88
  #
105
89
  # @return [ String ] The test description.
106
- #
107
- # @since 4.2.0
108
90
  attr_reader :description
109
91
 
110
92
  # Name of a field in a valid test case extjson document that should be
111
93
  # checked against the case's string field.
112
94
  #
113
95
  # @return [ String ] The json representation of the object.
114
- #
115
- # @since 4.2.0
116
96
  attr_reader :test_key
117
97
 
118
98
  # Instantiate the new Test.
@@ -122,8 +102,6 @@ module BSON
122
102
  #
123
103
  # @param [ Corpus::Spec ] spec The test specification.
124
104
  # @param [ Hash ] test The test specification.
125
- #
126
- # @since 4.2.0
127
105
  def initialize(spec, test)
128
106
  @spec = spec
129
107
  @description = test['description']
@@ -139,12 +117,29 @@ module BSON
139
117
  # test.correct_bson
140
118
  #
141
119
  # @return [ String ] The correct bson bytes.
142
- #
143
- # @since 4.2.0
144
120
  def correct_bson
145
121
  @correct_bson ||= decode_hex(@canonical_bson || @bson)
146
122
  end
147
123
 
124
+ # Create a BSON::Document object from the test's bson representation
125
+ #
126
+ # @return [ BSON::Document ] The BSON::Document object
127
+ def document_from_bson
128
+ bson_bytes = decode_hex(@bson)
129
+ buffer = BSON::ByteBuffer.new(bson_bytes)
130
+ BSON::Document.from_bson(buffer)
131
+ end
132
+
133
+ # Create a BSON::Document object from the test's canonical bson
134
+ # representation
135
+ #
136
+ # @return [ BSON::Document ] The BSON::Document object
137
+ def document_from_canonical_bson
138
+ bson_bytes = decode_hex(@canonical_bson)
139
+ buffer = BSON::ByteBuffer.new(bson_bytes)
140
+ BSON::Document.from_bson(buffer)
141
+ end
142
+
148
143
  # Given the hex representation of bson, decode it into a Document,
149
144
  # then reencoded it to bson.
150
145
  #
@@ -152,12 +147,8 @@ module BSON
152
147
  # test.reencoded_bson
153
148
  #
154
149
  # @return [ String ] The reencoded bson bytes.
155
- #
156
- # @since 4.2.0
157
150
  def reencoded_bson
158
- bson_bytes = decode_hex(@bson)
159
- buffer = BSON::ByteBuffer.new(bson_bytes)
160
- BSON::Document.from_bson(buffer).to_bson.to_s
151
+ document_from_bson.to_bson.to_s
161
152
  end
162
153
 
163
154
  # Given the hex representation of the canonical bson, decode it into a Document,
@@ -167,12 +158,8 @@ module BSON
167
158
  # test.reencoded_canonical_bson
168
159
  #
169
160
  # @return [ String ] The reencoded canonical bson bytes.
170
- #
171
- # @since 4.2.0
172
161
  def reencoded_canonical_bson
173
- bson_bytes = decode_hex(@canonical_bson)
174
- buffer = BSON::ByteBuffer.new(bson_bytes)
175
- BSON::Document.from_bson(buffer).to_bson.to_s
162
+ document_from_canonical_bson.to_bson.to_s
176
163
  end
177
164
 
178
165
  # Whether the canonical bson should be tested.
@@ -181,8 +168,6 @@ module BSON
181
168
  # test.test_canonical_bson?
182
169
  #
183
170
  # @return [ true, false ] Whether the canonical bson should be tested.
184
- #
185
- # @since 4.2.0
186
171
  def test_canonical_bson?
187
172
  @canonical_bson && (@bson != @canonical_bson)
188
173
  end
@@ -193,8 +178,6 @@ module BSON
193
178
  # test.correct_extjson
194
179
  #
195
180
  # @return [ String ] The correct extended json representation.
196
- #
197
- # @since 4.2.0
198
181
  def correct_extjson
199
182
  @canonical_extjson || @extjson
200
183
  end
@@ -205,8 +188,6 @@ module BSON
205
188
  # test.test_extjson?
206
189
  #
207
190
  # @return [ true, false ] Whether the extended json should be tested.
208
- #
209
- # @since 4.2.0
210
191
  def test_extjson?
211
192
  !!@extjson
212
193
  end
@@ -218,12 +199,8 @@ module BSON
218
199
  # test.extjson_from_encoded_bson
219
200
  #
220
201
  # @return [ Hash ] The extended json representation.
221
- #
222
- # @since 4.2.0
223
202
  def extjson_from_bson
224
- subject = decode_hex(@bson)
225
- buffer = BSON::ByteBuffer.new(subject)
226
- ::JSON.parse(BSON::Document.from_bson(buffer).to_json)
203
+ as_legacy_extended_json(document_from_bson)
227
204
  end
228
205
 
229
206
  # Get the extended json representation of the decoded doc from the provided
@@ -233,12 +210,8 @@ module BSON
233
210
  # test.extjson_from_canonical_bson
234
211
  #
235
212
  # @return [ Hash ] The extended json representation.
236
- #
237
- # @since 4.2.0
238
213
  def extjson_from_canonical_bson
239
- subject = decode_hex(@canonical_bson)
240
- buffer = BSON::ByteBuffer.new(subject)
241
- ::JSON.parse(BSON::Document.from_bson(buffer).to_json)
214
+ as_legacy_extended_json(document_from_canonical_bson)
242
215
  end
243
216
 
244
217
  # Get the extended json representation of the decoded doc from the provided
@@ -248,15 +221,24 @@ module BSON
248
221
  # test.extjson_from_encoded_extjson
249
222
  #
250
223
  # @return [ Hash ] The extended json representation.
251
- #
252
- # @since 4.2.0
253
224
  def extjson_from_encoded_extjson
254
225
  doc = BSON::Document.new(@extjson)
255
- ::JSON.parse(doc.to_json)
226
+ as_legacy_extended_json(doc)
256
227
  end
257
228
 
258
229
  private
259
230
 
231
+ def as_legacy_extended_json(object)
232
+ result = object.as_extended_json(mode: :legacy)
233
+ if object.respond_to?(:as_json)
234
+ old_result = object.as_json
235
+ unless result == old_result
236
+ raise "Serializing #{object} to legacy extended json did not match between new and old APIs"
237
+ end
238
+ end
239
+ result
240
+ end
241
+
260
242
  def decode_hex(obj)
261
243
  [ obj ].pack('H*')
262
244
  end
@@ -13,8 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
16
- DRIVER_COMMON_BSON_TESTS = Dir.glob("#{CURRENT_PATH}/support/driver-spec-tests/**/*.json")
17
- BSON_CORPUS_TESTS = Dir.glob("#{CURRENT_PATH}/support/corpus-tests/*.json")
16
+ DRIVER_COMMON_BSON_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/decimal128/*.json").sort
17
+ BSON_CORPUS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/corpus/*.json").sort
18
+ BSON_CORPUS_LEGACY_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/corpus_legacy/*.json").sort
18
19
 
19
20
  $LOAD_PATH.unshift(File.dirname(__FILE__))
20
21
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -54,3 +55,9 @@ class AlternateIO < StringIO
54
55
  super.chr
55
56
  end
56
57
  end
58
+
59
+ RSpec.configure do |config|
60
+ config.expect_with :rspec do |c|
61
+ c.syntax = [:should, :expect]
62
+ end
63
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'runners/common_driver'
2
3
 
3
4
  describe 'Driver common bson tests' do
4
5
 
@@ -1,13 +1,14 @@
1
1
  require 'spec_helper'
2
+ require 'runners/corpus_legacy'
2
3
 
3
- describe 'Driver BSON Corpus spec tests' do
4
+ describe 'Driver BSON Corpus Legacy spec tests' do
4
5
 
5
- BSON_CORPUS_TESTS.each do |path|
6
+ BSON_CORPUS_LEGACY_TESTS.each do |path|
6
7
  basename = File.basename(path)
7
8
  # All of the tests in the failures subdir are failing apparently
8
9
  #basename = path.sub(/.*corpus-tests\//, '')
9
10
 
10
- spec = BSON::Corpus::Spec.new(path)
11
+ spec = BSON::CorpusLegacy::Spec.new(path)
11
12
 
12
13
  context("(#{basename}): #{spec.description}") do
13
14
 
@@ -29,7 +30,6 @@ describe 'Driver BSON Corpus spec tests' do
29
30
  context 'when the document can be represented as extended json', if: test.test_extjson? do
30
31
 
31
32
  it 'decodes from the given bson, then encodes the document as extended json correctly' do
32
- skip 'The extended json in this test case does not match' unless (test.extjson_from_bson == test.correct_extjson)
33
33
  expect(test.extjson_from_bson).to eq(test.correct_extjson)
34
34
  expect(test.extjson_from_bson[test.test_key]).to eq(test.correct_extjson[test.test_key])
35
35
  end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'runners/corpus'
3
+
4
+ describe 'BSON Corpus spec tests' do
5
+
6
+ BSON_CORPUS_TESTS.each do |path|
7
+ basename = File.basename(path)
8
+ # All of the tests in the failures subdir are failing apparently
9
+ #basename = path.sub(/.*corpus-tests\//, '')
10
+
11
+ spec = BSON::Corpus::Spec.new(path)
12
+
13
+ context("(#{basename}): #{spec.description}") do
14
+
15
+ spec.valid_tests&.each do |test|
16
+
17
+ context("valid: #{test.description}") do
18
+
19
+ let(:decoded_canonical_bson) do
20
+ BSON::Document.from_bson(BSON::ByteBuffer.new(test.canonical_bson), mode: :bson)
21
+ end
22
+
23
+ it 'round-trips canonical bson' do
24
+ decoded_canonical_bson.to_bson.to_s.should == test.canonical_bson
25
+ end
26
+
27
+ =begin
28
+ it 'converts bson to canonical extended json' do
29
+ pending
30
+ raise NotImplementedError
31
+ end
32
+ =end
33
+
34
+ it 'converts bson to canonical extended json' do
35
+ decoded_canonical_bson.as_extended_json.should == test.canonical_extjson_doc
36
+ end
37
+
38
+ if test.relaxed_extjson
39
+ it 'converts bson to relaxed extended json' do
40
+ decoded_canonical_bson.as_extended_json(mode: :relaxed).should == test.relaxed_extjson_doc
41
+ end
42
+
43
+ let(:parsed_relaxed_extjson) do
44
+ BSON::ExtJSON.parse_obj(test.relaxed_extjson_doc, mode: :bson)
45
+ end
46
+
47
+ let(:round_tripped_relaxed_extjson) do
48
+ parsed_relaxed_extjson.as_extended_json(mode: :relaxed)
49
+ end
50
+
51
+ # Relaxed extended json may parse into something other than the
52
+ # canonical bson. For example, relaxed extjson representation for
53
+ # a small int64 is a number that would serialize to an int32.
54
+ # But round-tripping extended json back to extjson should produce
55
+ # the same representation we started with.
56
+ it 'round-trips relaxed extended json' do
57
+ round_tripped_relaxed_extjson.should == test.relaxed_extjson_doc
58
+ end
59
+ end
60
+
61
+ if test.degenerate_bson
62
+
63
+ let(:decoded_degenerate_bson) do
64
+ BSON::Document.from_bson(BSON::ByteBuffer.new(test.degenerate_bson), mode: :relaxed)
65
+ end
66
+
67
+ it 'round-trips degenerate bson to canonical bson' do
68
+ decoded_degenerate_bson.to_bson.to_s.should == test.canonical_bson
69
+ end
70
+ end
71
+
72
+ let(:parsed_canonical_extjson) do
73
+ BSON::ExtJSON.parse_obj(test.canonical_extjson_doc, mode: :bson)
74
+ end
75
+
76
+ unless test.lossy?
77
+ it 'converts canonical extended json to bson' do
78
+ parsed_canonical_extjson.to_bson.to_s.should == test.canonical_bson
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+
85
+ spec.decode_error_tests&.each do |test|
86
+
87
+ context("decode error: #{test.description}") do
88
+
89
+ let(:decoded_bson) do
90
+ BSON::Document.from_bson(BSON::ByteBuffer.new(test.bson), mode: :bson)
91
+ end
92
+
93
+ # Until bson-ruby gets an exception hierarchy, we can only rescue
94
+ # the basic Exception here.
95
+ # https://jira.mongodb.org/browse/RUBY-1806
96
+ it 'raises an exception' do
97
+ expect do
98
+ decoded_bson
99
+ end.to raise_error(Exception)
100
+ end
101
+ end
102
+ end
103
+
104
+ spec.parse_error_tests&.each do |test|
105
+
106
+ context("parse error: #{test.description}") do
107
+
108
+ let(:parsed_extjson) do
109
+ BSON::ExtJSON.parse(test.string, mode: :bson)
110
+ end
111
+
112
+ # Until bson-ruby gets an exception hierarchy, we can only rescue
113
+ # the basic Exception here.
114
+ # https://jira.mongodb.org/browse/RUBY-1806
115
+ it 'raises an exception' do
116
+ expect do
117
+ parsed_extjson
118
+ end.to raise_error(Exception)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,15 @@
1
+ There are the following deliberate changes made to the corpus tests in Ruby:
2
+
3
+ 1. In double.js, Ruby appears to offer less precision than the spec tests
4
+ demand:
5
+
6
+ irb(main):001:0> -1.23456789012345677E+18
7
+ => -1.2345678901234568e+18
8
+
9
+ Because of this, -1.23456789012345677E+18 was changed to -1.2345678901234568e+18.
10
+ The "e" was lowercased as well. Both the precision reduction and the lowercasing
11
+ of "e" changes are also present in the Python driver, which appears to be
12
+ affected by the same precision limitation.
13
+
14
+ 2. In datetime.js, the millisecond component of iso8601 serialization of
15
+ timestamps is always present, even if it is zero.
@@ -0,0 +1,49 @@
1
+ {
2
+ "description": "Array",
3
+ "bson_type": "0x04",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty",
8
+ "canonical_bson": "0D000000046100050000000000",
9
+ "canonical_extjson": "{\"a\" : []}"
10
+ },
11
+ {
12
+ "description": "Single Element Array",
13
+ "canonical_bson": "140000000461000C0000001030000A0000000000",
14
+ "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
15
+ },
16
+ {
17
+ "description": "Single Element Array with index set incorrectly to empty string",
18
+ "degenerate_bson": "130000000461000B00000010000A0000000000",
19
+ "canonical_bson": "140000000461000C0000001030000A0000000000",
20
+ "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
21
+ },
22
+ {
23
+ "description": "Single Element Array with index set incorrectly to ab",
24
+ "degenerate_bson": "150000000461000D000000106162000A0000000000",
25
+ "canonical_bson": "140000000461000C0000001030000A0000000000",
26
+ "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}]}"
27
+ },
28
+ {
29
+ "description": "Multi Element Array with duplicate indexes",
30
+ "degenerate_bson": "1b000000046100130000001030000a000000103000140000000000",
31
+ "canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
32
+ "canonical_extjson": "{\"a\" : [{\"$numberInt\": \"10\"}, {\"$numberInt\": \"20\"}]}"
33
+ }
34
+ ],
35
+ "decodeErrors": [
36
+ {
37
+ "description": "Array length too long: eats outer terminator",
38
+ "bson": "140000000461000D0000001030000A0000000000"
39
+ },
40
+ {
41
+ "description": "Array length too short: leaks terminator",
42
+ "bson": "140000000461000B0000001030000A0000000000"
43
+ },
44
+ {
45
+ "description": "Invalid Array: bad string length in field",
46
+ "bson": "1A00000004666F6F00100000000230000500000062617A000000"
47
+ }
48
+ ]
49
+ }