bson 4.2.0.rc1-java → 4.2.1-java

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 (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/bson-ruby.jar +0 -0
  5. data/lib/bson/array.rb +1 -1
  6. data/lib/bson/binary.rb +4 -2
  7. data/lib/bson/code.rb +1 -1
  8. data/lib/bson/code_with_scope.rb +1 -1
  9. data/lib/bson/date.rb +1 -1
  10. data/lib/bson/date_time.rb +1 -1
  11. data/lib/bson/decimal128.rb +2 -2
  12. data/lib/bson/false_class.rb +1 -1
  13. data/lib/bson/float.rb +1 -1
  14. data/lib/bson/hash.rb +1 -1
  15. data/lib/bson/integer.rb +1 -1
  16. data/lib/bson/object_id.rb +1 -1
  17. data/lib/bson/open_struct.rb +1 -1
  18. data/lib/bson/regexp.rb +87 -19
  19. data/lib/bson/specialized.rb +1 -1
  20. data/lib/bson/string.rb +1 -1
  21. data/lib/bson/symbol.rb +1 -1
  22. data/lib/bson/time.rb +1 -1
  23. data/lib/bson/timestamp.rb +1 -1
  24. data/lib/bson/true_class.rb +1 -1
  25. data/lib/bson/version.rb +1 -1
  26. data/spec/bson/array_spec.rb +1 -1
  27. data/spec/bson/binary_spec.rb +2 -1
  28. data/spec/bson/corpus_spec.rb +68 -0
  29. data/spec/bson/decimal128_spec.rb +5 -1
  30. data/spec/bson/int64_spec.rb +47 -0
  31. data/spec/bson/raw_spec.rb +562 -0
  32. data/spec/bson/regexp_spec.rb +7 -7
  33. data/spec/spec_helper.rb +1 -0
  34. data/spec/support/corpus-tests/array.json +43 -0
  35. data/spec/support/corpus-tests/boolean.json +27 -0
  36. data/spec/support/corpus-tests/code.json +67 -0
  37. data/spec/support/corpus-tests/code_w_scope.json +78 -0
  38. data/spec/support/corpus-tests/document.json +36 -0
  39. data/spec/support/corpus-tests/double.json +69 -0
  40. data/spec/support/corpus-tests/failures/binary.json +69 -0
  41. data/spec/support/corpus-tests/failures/datetime.json +31 -0
  42. data/spec/support/corpus-tests/failures/dbpointer.json +42 -0
  43. data/spec/support/corpus-tests/failures/int64.json +38 -0
  44. data/spec/support/corpus-tests/failures/symbol.json +62 -0
  45. data/spec/support/corpus-tests/failures/undefined.json +13 -0
  46. data/spec/support/corpus-tests/int32.json +38 -0
  47. data/spec/support/corpus-tests/maxkey.json +12 -0
  48. data/spec/support/corpus-tests/minkey.json +12 -0
  49. data/spec/support/corpus-tests/null.json +12 -0
  50. data/spec/support/corpus-tests/oid.json +28 -0
  51. data/spec/support/corpus-tests/regex.json +37 -0
  52. data/spec/support/corpus-tests/string.json +67 -0
  53. data/spec/support/corpus-tests/timestamp.json +18 -0
  54. data/spec/support/corpus-tests/top.json +62 -0
  55. data/spec/support/corpus.rb +265 -0
  56. data/spec/support/shared_examples.rb +1 -1
  57. metadata +51 -3
  58. metadata.gz.sig +0 -0
@@ -0,0 +1,265 @@
1
+ # Copyright (C) 2016 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'json'
16
+
17
+ module BSON
18
+ module Corpus
19
+
20
+ # Represents a test from the driver BSON Corpus.
21
+ #
22
+ # @since 4.2.0
23
+ class Spec
24
+
25
+ # The spec description.
26
+ #
27
+ # @return [ String ] The spec description.
28
+ #
29
+ # @since 4.2.0
30
+ attr_reader :description
31
+
32
+ # The document key of the object to test.
33
+ #
34
+ # @return [ String ] The document key.
35
+ #
36
+ # @since 4.2.0
37
+ attr_reader :test_key
38
+
39
+ # Instantiate the new spec.
40
+ #
41
+ # @example Create the spec.
42
+ # Spec.new(file)
43
+ #
44
+ # @param [ String ] file The name of the json file.
45
+ #
46
+ # @since 4.2.0
47
+ def initialize(file)
48
+ @spec = ::JSON.parse(File.read(file))
49
+ @valid = @spec['valid'] || []
50
+ @invalid = @spec['decodeErrors'] || []
51
+ @description = @spec['description']
52
+ @test_key = @spec['test_key']
53
+ end
54
+
55
+ # Get a list of tests that are expected to pass.
56
+ #
57
+ # @example Get the list of valid tests.
58
+ # spec.valid_tests
59
+ #
60
+ # @return [ Array<BSON::Corpus::Test> ] The list of valid Tests.
61
+ #
62
+ # @since 4.2.0
63
+ def valid_tests
64
+ @valid_tests ||=
65
+ @valid.collect do |test|
66
+ BSON::Corpus::Test.new(self, test)
67
+ end
68
+ end
69
+
70
+ # Get a list of tests that raise exceptions.
71
+ #
72
+ # @example Get the list of invalid tests.
73
+ # spec.invalid_tests
74
+ #
75
+ # @return [ Array<BSON::Corpus::Test> ] The list of invalid Tests.
76
+ #
77
+ # @since 4.2.0
78
+ def invalid_tests
79
+ @invalid_tests ||=
80
+ @invalid.collect do |test|
81
+ BSON::Corpus::Test.new(self, test)
82
+ end
83
+ end
84
+
85
+ # The class of the bson object to test.
86
+ #
87
+ # @example Get the class of the object to test.
88
+ # spec.klass
89
+ #
90
+ # @return [ Class ] The object class.
91
+ #
92
+ # @since 4.2.0
93
+ def klass
94
+ @klass ||= BSON.const_get(description)
95
+ end
96
+ end
97
+
98
+ # Represents a single BSON Corpus test.
99
+ #
100
+ # @since 4.2.0
101
+ class Test
102
+
103
+ # The test description.
104
+ #
105
+ # @return [ String ] The test description.
106
+ #
107
+ # @since 4.2.0
108
+ attr_reader :description
109
+
110
+ # Name of a field in a valid test case extjson document that should be
111
+ # checked against the case's string field.
112
+ #
113
+ # @return [ String ] The json representation of the object.
114
+ #
115
+ # @since 4.2.0
116
+ attr_reader :test_key
117
+
118
+ # Instantiate the new Test.
119
+ #
120
+ # @example Create the test.
121
+ # Test.new(test)
122
+ #
123
+ # @param [ Corpus::Spec ] spec The test specification.
124
+ # @param [ Hash ] test The test specification.
125
+ #
126
+ # @since 4.2.0
127
+ def initialize(spec, test)
128
+ @spec = spec
129
+ @description = test['description']
130
+ @canonical_bson = test['canonical_bson']
131
+ @extjson = ::JSON.parse(test['extjson']) if test['extjson']
132
+ @bson = test['bson']
133
+ @test_key = spec.test_key
134
+ end
135
+
136
+ # The correct representation of the subject as bson.
137
+ #
138
+ # @example Get the correct representation of the subject as bson.
139
+ # test.correct_bson
140
+ #
141
+ # @return [ String ] The correct bson bytes.
142
+ #
143
+ # @since 4.2.0
144
+ def correct_bson
145
+ @correct_bson ||= decode_hex(@canonical_bson || @bson)
146
+ end
147
+
148
+ # Given the hex representation of bson, decode it into a Document,
149
+ # then reencoded it to bson.
150
+ #
151
+ # @example Decoded the bson hex representation, then reencode.
152
+ # test.reencoded_bson
153
+ #
154
+ # @return [ String ] The reencoded bson bytes.
155
+ #
156
+ # @since 4.2.0
157
+ 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
161
+ end
162
+
163
+ # Given the hex representation of the canonical bson, decode it into a Document,
164
+ # then reencoded it to bson.
165
+ #
166
+ # @example Decoded the canonical bson hex representation, then reencode.
167
+ # test.reencoded_canonical_bson
168
+ #
169
+ # @return [ String ] The reencoded canonical bson bytes.
170
+ #
171
+ # @since 4.2.0
172
+ 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
176
+ end
177
+
178
+ # Whether the canonical bson should be tested.
179
+ #
180
+ # @example Determine if the canonical bson should be tested.
181
+ # test.test_canonical_bson?
182
+ #
183
+ # @return [ true, false ] Whether the canonical bson should be tested.
184
+ #
185
+ # @since 4.2.0
186
+ def test_canonical_bson?
187
+ @canonical_bson && (@bson != @canonical_bson)
188
+ end
189
+
190
+ # The correct representation of the subject as extended json.
191
+ #
192
+ # @example Get the correct representation of the subject as extended json.
193
+ # test.correct_extjson
194
+ #
195
+ # @return [ String ] The correct extended json representation.
196
+ #
197
+ # @since 4.2.0
198
+ def correct_extjson
199
+ @canonical_extjson || @extjson
200
+ end
201
+
202
+ # Whether the extended json should be tested.
203
+ #
204
+ # @example Determine if the extended json should be tested.
205
+ # test.test_extjson?
206
+ #
207
+ # @return [ true, false ] Whether the extended json should be tested.
208
+ #
209
+ # @since 4.2.0
210
+ def test_extjson?
211
+ !!@extjson
212
+ end
213
+
214
+ # Get the extended json representation of the decoded doc from the provided
215
+ # bson hex representation.
216
+ #
217
+ # @example Get the extended json representation of the decoded doc.
218
+ # test.extjson_from_encoded_bson
219
+ #
220
+ # @return [ Hash ] The extended json representation.
221
+ #
222
+ # @since 4.2.0
223
+ 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)
227
+ end
228
+
229
+ # Get the extended json representation of the decoded doc from the provided
230
+ # canonical bson hex representation.
231
+ #
232
+ # @example Get the extended json representation of the canonical decoded doc.
233
+ # test.extjson_from_canonical_bson
234
+ #
235
+ # @return [ Hash ] The extended json representation.
236
+ #
237
+ # @since 4.2.0
238
+ 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)
242
+ end
243
+
244
+ # Get the extended json representation of the decoded doc from the provided
245
+ # extended json representation. (Verifies roundtrip)
246
+ #
247
+ # @example Get the extended json representation of the canonical decoded doc.
248
+ # test.extjson_from_encoded_extjson
249
+ #
250
+ # @return [ Hash ] The extended json representation.
251
+ #
252
+ # @since 4.2.0
253
+ def extjson_from_encoded_extjson
254
+ doc = BSON::Document.new(@extjson)
255
+ ::JSON.parse(doc.to_json)
256
+ end
257
+
258
+ private
259
+
260
+ def decode_hex(obj)
261
+ [ obj ].pack('H*')
262
+ end
263
+ end
264
+ end
265
+ end
@@ -50,7 +50,7 @@ shared_examples_for "a deserializable bson element" do
50
50
  end
