bson 4.11.1-java → 4.14.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +4 -7
  4. data/lib/bson/active_support.rb +1 -0
  5. data/lib/bson/array.rb +2 -1
  6. data/lib/bson/big_decimal.rb +67 -0
  7. data/lib/bson/binary.rb +8 -5
  8. data/lib/bson/boolean.rb +2 -1
  9. data/lib/bson/code.rb +2 -1
  10. data/lib/bson/code_with_scope.rb +2 -1
  11. data/lib/bson/config.rb +1 -0
  12. data/lib/bson/date.rb +1 -0
  13. data/lib/bson/date_time.rb +1 -0
  14. data/lib/bson/db_pointer.rb +2 -1
  15. data/lib/bson/dbref.rb +125 -0
  16. data/lib/bson/decimal128/builder.rb +27 -20
  17. data/lib/bson/decimal128.rb +27 -12
  18. data/lib/bson/document.rb +61 -18
  19. data/lib/bson/environment.rb +1 -0
  20. data/lib/bson/error.rb +7 -0
  21. data/lib/bson/ext_json.rb +24 -11
  22. data/lib/bson/false_class.rb +2 -1
  23. data/lib/bson/float.rb +21 -32
  24. data/lib/bson/hash.rb +15 -6
  25. data/lib/bson/int32.rb +3 -2
  26. data/lib/bson/int64.rb +3 -2
  27. data/lib/bson/integer.rb +3 -2
  28. data/lib/bson/json.rb +1 -0
  29. data/lib/bson/max_key.rb +3 -2
  30. data/lib/bson/min_key.rb +3 -2
  31. data/lib/bson/nil_class.rb +2 -1
  32. data/lib/bson/object.rb +1 -0
  33. data/lib/bson/object_id.rb +4 -3
  34. data/lib/bson/open_struct.rb +1 -0
  35. data/lib/bson/regexp.rb +17 -6
  36. data/lib/bson/registry.rb +1 -0
  37. data/lib/bson/specialized.rb +1 -0
  38. data/lib/bson/string.rb +3 -2
  39. data/lib/bson/symbol.rb +2 -1
  40. data/lib/bson/time.rb +4 -3
  41. data/lib/bson/time_with_zone.rb +1 -0
  42. data/lib/bson/timestamp.rb +3 -2
  43. data/lib/bson/true_class.rb +2 -1
  44. data/lib/bson/undefined.rb +2 -1
  45. data/lib/bson/version.rb +2 -1
  46. data/lib/bson-ruby.jar +0 -0
  47. data/lib/bson.rb +8 -5
  48. data/lib/bson_native.bundle +0 -0
  49. data/spec/README.md +14 -0
  50. data/spec/bson/big_decimal_spec.rb +316 -0
  51. data/spec/bson/binary_spec.rb +1 -1
  52. data/spec/bson/binary_uuid_spec.rb +12 -0
  53. data/spec/bson/dbref_spec.rb +461 -0
  54. data/spec/bson/decimal128_spec.rb +16 -0
  55. data/spec/bson/document_as_spec.rb +46 -0
  56. data/spec/bson/document_spec.rb +43 -1
  57. data/spec/bson/ext_json_parse_spec.rb +37 -0
  58. data/spec/bson/hash_as_spec.rb +57 -0
  59. data/spec/bson/hash_spec.rb +32 -0
  60. data/spec/bson/int64_spec.rb +4 -24
  61. data/spec/bson/raw_spec.rb +7 -1
  62. data/spec/bson/regexp_spec.rb +52 -0
  63. data/spec/runners/common_driver.rb +1 -1
  64. data/spec/shared/LICENSE +20 -0
  65. data/spec/shared/bin/get-mongodb-download-url +17 -0
  66. data/spec/shared/bin/s3-copy +45 -0
  67. data/spec/shared/bin/s3-upload +69 -0
  68. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  69. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  70. data/spec/shared/lib/mrss/constraints.rb +386 -0
  71. data/spec/shared/lib/mrss/docker_runner.rb +271 -0
  72. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  73. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  74. data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
  75. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  76. data/spec/shared/lib/mrss/utils.rb +15 -0
  77. data/spec/shared/share/Dockerfile.erb +338 -0
  78. data/spec/shared/share/haproxy-1.conf +16 -0
  79. data/spec/shared/share/haproxy-2.conf +17 -0
  80. data/spec/shared/shlib/distro.sh +74 -0
  81. data/spec/shared/shlib/server.sh +367 -0
  82. data/spec/shared/shlib/set_env.sh +131 -0
  83. data/spec/spec_helper.rb +20 -0
  84. data/spec/spec_tests/common_driver_spec.rb +2 -1
  85. data/spec/spec_tests/data/corpus/binary.json +33 -0
  86. data/spec/spec_tests/data/corpus/dbref.json +21 -1
  87. data/spec/spec_tests/data/corpus/document.json +4 -0
  88. data/spec/spec_tests/data/corpus/regex.json +2 -2
  89. data/spec/spec_tests/data/corpus/top.json +20 -9
  90. data/spec/support/spec_config.rb +2 -1
  91. data.tar.gz.sig +0 -0
  92. metadata +156 -105
  93. metadata.gz.sig +0 -0
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (C) 2009-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,12 +27,12 @@ module BSON
26
27
  # A timestamp is type 0x11 in the BSON spec.
