bson 4.14.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +4 -4
- data/Rakefile +5 -0
- data/ext/bson/bson-native.h +12 -4
- data/ext/bson/extconf.rb +8 -3
- data/ext/bson/init.c +11 -11
- data/ext/bson/read.c +21 -6
- data/ext/bson/util.c +168 -16
- data/ext/bson/write.c +30 -39
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +57 -31
- data/lib/bson/big_decimal.rb +16 -6
- data/lib/bson/binary.rb +255 -128
- data/lib/bson/boolean.rb +1 -0
- data/lib/bson/code.rb +9 -11
- data/lib/bson/code_with_scope.rb +8 -10
- data/lib/bson/config.rb +1 -27
- data/lib/bson/date.rb +2 -1
- data/lib/bson/date_time.rb +2 -1
- data/lib/bson/db_pointer.rb +11 -12
- data/lib/bson/dbref.rb +11 -9
- data/lib/bson/decimal128/builder.rb +9 -8
- data/lib/bson/decimal128.rb +33 -109
- data/lib/bson/document.rb +1 -0
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error/bson_decode_error.rb +11 -0
- data/lib/bson/error/ext_json_parse_error.rb +11 -0
- data/lib/bson/error/illegal_key.rb +23 -0
- data/lib/bson/error/invalid_binary_type.rb +37 -0
- data/lib/bson/error/invalid_dbref_argument.rb +12 -0
- data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
- data/lib/bson/error/invalid_decimal128_range.rb +27 -0
- data/lib/bson/error/invalid_decimal128_string.rb +26 -0
- data/lib/bson/error/invalid_key.rb +24 -0
- data/lib/bson/error/invalid_object_id.rb +11 -0
- data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
- data/lib/bson/error/unrepresentable_precision.rb +19 -0
- data/lib/bson/error/unserializable_class.rb +13 -0
- data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
- data/lib/bson/error/unsupported_type.rb +11 -0
- data/lib/bson/error.rb +16 -28
- data/lib/bson/ext_json.rb +1 -0
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +2 -1
- data/lib/bson/hash.rb +127 -72
- data/lib/bson/int32.rb +16 -4
- data/lib/bson/int64.rb +16 -4
- data/lib/bson/integer.rb +3 -4
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +7 -9
- data/lib/bson/min_key.rb +7 -9
- data/lib/bson/nil_class.rb +1 -0
- data/lib/bson/object.rb +5 -25
- data/lib/bson/object_id.rb +75 -121
- data/lib/bson/open_struct.rb +3 -2
- data/lib/bson/regexp.rb +35 -64
- data/lib/bson/registry.rb +2 -6
- data/lib/bson/specialized.rb +2 -1
- data/lib/bson/string.rb +4 -27
- data/lib/bson/symbol.rb +22 -19
- data/lib/bson/time.rb +2 -1
- data/lib/bson/time_with_zone.rb +13 -1
- data/lib/bson/timestamp.rb +2 -1
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +14 -0
- data/lib/bson/version.rb +2 -1
- data/lib/bson.rb +3 -2
- data/spec/bson/array_spec.rb +19 -60
- data/spec/bson/big_decimal_spec.rb +16 -4
- data/spec/bson/binary_spec.rb +83 -74
- data/spec/bson/binary_uuid_spec.rb +1 -0
- data/spec/bson/boolean_spec.rb +1 -0
- data/spec/bson/byte_buffer_read_spec.rb +1 -0
- data/spec/bson/byte_buffer_spec.rb +1 -0
- data/spec/bson/byte_buffer_write_spec.rb +1 -0
- data/spec/bson/code_spec.rb +5 -3
- data/spec/bson/code_with_scope_spec.rb +5 -3
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +1 -0
- data/spec/bson/date_time_spec.rb +1 -0
- data/spec/bson/dbref_legacy_spec.rb +20 -3
- data/spec/bson/dbref_spec.rb +9 -9
- data/spec/bson/decimal128_spec.rb +249 -14
- data/spec/bson/document_as_spec.rb +1 -0
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/ext_json_parse_spec.rb +1 -0
- data/spec/bson/false_class_spec.rb +8 -0
- data/spec/bson/float_spec.rb +8 -3
- data/spec/bson/hash_as_spec.rb +1 -0
- data/spec/bson/hash_spec.rb +87 -75
- data/spec/bson/int32_spec.rb +21 -6
- data/spec/bson/int64_spec.rb +21 -6
- data/spec/bson/integer_spec.rb +45 -13
- data/spec/bson/json_spec.rb +1 -0
- data/spec/bson/max_key_spec.rb +5 -3
- data/spec/bson/min_key_spec.rb +5 -3
- data/spec/bson/nil_class_spec.rb +1 -0
- data/spec/bson/object_id_spec.rb +43 -4
- data/spec/bson/object_spec.rb +2 -1
- data/spec/bson/open_struct_spec.rb +14 -71
- data/spec/bson/raw_spec.rb +9 -15
- data/spec/bson/regexp_spec.rb +4 -3
- data/spec/bson/registry_spec.rb +2 -1
- data/spec/bson/string_spec.rb +13 -38
- data/spec/bson/symbol_raw_spec.rb +25 -0
- data/spec/bson/symbol_spec.rb +15 -18
- data/spec/bson/time_spec.rb +1 -0
- data/spec/bson/time_with_zone_spec.rb +1 -0
- data/spec/bson/timestamp_spec.rb +1 -0
- data/spec/bson/true_class_spec.rb +8 -0
- data/spec/bson/undefined_spec.rb +27 -0
- data/spec/bson_spec.rb +1 -0
- data/spec/runners/common_driver.rb +6 -5
- data/spec/runners/corpus.rb +6 -0
- data/spec/runners/corpus_legacy.rb +1 -0
- data/spec/shared/lib/mrss/constraints.rb +8 -16
- data/spec/shared/lib/mrss/docker_runner.rb +30 -3
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +68 -85
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/server.sh +73 -24
- data/spec/shared/shlib/set_env.sh +39 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_tests/common_driver_spec.rb +9 -4
- data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
- data/spec/spec_tests/corpus_spec.rb +13 -3
- data/spec/spec_tests/data/corpus/binary.json +5 -0
- data/spec/spec_tests/data/corpus/code.json +13 -13
- data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
- data/spec/spec_tests/data/corpus/document.json +20 -0
- data/spec/spec_tests/data/corpus/symbol.json +7 -7
- data/spec/spec_tests/data/corpus/top.json +18 -3
- data/spec/support/shared_examples.rb +28 -5
- data/spec/support/spec_config.rb +1 -0
- data/spec/support/utils.rb +49 -1
- data.tar.gz.sig +0 -0
- metadata +167 -143
- metadata.gz.sig +0 -0
data/spec/bson/code_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,17 +17,18 @@ require "spec_helper"
|
|
16
17
|
|
17
18
|
describe BSON::Code do
|
18
19
|
|
19
|
-
describe "#
|
20
|
+
describe "#as_extended_json" do
|
20
21
|
|
21
22
|
let(:object) do
|
22
23
|
described_class.new("this.value = 5")
|
23
24
|
end
|
24
25
|
|
25
26
|
it "returns the binary data plus type" do
|
26
|
-
expect(object.
|
27
|
+
expect(object.as_extended_json).to eq({ "$code" => "this.value = 5" })
|
27
28
|
end
|
28
29
|
|
29
|
-
it_behaves_like
|
30
|
+
it_behaves_like 'an Extended JSON serializable object'
|
31
|
+
it_behaves_like '#as_json calls #as_extended_json'
|
30
32
|
end
|
31
33
|
|
32
34
|
describe "#to_bson/#from_bson" do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -39,19 +40,20 @@ describe BSON::CodeWithScope do
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
describe "#
|
43
|
+
describe "#as_extended_json" do
|
43
44
|
|
44
45
|
let(:object) do
|
45
46
|
described_class.new("this.value = val", :val => "test")
|
46
47
|
end
|
47
48
|
|
48
49
|
it "returns the binary data plus type" do
|
49
|
-
expect(object.
|
50
|
+
expect(object.as_extended_json).to eq(
|
50
51
|
{ "$code" => "this.value = val", "$scope" => { :val => "test" }}
|
51
52
|
)
|
52
53
|
end
|
53
54
|
|
54
|
-
it_behaves_like
|
55
|
+
it_behaves_like 'an Extended JSON serializable object'
|
56
|
+
it_behaves_like '#as_json calls #as_extended_json'
|
55
57
|
end
|
56
58
|
|
57
59
|
describe "#to_bson" do
|
data/spec/bson/config_spec.rb
CHANGED
@@ -1,40 +1,6 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe BSON::Config do
|
4
5
|
|
5
|
-
describe "#validating_keys?" do
|
6
|
-
|
7
|
-
context "when the default is used" do
|
8
|
-
|
9
|
-
it "returns false" do
|
10
|
-
expect(described_class).to_not be_validating_keys
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when configuring to false" do
|
15
|
-
|
16
|
-
before do
|
17
|
-
BSON::Config.validating_keys = false
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns false" do
|
21
|
-
expect(described_class).to_not be_validating_keys
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when configuring to true" do
|
26
|
-
|
27
|
-
before do
|
28
|
-
BSON::Config.validating_keys = true
|
29
|
-
end
|
30
|
-
|
31
|
-
after do
|
32
|
-
BSON::Config.validating_keys = false
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns true" do
|
36
|
-
expect(described_class).to be_validating_keys
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
6
|
end
|
data/spec/bson/date_spec.rb
CHANGED
data/spec/bson/date_time_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
#
|
2
|
+
# rubocop:todo all
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
require 'json'
|
@@ -8,7 +8,24 @@ require 'json'
|
|
8
8
|
# class, and are intended to verify that the current DBRef implementation is
|
9
9
|
# compatible with the legacy driver DBRef interface.
|
10
10
|
|
11
|
-
|
11
|
+
# For testing a class that emits warnings, without spamming the terminal
|
12
|
+
# with them.
|
13
|
+
def silenced_version_of(klass)
|
14
|
+
Class.new(klass) do
|
15
|
+
class <<self
|
16
|
+
def name
|
17
|
+
"#{superclass.name} (silenced)"
|
18
|
+
end
|
19
|
+
|
20
|
+
alias to_s name
|
21
|
+
end
|
22
|
+
|
23
|
+
def warn(*_args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe silenced_version_of BSON::DBRef do
|
12
29
|
|
13
30
|
let(:object_id) do
|
14
31
|
BSON::ObjectId.new
|
@@ -76,7 +93,7 @@ describe BSON::DBRef do
|
|
76
93
|
it 'raises ArgumentError' do
|
77
94
|
lambda do
|
78
95
|
dbref
|
79
|
-
end.should raise_error(
|
96
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
80
97
|
end
|
81
98
|
end
|
82
99
|
end
|
data/spec/bson/dbref_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
#
|
2
|
+
# rubocop:todo all
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
require 'json'
|
@@ -79,10 +79,10 @@ describe BSON::DBRef do
|
|
79
79
|
described_class.new({:$ref => 'users', :$id => object_id}, object_id)
|
80
80
|
end
|
81
81
|
|
82
|
-
it 'raises
|
82
|
+
it 'raises InvalidDBRefArgument' do
|
83
83
|
lambda do
|
84
84
|
dbref
|
85
|
-
end.should raise_error(
|
85
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -92,10 +92,10 @@ describe BSON::DBRef do
|
|
92
92
|
described_class.new({:$ref => 'users', :$id => object_id}, object_id, 'db')
|
93
93
|
end
|
94
94
|
|
95
|
-
it 'raises
|
95
|
+
it 'raises InvalidDBRefArgument' do
|
96
96
|
lambda do
|
97
97
|
dbref
|
98
|
-
end.should raise_error(
|
98
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -118,7 +118,7 @@ describe BSON::DBRef do
|
|
118
118
|
it 'raises an error' do
|
119
119
|
expect do
|
120
120
|
dbref
|
121
|
-
end.to raise_error(
|
121
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /DBRef must have \$ref/)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -130,7 +130,7 @@ describe BSON::DBRef do
|
|
130
130
|
it 'raises an error' do
|
131
131
|
expect do
|
132
132
|
dbref
|
133
|
-
end.to raise_error(
|
133
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /DBRef must have \$id/)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -142,7 +142,7 @@ describe BSON::DBRef do
|
|
142
142
|
it 'raises an error' do
|
143
143
|
expect do
|
144
144
|
dbref
|
145
|
-
end.to raise_error(
|
145
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /The value for key \$ref must be a string/)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -154,7 +154,7 @@ describe BSON::DBRef do
|
|
154
154
|
it 'raises an error' do
|
155
155
|
expect do
|
156
156
|
dbref
|
157
|
-
end.to raise_error(
|
157
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /The value for key \$db must be a string/)
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2016-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -28,10 +29,10 @@ describe BSON::Decimal128 do
|
|
28
29
|
|
29
30
|
context 'when the argument is neither a BigDecimal or String' do
|
30
31
|
|
31
|
-
it 'raises an
|
32
|
+
it 'raises an InvalidDecimal128Argument error' do
|
32
33
|
expect {
|
33
34
|
described_class.new(:invalid)
|
34
|
-
}.to raise_exception(
|
35
|
+
}.to raise_exception(BSON::Error::InvalidDecimal128Argument, /A Decimal128 can only be created from a String or BigDecimal./ )
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -46,7 +47,7 @@ describe BSON::Decimal128 do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
let(:from_bson) do
|
49
|
-
described_class.from_bson(buffer)
|
50
|
+
described_class.from_bson(buffer, mode: :bson)
|
50
51
|
end
|
51
52
|
|
52
53
|
let(:expected_bson) do
|
@@ -314,7 +315,7 @@ describe BSON::Decimal128 do
|
|
314
315
|
it 'raises InvalidRange' do
|
315
316
|
lambda do
|
316
317
|
described_class.new('1e10000')
|
317
|
-
end.should raise_error(BSON::
|
318
|
+
end.should raise_error(BSON::Error::InvalidDecimal128Range, /Value out of range/)
|
318
319
|
end
|
319
320
|
end
|
320
321
|
|
@@ -322,7 +323,7 @@ describe BSON::Decimal128 do
|
|
322
323
|
it 'raises UnrepresentablePrecision' do
|
323
324
|
lambda do
|
324
325
|
described_class.new('1.000000000000000000000000000000000000000000000000001')
|
325
|
-
end.should raise_error(BSON::
|
326
|
+
end.should raise_error(BSON::Error::UnrepresentablePrecision, /The value contains too much precision/)
|
326
327
|
end
|
327
328
|
end
|
328
329
|
end
|
@@ -344,7 +345,7 @@ describe BSON::Decimal128 do
|
|
344
345
|
end
|
345
346
|
|
346
347
|
let(:decimal128) do
|
347
|
-
BSON::Document.from_bson(buffer)['d']
|
348
|
+
BSON::Document.from_bson(buffer, mode: :bson)['d']
|
348
349
|
end
|
349
350
|
|
350
351
|
let(:object_from_string) do
|
@@ -1270,13 +1271,39 @@ describe BSON::Decimal128 do
|
|
1270
1271
|
described_class.new(BigDecimal('1.23'))
|
1271
1272
|
end
|
1272
1273
|
|
1273
|
-
it "returns the decimal128
|
1274
|
-
expect(object.as_json).to eq(
|
1274
|
+
it "returns the decimal128 as a string" do
|
1275
|
+
expect(object.as_json).to eq('1.23')
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
%w[NaN -NaN SNaN -SNaN Infinity -Infinity].each do |value|
|
1279
|
+
context "when special value #{value}" do
|
1280
|
+
|
1281
|
+
let(:object) do
|
1282
|
+
described_class.new(value)
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
it "returns nil to be consistent with ActiveSupport" do
|
1286
|
+
expect(object.as_json).to eq(nil)
|
1287
|
+
end
|
1288
|
+
end
|
1275
1289
|
end
|
1276
1290
|
|
1277
1291
|
it_behaves_like "a JSON serializable object"
|
1278
1292
|
end
|
1279
1293
|
|
1294
|
+
describe "#as_extended_json" do
|
1295
|
+
|
1296
|
+
let(:object) do
|
1297
|
+
described_class.new(BigDecimal('1.23'))
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
it "returns the decimal128 with $numberDecimal key" do
|
1301
|
+
expect(object.as_extended_json).to eq({ "$numberDecimal" => '1.23' })
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
it_behaves_like "an Extended JSON serializable object"
|
1305
|
+
end
|
1306
|
+
|
1280
1307
|
describe "::BSON_TYPE" do
|
1281
1308
|
|
1282
1309
|
it "returns 0x13" do
|
@@ -1361,7 +1388,7 @@ describe BSON::Decimal128 do
|
|
1361
1388
|
end
|
1362
1389
|
end
|
1363
1390
|
|
1364
|
-
describe "#
|
1391
|
+
describe "#to_d" do
|
1365
1392
|
|
1366
1393
|
shared_examples_for 'a decimal128 convertible to a Ruby BigDecimal' do
|
1367
1394
|
|
@@ -1370,6 +1397,10 @@ describe BSON::Decimal128 do
|
|
1370
1397
|
end
|
1371
1398
|
|
1372
1399
|
it 'properly converts the Decimal128 to a BigDecimal' do
|
1400
|
+
expect(decimal128.to_d).to eq(expected_big_decimal)
|
1401
|
+
end
|
1402
|
+
|
1403
|
+
it 'permits the alias #to_big_decimal' do
|
1373
1404
|
expect(decimal128.to_big_decimal).to eq(expected_big_decimal)
|
1374
1405
|
end
|
1375
1406
|
end
|
@@ -1592,14 +1623,218 @@ describe BSON::Decimal128 do
|
|
1592
1623
|
end
|
1593
1624
|
end
|
1594
1625
|
|
1595
|
-
|
1626
|
+
%w(== ===).each do |eq_op|
|
1627
|
+
let(:lhs) { described_class.new('1.2e12') }
|
1628
|
+
|
1629
|
+
describe "##{eq_op}" do
|
1630
|
+
context 'when rhs is equal to lhs' do
|
1631
|
+
context 'when both are Decimal128 instances' do
|
1632
|
+
let(:rhs) { described_class.new('1.2e12') }
|
1633
|
+
|
1634
|
+
it 'is true' do
|
1635
|
+
(lhs == rhs).should be true
|
1636
|
+
end
|
1637
|
+
end
|
1596
1638
|
|
1597
|
-
|
1598
|
-
|
1639
|
+
context 'when rhs is of a different type' do
|
1640
|
+
[
|
1641
|
+
1200000000000,
|
1642
|
+
1200000000000.0,
|
1643
|
+
BigDecimal('1.2e12'),
|
1644
|
+
].each do |rhs|
|
1645
|
+
context "when rhs is #{rhs.class}" do
|
1646
|
+
it 'is true' do
|
1647
|
+
pending 'RUBY-2952'
|
1648
|
+
|
1649
|
+
(lhs == rhs).should be true
|
1650
|
+
end
|
1651
|
+
end
|
1652
|
+
end
|
1653
|
+
end
|
1654
|
+
end
|
1655
|
+
|
1656
|
+
context 'when rhs is not equal to lhs' do
|
1657
|
+
context 'when both are Decimal128 instances' do
|
1658
|
+
let(:rhs) { described_class.new('1.21e12') }
|
1659
|
+
|
1660
|
+
it 'is false' do
|
1661
|
+
(lhs == rhs).should be false
|
1662
|
+
end
|
1663
|
+
end
|
1664
|
+
|
1665
|
+
context 'when rhs is of a different type' do
|
1666
|
+
|
1667
|
+
[
|
1668
|
+
1200000000001,
|
1669
|
+
1200000000001.0,
|
1670
|
+
BigDecimal('1.21e12'),
|
1671
|
+
].each do |rhs|
|
1672
|
+
context "when rhs is #{rhs.class}" do
|
1673
|
+
it 'is false' do
|
1674
|
+
(lhs == rhs).should be false
|
1675
|
+
end
|
1676
|
+
end
|
1677
|
+
end
|
1678
|
+
end
|
1679
|
+
end
|
1680
|
+
end
|
1681
|
+
end
|
1682
|
+
|
1683
|
+
describe "#<=>" do
|
1684
|
+
|
1685
|
+
let(:lhs) { described_class.new('1.2e12') }
|
1686
|
+
|
1687
|
+
context 'when lhs is less than rhs' do
|
1688
|
+
context 'when both are Decimal128 instances' do
|
1689
|
+
let(:rhs) { described_class.new('1.21e12') }
|
1690
|
+
|
1691
|
+
it 'is -1' do
|
1692
|
+
(lhs <=> rhs).should be -1
|
1693
|
+
end
|
1694
|
+
end
|
1695
|
+
|
1696
|
+
context 'when rhs is of a different type' do
|
1697
|
+
[
|
1698
|
+
1200000000001,
|
1699
|
+
1200000000001.0,
|
1700
|
+
BigDecimal('1.21e12'),
|
1701
|
+
].each do |rhs|
|
1702
|
+
context "when rhs is #{rhs.class}" do
|
1703
|
+
it 'is -1' do
|
1704
|
+
(lhs <=> rhs).should be -1
|
1705
|
+
end
|
1706
|
+
end
|
1707
|
+
end
|
1708
|
+
end
|
1599
1709
|
end
|
1600
1710
|
|
1601
|
-
|
1602
|
-
|
1711
|
+
context 'when rhs is equal to lhs' do
|
1712
|
+
context 'when both are Decimal128 instances' do
|
1713
|
+
let(:rhs) { described_class.new('1.2e12') }
|
1714
|
+
|
1715
|
+
it 'is 0' do
|
1716
|
+
(lhs <=> rhs).should be 0
|
1717
|
+
end
|
1718
|
+
end
|
1719
|
+
|
1720
|
+
context 'when rhs is of a different type' do
|
1721
|
+
|
1722
|
+
[
|
1723
|
+
1200000000000,
|
1724
|
+
1200000000000.0,
|
1725
|
+
BigDecimal('1.2e12'),
|
1726
|
+
].each do |rhs|
|
1727
|
+
context "when rhs is #{rhs.class}" do
|
1728
|
+
it 'is 0' do
|
1729
|
+
(lhs <=> rhs).should be 0
|
1730
|
+
end
|
1731
|
+
end
|
1732
|
+
end
|
1733
|
+
end
|
1734
|
+
end
|
1735
|
+
|
1736
|
+
context 'when rhs is greater than lhs' do
|
1737
|
+
context 'when both are Decimal128 instances' do
|
1738
|
+
let(:rhs) { described_class.new('1.1e12') }
|
1739
|
+
|
1740
|
+
it 'is 1' do
|
1741
|
+
(lhs <=> rhs).should be 1
|
1742
|
+
end
|
1743
|
+
end
|
1744
|
+
|
1745
|
+
context 'when rhs is of a different type' do
|
1746
|
+
|
1747
|
+
[
|
1748
|
+
1100000000000,
|
1749
|
+
1100000000000.0,
|
1750
|
+
BigDecimal('1.1e12'),
|
1751
|
+
].each do |rhs|
|
1752
|
+
context "when rhs is #{rhs.class}" do
|
1753
|
+
it 'is 1' do
|
1754
|
+
(lhs <=> rhs).should be 1
|
1755
|
+
end
|
1756
|
+
end
|
1757
|
+
end
|
1758
|
+
end
|
1759
|
+
end
|
1760
|
+
end
|
1761
|
+
|
1762
|
+
describe "#<" do
|
1763
|
+
|
1764
|
+
let(:lhs) { described_class.new('1.2e12') }
|
1765
|
+
|
1766
|
+
context 'when lhs is less than rhs' do
|
1767
|
+
context 'when both are Decimal128 instances' do
|
1768
|
+
let(:rhs) { described_class.new('1.21e12') }
|
1769
|
+
|
1770
|
+
it 'is true' do
|
1771
|
+
(lhs < rhs).should be true
|
1772
|
+
end
|
1773
|
+
end
|
1774
|
+
|
1775
|
+
context 'when rhs is of a different type' do
|
1776
|
+
[
|
1777
|
+
1200000000001,
|
1778
|
+
1200000000001.0,
|
1779
|
+
BigDecimal('1.21e12'),
|
1780
|
+
].each do |rhs|
|
1781
|
+
context "when rhs is #{rhs.class}" do
|
1782
|
+
it 'is true' do
|
1783
|
+
(lhs < rhs).should be true
|
1784
|
+
end
|
1785
|
+
end
|
1786
|
+
end
|
1787
|
+
end
|
1788
|
+
end
|
1789
|
+
|
1790
|
+
context 'when rhs is equal to lhs' do
|
1791
|
+
context 'when both are Decimal128 instances' do
|
1792
|
+
let(:rhs) { described_class.new('1.2e12') }
|
1793
|
+
|
1794
|
+
it 'is false' do
|
1795
|
+
(lhs < rhs).should be false
|
1796
|
+
end
|
1797
|
+
end
|
1798
|
+
|
1799
|
+
context 'when rhs is of a different type' do
|
1800
|
+
|
1801
|
+
[
|
1802
|
+
1200000000000,
|
1803
|
+
1200000000000.0,
|
1804
|
+
BigDecimal('1.2e12'),
|
1805
|
+
].each do |rhs|
|
1806
|
+
context "when rhs is #{rhs.class}" do
|
1807
|
+
it 'is false' do
|
1808
|
+
(lhs < rhs).should be false
|
1809
|
+
end
|
1810
|
+
end
|
1811
|
+
end
|
1812
|
+
end
|
1813
|
+
end
|
1814
|
+
|
1815
|
+
context 'when rhs is greater than lhs' do
|
1816
|
+
context 'when both are Decimal128 instances' do
|
1817
|
+
let(:rhs) { described_class.new('1.1e12') }
|
1818
|
+
|
1819
|
+
it 'is false' do
|
1820
|
+
(lhs < rhs).should be false
|
1821
|
+
end
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
context 'when rhs is of a different type' do
|
1825
|
+
|
1826
|
+
[
|
1827
|
+
1100000000000,
|
1828
|
+
1100000000000.0,
|
1829
|
+
BigDecimal('1.1e12'),
|
1830
|
+
].each do |rhs|
|
1831
|
+
context "when rhs is #{rhs.class}" do
|
1832
|
+
it 'is false' do
|
1833
|
+
(lhs < rhs).should be false
|
1834
|
+
end
|
1835
|
+
end
|
1836
|
+
end
|
1837
|
+
end
|
1603
1838
|
end
|
1604
1839
|
end
|
1605
1840
|
end
|
data/spec/bson/document_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -25,4 +26,11 @@ describe FalseClass do
|
|
25
26
|
it_behaves_like "a bson element"
|
26
27
|
it_behaves_like "a serializable bson element"
|
27
28
|
end
|
29
|
+
|
30
|
+
describe '#as_extended_json' do
|
31
|
+
let(:object) { false }
|
32
|
+
|
33
|
+
it_behaves_like '#as_extended_json returns self'
|
34
|
+
it_behaves_like 'an Extended JSON serializable object'
|
35
|
+
end
|
28
36
|
end
|
data/spec/bson/float_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -34,15 +35,17 @@ describe Float do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
describe '#as_extended_json' do
|
38
|
+
let(:object) { 42.0 }
|
39
|
+
|
37
40
|
context 'canonical mode' do
|
38
41
|
it 'returns $numberDouble' do
|
39
|
-
|
42
|
+
object.as_extended_json.should == {'$numberDouble' => '42.0'}
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
context 'relaxed mode' do
|
44
47
|
let(:serialized) do
|
45
|
-
|
48
|
+
object.as_extended_json(mode: :relaxed)
|
46
49
|
end
|
47
50
|
|
48
51
|
it 'returns float' do
|
@@ -53,7 +56,7 @@ describe Float do
|
|
53
56
|
|
54
57
|
context 'legacy mode' do
|
55
58
|
let(:serialized) do
|
56
|
-
|
59
|
+
object.as_extended_json(mode: :legacy)
|
57
60
|
end
|
58
61
|
|
59
62
|
it 'returns float' do
|
@@ -61,5 +64,7 @@ describe Float do
|
|
61
64
|
serialized.should be_within(0.00001).of(42)
|
62
65
|
end
|
63
66
|
end
|
67
|
+
|
68
|
+
it_behaves_like "an Extended JSON serializable object"
|
64
69
|
end
|
65
70
|
end
|
data/spec/bson/hash_as_spec.rb
CHANGED