51
51
 
52
52
  let(:result) do
53
- described_class.from_bson(io)
53
+ (defined?(klass) ? klass : described_class).from_bson(io)
54
54
  end
55
55
 
56
56
  it "deserializes from bson" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0.rc1
4
+ version: 4.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - Tyler Brock
@@ -34,7 +34,7 @@ cert_chain:
34
34
  yVPbgNJA2D/PnLe8ZFMhgJf+VIA1V4oybP/o+9aqlghTtNfYHJpRCAluUiaywwXl
35
35
  KzD4mmIBpxtbWrWB3hx7tsVJmWx5zgO9aDAfvWnXfoo=
36
36
  -----END CERTIFICATE-----
37
- date: 2016-11-01 00:00:00.000000000 Z
37
+ date: 2016-12-19 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: A full featured BSON specification implementation, in Ruby
40
40
  email:
@@ -93,6 +93,7 @@ files:
93
93
  - spec/bson/code_spec.rb
94
94
  - spec/bson/code_with_scope_spec.rb
95
95
  - spec/bson/config_spec.rb
96
+ - spec/bson/corpus_spec.rb
96
97
  - spec/bson/date_spec.rb
97
98
  - spec/bson/date_time_spec.rb
98
99
  - spec/bson/decimal128_spec.rb