27
28
  #
28
29
  # @since 2.0.0
29
- BSON_TYPE = 17.chr.force_encoding(BINARY).freeze
30
+ BSON_TYPE = ::String.new(17.chr, encoding: BINARY).freeze
30
31
 
31
32
  # Error message if an object other than a Timestamp is compared with this object.
32
33
  #
33
34
  # @since 4.3.0
34
- COMPARISON_ERROR_MESSAGE = 'comparison of %s with Timestamp failed'.freeze
35
+ COMPARISON_ERROR_MESSAGE = 'comparison of %s with Timestamp failed'
35
36
 
36
37
  # @!attribute seconds
37
38
  # @return [ Integer ] The number of seconds.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (C) 2009-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +26,7 @@ module BSON
25
26
  # A true value in the BSON spec is 0x01.
26
27
  #
27
28
  # @since 2.0.0
28
- TRUE_BYTE = 1.chr.force_encoding(BINARY).freeze
29
+ TRUE_BYTE = ::String.new(1.chr, encoding: BINARY).freeze
29
30
 
30
31
  # The BSON type for true values is the general boolean type of 0x08.
31
32
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (C) 2009-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +26,7 @@ module BSON
25
26
  # Undefined is type 0x06 in the BSON spec.
26
27
  #
27
28
  # @since 2.0.0
28
- BSON_TYPE = 6.chr.force_encoding(BINARY).freeze
29
+ BSON_TYPE = ::String.new(6.chr, encoding: BINARY).freeze
29
30
 
30
31
  # Determine if undefined is equal to another object.
31
32
  #
data/lib/bson/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (C) 2009-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,5 +14,5 @@
13
14
  # limitations under the License.
14
15
 
15
16
  module BSON
16
- VERSION = "4.11.1".freeze
17
+ VERSION = "4.14.0"
17
18
  end
data/lib/bson-ruby.jar CHANGED
Binary file
data/lib/bson.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (C) 2009-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,22 +39,22 @@ module BSON
38
39
  # Constant for binary string encoding.
39
40
  #
40
41
  # @since 2.0.0
41
- BINARY = "BINARY".freeze
42
+ BINARY = "BINARY"
42
43
 
43
44
  # Constant for bson types that don't actually serialize a value.
44
45
  #
45
46
  # @since 2.0.0
46
- NO_VALUE = "".force_encoding(BINARY).freeze
47
+ NO_VALUE = ::String.new(encoding: BINARY).freeze
47
48
 
48
49
  # Constant for a null byte (0x00).
49
50
  #
50
51
  # @since 2.0.0
51
- NULL_BYTE = 0.chr.force_encoding(BINARY).freeze
52
+ NULL_BYTE = ::String.new(0.chr, encoding: BINARY).freeze
52
53
 
53
54
  # Constant for UTF-8 string encoding.
54
55
  #
55
56
  # @since 2.0.0
56
- UTF8 = "UTF-8".freeze
57
+ UTF8 = "UTF-8"
57
58
  end
58
59
 
59
60
  require "bson/config"
@@ -73,11 +74,13 @@ require "bson/date"
73
74
  require "bson/date_time"
74
75
  require "bson/db_pointer"
75
76
  require "bson/decimal128"
77
+ require "bson/big_decimal"
76
78
  require "bson/document"
77
79
  require "bson/ext_json"
78
80
  require "bson/false_class"
79
81
  require "bson/float"
80
82
  require "bson/hash"
83
+ require "bson/dbref"
81
84
  require "bson/open_struct"
82
85
  require "bson/max_key"
83
86
  require "bson/min_key"
@@ -100,7 +103,7 @@ require "bson/version"
100
103
  begin
101
104
  if BSON::Environment.jruby?
102
105
  require "bson-ruby.jar"
103
- org.bson.NativeService.new.basicLoad(JRuby.runtime)
106
+ JRuby::Util.load_ext("org.bson.NativeService")
104
107
  else
105
108
  require "bson_native"
106
109
  end
Binary file
data/spec/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Running BSON Ruby Tests
2
+
3
+ ## Quick Start
4
+
5
+ The test suite requires shared tooling that is stored in a separate repository
6
+ and is referenced as a submodule. After checking out the desired bson-ruby
7
+ branch, check out the matching submodules:
8
+
9
+ git submodule init
10
+ git submodule update
11
+
12
+ Then, to run the test suite:
13
+
14
+ rake
@@ -0,0 +1,316 @@
1
+ # Copyright (C) 2016-2021 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 "spec_helper"
16
+
17
+ describe BSON::BigDecimal do
18
+
19
+ describe '#from_bson' do
20
+ shared_examples_for 'a BSON::BigDecimal deserializer' do
21
+
22
+ let(:decimal128) do
23
+ BSON::Decimal128.new(argument)
24
+ end
25
+
26
+ let(:deserialized_big_decimal) do
27
+ BigDecimal.from_bson(decimal128.to_bson)
28
+ end
29
+
30
+ let(:deserialized_decimal128) do
31
+ BSON::Decimal128.from_bson(decimal128.to_bson)
32
+ end
33
+
34
+ it 'deserializes Decimal128 encoded bson correctly' do
35
+ if deserialized_decimal128.to_s == "NaN"
36
+ expect(deserialized_big_decimal.nan?).to be true
37
+ else
38
+ expect(deserialized_big_decimal).to eq(deserialized_decimal128.to_big_decimal)
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'when Infinity is passed' do
44
+
45
+ let(:argument) { "Infinity" }
46
+
47
+ it_behaves_like 'a BSON::BigDecimal deserializer'
48
+ end
49
+
50
+ context 'when -Infinity is passed' do
51
+
52
+ let(:argument) { "-Infinity" }
53
+
54
+ it_behaves_like 'a BSON::BigDecimal deserializer'
55
+ end
56
+
57
+ context 'when NaN is passed' do
58
+
59
+ let(:argument) { "NaN" }
60
+
61
+ it_behaves_like 'a BSON::BigDecimal deserializer'
62
+ end
63
+
64
+ context 'when -NaN is passed' do
65
+ let(:argument) { "-NaN" }
66
+
67
+ it_behaves_like 'a BSON::BigDecimal deserializer'
68
+ end
69
+
70
+ context 'when SNaN is passed' do
71
+ let(:argument) { "SNaN" }
72
+
73
+ it_behaves_like 'a BSON::BigDecimal deserializer'
74
+ end
75
+
76
+ context 'when -SNaN is passed' do
77
+ let(:argument) { "SNaN" }
78
+
79
+ it_behaves_like 'a BSON::BigDecimal deserializer'
80
+ end
81
+
82
+ context 'when -0 is passed' do
83
+ let(:argument) { "-0" }
84
+
85
+ it_behaves_like 'a BSON::BigDecimal deserializer'
86
+ end
87
+
88
+ context 'when a positive integer is passed' do
89
+ let(:argument) { "12" }
90
+
91
+ it_behaves_like 'a BSON::BigDecimal deserializer'
92
+ end
93
+
94
+ context 'when a negative integer is passed' do
95
+ let(:argument) { "-12" }
96
+
97
+ it_behaves_like 'a BSON::BigDecimal deserializer'
98
+ end
99
+
100
+ context 'when a positive float is passed' do
101
+ let(:argument) { "0.12345" }
102
+
103
+ it_behaves_like 'a BSON::BigDecimal deserializer'
104
+ end
105
+
106
+ context 'when a negative float is passed' do
107
+ let(:argument) { "-0.12345" }
108
+
109
+ it_behaves_like 'a BSON::BigDecimal deserializer'
110
+ end
111
+
112
+ context 'when a large positive integer is passed' do
113
+ let(:argument) { "1234567890123456789012345678901234" }
114
+
115
+ it_behaves_like 'a BSON::BigDecimal deserializer'
116
+ end
117
+
118
+ context 'when a large negative integer is passed' do
119
+ let(:argument) { "-1234567890123456789012345678901234" }
120
+
121
+ it_behaves_like 'a BSON::BigDecimal deserializer'
122
+ end
123
+ end
124
+
125
+ describe "#to_bson" do
126
+ shared_examples_for 'a BSON::BigDecimal serializer' do
127
+
128
+ let(:decimal128) do
129
+ BSON::Decimal128.new(BigDecimal(argument).to_s)
130
+ end
131
+
132
+ let(:decimal_128_bson) do
133
+ decimal128.to_bson
134
+ end
135
+
136
+ let(:big_decimal_bson) do
137
+ BigDecimal(argument).to_bson
138
+ end
139
+
140
+ it 'serializes BigDecimals correctly' do
141
+ expect(decimal_128_bson.to_s).to eq(big_decimal_bson.to_s)
142
+ end
143
+ end
144
+
145
+ context 'when Infinity is passed' do
146
+
147
+ let(:argument) { "Infinity" }
148
+
149
+ it_behaves_like 'a BSON::BigDecimal serializer'
150
+ end
151
+
152
+ context 'when -Infinity is passed' do
153
+
154
+ let(:argument) { "-Infinity" }
155
+
156
+ it_behaves_like 'a BSON::BigDecimal serializer'
157
+ end
158
+
159
+ context 'when NaN is passed' do
160
+
161
+ let(:argument) { "NaN" }
162
+
163
+ it_behaves_like 'a BSON::BigDecimal serializer'
164
+ end
165
+
166
+ context 'when -0 is passed' do
167
+ let(:argument) { "-0" }
168
+
169
+ it_behaves_like 'a BSON::BigDecimal serializer'
170
+ end
171
+
172
+ context 'when a positive integer is passed' do
173
+ let(:argument) { "12" }
174
+
175
+ it_behaves_like 'a BSON::BigDecimal serializer'
176
+ end
177
+
178
+ context 'when a negative integer is passed' do
179
+ let(:argument) { "-12" }
180
+
181
+ it_behaves_like 'a BSON::BigDecimal serializer'
182
+ end
183
+
184
+ context 'when a positive float is passed' do
185
+ let(:argument) { "0.12345" }
186
+
187
+ it_behaves_like 'a BSON::BigDecimal serializer'
188
+ end
189
+
190
+ context 'when a negative float is passed' do
191
+ let(:argument) { "-0.12345" }
192
+
193
+ it_behaves_like 'a BSON::BigDecimal serializer'
194
+ end
195
+
196
+ context 'when a large positive integer is passed' do
197
+ let(:argument) { "1234567890123456789012345678901234" }
198
+
199
+ it_behaves_like 'a BSON::BigDecimal serializer'
200
+ end
201
+
202
+ context 'when a large negative integer is passed' do
203
+ let(:argument) { "-1234567890123456789012345678901234" }
204
+
205
+ it_behaves_like 'a BSON::BigDecimal serializer'
206
+ end
207
+
208
+ context "when passing an out of range Decimal128" do
209
+ let(:argument) { "1E1000000" }
210
+
211
+ it "raises an error" do
212
+ expect do
213
+ BigDecimal(argument).to_bson
214
+ end.to raise_error(BSON::Decimal128::InvalidRange)
215
+ end
216
+ end
217
+
218
+ context "when passing a number with too much precision for Decimal128" do
219
+ let(:argument) { "1.000000000000000000000000000000000000000000000000001" }
220
+
221
+ it "raises an error" do
222
+ expect do
223
+ BigDecimal(argument).to_bson
224
+ end.to raise_error(BSON::Decimal128::UnrepresentablePrecision)
225
+ end
226
+ end
227
+ end
228
+
229
+ describe "#from_bson/#to_bson" do
230
+ shared_examples_for 'a BSON::BigDecimal round trip' do
231
+
232
+ let(:big_decimal) do
233
+ BigDecimal(argument)
234
+ end
235
+
236
+ let(:big_decimal_bson) do
237
+ big_decimal.to_bson
238
+ end
239
+
240
+ let(:deserialized_big_decimal) do
241
+ BigDecimal.from_bson(big_decimal_bson)
242
+ end
243
+
244
+ it 'serializes BigDecimals correctly' do
245
+ if big_decimal.nan?
246
+ expect(deserialized_big_decimal.nan?).to be true
247
+ else
248
+ expect(deserialized_big_decimal).to eq(big_decimal)
249
+ end
250
+ end
251
+ end
252
+
253
+ context 'when Infinity is passed' do
254
+
255
+ let(:argument) { "Infinity" }
256
+
257
+ it_behaves_like 'a BSON::BigDecimal round trip'
258
+ end
259
+
260
+ context 'when -Infinity is passed' do
261
+
262
+ let(:argument) { "-Infinity" }
263
+
264
+ it_behaves_like 'a BSON::BigDecimal round trip'
265
+ end
266
+
267
+ context 'when NaN is passed' do
268
+
269
+ let(:argument) { "NaN" }
270
+
271
+ it_behaves_like 'a BSON::BigDecimal round trip'
272
+ end
273
+
274
+ context 'when -0 is passed' do
275
+ let(:argument) { "-0" }
276
+
277
+ it_behaves_like 'a BSON::BigDecimal round trip'
278
+ end
279
+
280
+ context 'when a positive integer is passed' do
281
+ let(:argument) { "12" }
282
+
283
+ it_behaves_like 'a BSON::BigDecimal round trip'
284
+ end
285
+
286
+ context 'when a negative integer is passed' do
287
+ let(:argument) { "-12" }
288
+
289
+ it_behaves_like 'a BSON::BigDecimal round trip'
290
+ end
291
+
292
+ context 'when a positive float is passed' do
293
+ let(:argument) { "0.12345" }
294
+
295
+ it_behaves_like 'a BSON::BigDecimal round trip'
296
+ end
297
+
298
+ context 'when a negative float is passed' do
299
+ let(:argument) { "-0.12345" }
300
+
301
+ it_behaves_like 'a BSON::BigDecimal round trip'
302
+ end
303
+
304
+ context 'when a large positive integer is passed' do
305
+ let(:argument) { "1234567890123456789012345678901234" }
306
+
307
+ it_behaves_like 'a BSON::BigDecimal round trip'
308
+ end
309
+
310
+ context 'when a large negative integer is passed' do
311
+ let(:argument) { "-1234567890123456789012345678901234" }
312
+
313
+ it_behaves_like 'a BSON::BigDecimal round trip'
314
+ end
315
+ end
316
+ end
@@ -255,7 +255,7 @@ describe BSON::Binary do
255
255
  let(:obj) { described_class.new("\x00" * 16, :uuid) }