@@ -111,6 +112,7 @@ files:
111
112
  - spec/bson/object_id_spec.rb
112
113
  - spec/bson/object_spec.rb
113
114
  - spec/bson/open_struct_spec.rb
115
+ - spec/bson/raw_spec.rb
114
116
  - spec/bson/regexp_spec.rb
115
117
  - spec/bson/registry_spec.rb
116
118
  - spec/bson/string_spec.rb
@@ -122,6 +124,28 @@ files:
122
124
  - spec/bson_spec.rb
123
125
  - spec/spec_helper.rb
124
126
  - spec/support/common_driver.rb
127
+ - spec/support/corpus-tests/array.json
128
+ - spec/support/corpus-tests/boolean.json
129
+ - spec/support/corpus-tests/code.json
130
+ - spec/support/corpus-tests/code_w_scope.json
131
+ - spec/support/corpus-tests/document.json
132
+ - spec/support/corpus-tests/double.json
133
+ - spec/support/corpus-tests/failures/binary.json
134
+ - spec/support/corpus-tests/failures/datetime.json
135
+ - spec/support/corpus-tests/failures/dbpointer.json
136
+ - spec/support/corpus-tests/failures/int64.json
137
+ - spec/support/corpus-tests/failures/symbol.json
138
+ - spec/support/corpus-tests/failures/undefined.json
139
+ - spec/support/corpus-tests/int32.json
140
+ - spec/support/corpus-tests/maxkey.json
141
+ - spec/support/corpus-tests/minkey.json
142
+ - spec/support/corpus-tests/null.json
143
+ - spec/support/corpus-tests/oid.json
144
+ - spec/support/corpus-tests/regex.json
145
+ - spec/support/corpus-tests/string.json
146
+ - spec/support/corpus-tests/timestamp.json
147
+ - spec/support/corpus-tests/top.json
148
+ - spec/support/corpus.rb
125
149
  - spec/support/driver-spec-tests/decimal128/decimal128-1.json