256
256
 
257
257
  it 'accepts symbol representation' do
258
- expect(obj.to_uuid(:standard)).to eq('00000000-0000-0000-0000000000000000')
258
+ expect(obj.to_uuid(:standard)).to eq('00000000-0000-0000-0000-000000000000')
259
259
  end
260
260
 
261
261
  it 'rejects string representation' do
@@ -136,6 +136,10 @@ describe "BSON::Binary - UUID spec tests" do
136
136
  it 'decodes as python legacy' do
137
137
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
138
138
  end
139
+
140
+ it 'expects four dashes when output as String' do
141
+ expect(binary.to_uuid(:csharp_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
142
+ end
139
143
  end
140
144
 
141
145
  context ':uuid_old, java legacy encoded' do
@@ -154,6 +158,10 @@ describe "BSON::Binary - UUID spec tests" do
154
158
  it 'decodes as python legacy' do
155
159
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
156
160
  end
161
+
162
+ it 'expects four dashes when output as String' do
163
+ expect(binary.to_uuid(:java_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
164
+ end
157
165
  end
158
166
 
159
167
  context ':uuid_old, python legacy encoded' do
@@ -172,6 +180,10 @@ describe "BSON::Binary - UUID spec tests" do
172
180
  it 'decodes as python legacy' do
173
181
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
174
182
  end
183
+
184
+ it 'expects four dashes when output as String' do
185
+ expect(binary.to_uuid(:python_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
186
+ end
175
187
  end
176
188
  end
177
189
  end