126
150
  - spec/support/driver-spec-tests/decimal128/decimal128-2.json
127
151
  - spec/support/driver-spec-tests/decimal128/decimal128-3.json
@@ -150,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
174
  version: 1.3.6
151
175
  requirements: []
152
176
  rubyforge_project: bson
153
- rubygems_version: 2.6.6
177
+ rubygems_version: 2.6.8
154
178
  signing_key:
155
179
  specification_version: 4
156
180
  summary: Ruby Implementation of the BSON specification
@@ -164,6 +188,7 @@ test_files:
164
188
  - spec/bson/code_spec.rb
165
189
  - spec/bson/code_with_scope_spec.rb
166
190
  - spec/bson/config_spec.rb
191
+ - spec/bson/corpus_spec.rb
167
192
  - spec/bson/date_spec.rb
168
193
  - spec/bson/date_time_spec.rb
169
194
  - spec/bson/decimal128_spec.rb
@@ -182,6 +207,7 @@ test_files:
182
207
  - spec/bson/object_id_spec.rb
183
208
  - spec/bson/object_spec.rb
184
209
  - spec/bson/open_struct_spec.rb
210
+ - spec/bson/raw_spec.rb
185
211
  - spec/bson/regexp_spec.rb
186
212
  - spec/bson/registry_spec.rb
187
213
  - spec/bson/string_spec.rb
@@ -191,7 +217,29 @@ test_files:
191
217
  - spec/bson/true_class_spec.rb
192
218
  - spec/bson/undefined_spec.rb
193
219
  - spec/support/common_driver.rb
220
+ - spec/support/corpus.rb
194
221
  - spec/support/shared_examples.rb
222
+ - spec/support/corpus-tests/array.json
223
+ - spec/support/corpus-tests/boolean.json
224
+ - spec/support/corpus-tests/code.json
225
+ - spec/support/corpus-tests/code_w_scope.json
226
+ - spec/support/corpus-tests/document.json
227
+ - spec/support/corpus-tests/double.json
228
+ - spec/support/corpus-tests/int32.json
229
+ - spec/support/corpus-tests/maxkey.json
230
+ - spec/support/corpus-tests/minkey.json
231
+ - spec/support/corpus-tests/null.json
232
+ - spec/support/corpus-tests/oid.json
233
+ - spec/support/corpus-tests/regex.json
234
+ - spec/support/corpus-tests/string.json
235
+ - spec/support/corpus-tests/timestamp.json
236
+ - spec/support/corpus-tests/top.json
237
+ - spec/support/corpus-tests/failures/binary.json
238
+ - spec/support/corpus-tests/failures/datetime.json
239
+ - spec/support/corpus-tests/failures/dbpointer.json
240
+ - spec/support/corpus-tests/failures/int64.json
241
+ - spec/support/corpus-tests/failures/symbol.json
242
+ - spec/support/corpus-tests/failures/undefined.json
195
243
  - spec/support/driver-spec-tests/decimal128/decimal128-1.json
196
244
  - spec/support/driver-spec-tests/decimal128/decimal128-2.json
197
245
  - spec/support/driver-spec-tests/decimal128/decimal128-3.json
metadata.gz.sig CHANGED
Binary file