bson 4.15.0-java → 5.0.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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +94 -10
  3. data/Rakefile +68 -39
  4. data/lib/bson/active_support.rb +1 -0
  5. data/lib/bson/array.rb +57 -31
  6. data/lib/bson/big_decimal.rb +16 -6
  7. data/lib/bson/binary.rb +255 -128
  8. data/lib/bson/boolean.rb +1 -0
  9. data/lib/bson/code.rb +9 -11
  10. data/lib/bson/code_with_scope.rb +8 -10
  11. data/lib/bson/config.rb +1 -27
  12. data/lib/bson/date.rb +2 -1
  13. data/lib/bson/date_time.rb +2 -1
  14. data/lib/bson/db_pointer.rb +11 -12
  15. data/lib/bson/dbref.rb +11 -9
  16. data/lib/bson/decimal128/builder.rb +10 -9
  17. data/lib/bson/decimal128.rb +24 -110
  18. data/lib/bson/document.rb +1 -0
  19. data/lib/bson/environment.rb +1 -0
  20. data/lib/bson/error/bson_decode_error.rb +11 -0
  21. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  22. data/lib/bson/error/illegal_key.rb +23 -0
  23. data/lib/bson/error/invalid_binary_type.rb +37 -0
  24. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  25. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  26. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  27. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  28. data/lib/bson/error/invalid_key.rb +24 -0
  29. data/lib/bson/error/invalid_object_id.rb +11 -0
  30. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  31. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  32. data/lib/bson/error/unserializable_class.rb +13 -0
  33. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  34. data/lib/bson/error/unsupported_type.rb +11 -0
  35. data/lib/bson/error.rb +16 -28
  36. data/lib/bson/ext_json.rb +1 -0
  37. data/lib/bson/false_class.rb +2 -1
  38. data/lib/bson/float.rb +2 -1
  39. data/lib/bson/hash.rb +127 -72
  40. data/lib/bson/int32.rb +16 -4
  41. data/lib/bson/int64.rb +16 -4
  42. data/lib/bson/integer.rb +3 -4
  43. data/lib/bson/json.rb +1 -0
  44. data/lib/bson/max_key.rb +7 -9
  45. data/lib/bson/min_key.rb +7 -9
  46. data/lib/bson/nil_class.rb +1 -0
  47. data/lib/bson/object.rb +5 -25
  48. data/lib/bson/object_id.rb +83 -119
  49. data/lib/bson/open_struct.rb +3 -2
  50. data/lib/bson/regexp.rb +35 -64
  51. data/lib/bson/registry.rb +2 -6
  52. data/lib/bson/specialized.rb +2 -1
  53. data/lib/bson/string.rb +4 -27
  54. data/lib/bson/symbol.rb +22 -19
  55. data/lib/bson/time.rb +2 -1
  56. data/lib/bson/time_with_zone.rb +13 -1
  57. data/lib/bson/timestamp.rb +2 -1
  58. data/lib/bson/true_class.rb +2 -1
  59. data/lib/bson/undefined.rb +14 -0
  60. data/lib/bson/version.rb +3 -1
  61. data/lib/bson-ruby.jar +0 -0
  62. data/lib/bson.rb +3 -2
  63. data/spec/bson/array_spec.rb +19 -60
  64. data/spec/bson/big_decimal_spec.rb +16 -4
  65. data/spec/bson/binary_spec.rb +83 -74
  66. data/spec/bson/binary_uuid_spec.rb +1 -0
  67. data/spec/bson/boolean_spec.rb +1 -0
  68. data/spec/bson/byte_buffer_read_spec.rb +1 -0
  69. data/spec/bson/byte_buffer_spec.rb +1 -0
  70. data/spec/bson/byte_buffer_write_spec.rb +1 -0
  71. data/spec/bson/code_spec.rb +5 -3
  72. data/spec/bson/code_with_scope_spec.rb +5 -3
  73. data/spec/bson/config_spec.rb +1 -35
  74. data/spec/bson/date_spec.rb +1 -0
  75. data/spec/bson/date_time_spec.rb +1 -0
  76. data/spec/bson/dbref_legacy_spec.rb +20 -3
  77. data/spec/bson/dbref_spec.rb +9 -9
  78. data/spec/bson/decimal128_spec.rb +40 -20
  79. data/spec/bson/document_as_spec.rb +1 -0
  80. data/spec/bson/document_spec.rb +1 -1
  81. data/spec/bson/ext_json_parse_spec.rb +1 -0
  82. data/spec/bson/false_class_spec.rb +8 -0
  83. data/spec/bson/float_spec.rb +8 -3
  84. data/spec/bson/hash_as_spec.rb +1 -0
  85. data/spec/bson/hash_spec.rb +87 -75
  86. data/spec/bson/int32_spec.rb +21 -6
  87. data/spec/bson/int64_spec.rb +21 -6
  88. data/spec/bson/integer_spec.rb +45 -13
  89. data/spec/bson/json_spec.rb +1 -0
  90. data/spec/bson/max_key_spec.rb +5 -3
  91. data/spec/bson/min_key_spec.rb +5 -3
  92. data/spec/bson/nil_class_spec.rb +1 -0
  93. data/spec/bson/object_id_spec.rb +57 -4
  94. data/spec/bson/object_spec.rb +2 -1
  95. data/spec/bson/open_struct_spec.rb +14 -71
  96. data/spec/bson/raw_spec.rb +9 -15
  97. data/spec/bson/regexp_spec.rb +4 -3
  98. data/spec/bson/registry_spec.rb +2 -1
  99. data/spec/bson/string_spec.rb +13 -38
  100. data/spec/bson/symbol_raw_spec.rb +25 -0
  101. data/spec/bson/symbol_spec.rb +15 -18
  102. data/spec/bson/time_spec.rb +1 -0
  103. data/spec/bson/time_with_zone_spec.rb +1 -0
  104. data/spec/bson/timestamp_spec.rb +1 -0
  105. data/spec/bson/true_class_spec.rb +8 -0
  106. data/spec/bson/undefined_spec.rb +27 -0
  107. data/spec/bson_spec.rb +1 -0
  108. data/spec/runners/common_driver.rb +6 -5
  109. data/spec/runners/corpus.rb +6 -0
  110. data/spec/runners/corpus_legacy.rb +1 -0
  111. data/spec/spec_helper.rb +1 -0
  112. data/spec/spec_tests/common_driver_spec.rb +9 -4
  113. data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
  114. data/spec/spec_tests/corpus_spec.rb +13 -3
  115. data/spec/spec_tests/data/corpus/binary.json +5 -0
  116. data/spec/spec_tests/data/corpus/code.json +13 -13
  117. data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
  118. data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
  119. data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
  120. data/spec/spec_tests/data/corpus/document.json +20 -0
  121. data/spec/spec_tests/data/corpus/symbol.json +7 -7
  122. data/spec/spec_tests/data/corpus/top.json +18 -3
  123. data/spec/support/shared_examples.rb +28 -5
  124. data/spec/support/spec_config.rb +1 -0
  125. data/spec/support/utils.rb +49 -1
  126. metadata +112 -161
  127. checksums.yaml.gz.sig +0 -0
  128. data/spec/shared/LICENSE +0 -20
  129. data/spec/shared/bin/get-mongodb-download-url +0 -17
  130. data/spec/shared/bin/s3-copy +0 -45
  131. data/spec/shared/bin/s3-upload +0 -69
  132. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  133. data/spec/shared/lib/mrss/cluster_config.rb +0 -231
  134. data/spec/shared/lib/mrss/constraints.rb +0 -386
  135. data/spec/shared/lib/mrss/docker_runner.rb +0 -271
  136. data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
  137. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  138. data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
  139. data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
  140. data/spec/shared/lib/mrss/utils.rb +0 -15
  141. data/spec/shared/share/Dockerfile.erb +0 -338
  142. data/spec/shared/share/haproxy-1.conf +0 -16
  143. data/spec/shared/share/haproxy-2.conf +0 -17
  144. data/spec/shared/shlib/distro.sh +0 -74
  145. data/spec/shared/shlib/server.sh +0 -367
  146. data/spec/shared/shlib/set_env.sh +0 -131
  147. data.tar.gz.sig +0 -1
  148. metadata.gz.sig +0 -2
@@ -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");
@@ -106,28 +107,24 @@ describe Symbol do
106
107
 
107
108
  describe "#to_bson_key" do
108
109
 
109
- context "when validating keys" do
110
-
111
- let(:symbol) do
112
- :'$testing.testing'
113
- end
114
-
115
- it "raises an exception" do
116
- expect {
117
- symbol.to_bson_key(true)
118
- }.to raise_error(BSON::String::IllegalKey)
119
- end
110
+ let(:symbol) do
111
+ :'$testing.testing'
120
112
  end
121
113
 
122
- context "when not validating keys" do
114
+ it "returns the key" do
115
+ expect(symbol.to_bson_key).to eq(symbol)
116
+ end
117
+ end
123
118
 
124
- let(:symbol) do
125
- :'$testing.testing'
126
- end
119
+ describe '#as_extended_json' do
120
+ let(:object) do
121
+ :foobar
122
+ end
127
123
 
128
- it "allows invalid keys" do
129
- expect(symbol.to_bson_key).to eq(symbol)
130
- end
124
+ it 'returns the binary data plus type' do
125
+ expect(object.as_extended_json).to eq({ '$symbol' => 'foobar' })
131
126
  end
127
+
128
+ it_behaves_like 'an Extended JSON serializable object'
132
129
  end
133
130
  end
@@ -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");
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  # Copyright (C) 2018-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -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");
@@ -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 TrueClass 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) { true }
32
+
33
+ it_behaves_like '#as_extended_json returns self'
34
+ it_behaves_like 'an Extended JSON serializable object'
35
+ end
28
36
  end
@@ -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");
@@ -26,4 +27,30 @@ describe BSON::Undefined do
26
27
  it_behaves_like "a serializable bson element"
27
28
  it_behaves_like "a deserializable bson element"
28
29
  end
30
+
31
+ describe "#as_json" do
32
+
33
+ let(:object) do
34
+ described_class.new
35
+ end
36
+
37
+ it "returns nil" do
38
+ expect(object.as_json).to eq(nil)
39
+ end
40
+
41
+ it_behaves_like 'a JSON serializable object'
42
+ end
43
+
44
+ describe "#as_extended_json" do
45
+
46
+ let(:object) do
47
+ described_class.new
48
+ end
49
+
50
+ it "returns the binary data plus type" do
51
+ expect(object.as_extended_json).to eq({ "$undefined" => true })
52
+ end
53
+
54
+ it_behaves_like 'an Extended JSON serializable object'
55
+ end
29
56
  end
data/spec/bson_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");
@@ -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");
@@ -184,13 +185,13 @@ module BSON
184
185
  # The object as json, in a document with the test key.
185
186
  #
186
187
  # @example Get a document with the object at the test key.
187
- # test.document_as_json
188
+ # test.document_as_extended_json
188
189
  #
189
- # @return [ BSON::Document ] The json document.
190
+ # @return [ Hash ] The extended_json representation of document.
190
191
  #
191
192
  # @since 4.2.0
192
- def document_as_json
193
- { @test_key => object.as_json }
193
+ def document_as_extended_json
194
+ { @test_key => object.as_extended_json }
194
195
  end
195
196
 
196
197
  # Use the string in the extended json to instantiate the bson object.
@@ -340,7 +341,7 @@ module BSON
340
341
  def decoded_document
341
342
  @document ||= (data = [ @subject ].pack('H*')
342
343
  buffer = BSON::ByteBuffer.new(data)
343
- BSON::Document.from_bson(buffer))
344
+ BSON::Document.from_bson(buffer, mode: :bson))
344
345
  end
345
346
  end
346
347
  end
@@ -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");
@@ -57,6 +58,10 @@ module BSON
57
58
  @spec['test_key']
58
59
  end
59
60
 
61
+ def bson_type
62
+ @bson_type ||= @spec['bson_type'].to_i(16).chr
63
+ end
64
+
60
65
  def valid_tests
61
66
  @valid_tests ||=
62
67
  @spec['valid']&.map do |test_spec|
@@ -179,6 +184,7 @@ module BSON
179
184
  @string = test_params['string']
180
185
  end
181
186
 
187
+ attr_reader :spec
182
188
  attr_reader :description, :string
183
189
  end
184
190
  end
@@ -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");
data/spec/spec_helper.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");
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
  require 'runners/common_driver'
3
4
 
@@ -25,8 +26,12 @@ describe 'Driver common bson tests' do
25
26
  expect(test.from_json_string).to eq(test.object)
26
27
  end
27
28
 
29
+ it 'serializes to a string', if: test.to_ext_json? do
30
+ expect(test.document_as_extended_json).to eq(test.ext_json)
31
+ end
32
+
28
33
  it 'creates the correct extended json document from the decoded object', if: test.to_ext_json? do
29
- expect(test.document_as_json).to eq(test.ext_json)
34
+ expect(test.document_as_extended_json).to eq(test.ext_json)
30
35
  end
31
36
 
32
37
  it 'parses the string value to the same value as the decoded document', if: test.from_string? do
@@ -63,9 +68,9 @@ describe 'Driver common bson tests' do
63
68
 
64
69
  let(:valid_errors) do
65
70
  [
66
- BSON::Decimal128::InvalidString,
67
- BSON::Decimal128::InvalidRange,
68
- BSON::Decimal128::UnrepresentablePrecision,
71
+ BSON::Error::InvalidDecimal128String,
72
+ BSON::Error::InvalidDecimal128Range,
73
+ BSON::Error::UnrepresentablePrecision,
69
74
  ]
70
75
  end
71
76
 
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
  require 'runners/corpus_legacy'
3
4
 
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
  require 'runners/corpus'
3
4
 
@@ -105,8 +106,17 @@ describe 'BSON Corpus spec tests' do
105
106
 
106
107
  context("parse error: #{test.description}") do
107
108
 
108
- let(:parsed_extjson) do
109
- BSON::ExtJSON.parse(test.string, mode: :bson)
109
+ # As per:
110
+ # https://github.com/mongodb/specifications/blob/e7ee829329400786e01279b4f37d4e440d1e9cfa/source/bson-corpus/bson-corpus.rst#decimal128-type-0x13
111
+ #
112
+ # Values under test must be parsed in a type-specific manner.
113
+ let(:parsed_value) do
114
+ case spec.bson_type
115
+ when BSON::Decimal128::BSON_TYPE
116
+ BSON::Decimal128.new(test.string)
117
+ else
118
+ BSON::ExtJSON.parse(test.string, mode: :bson)
119
+ end
110
120
  end
111
121
 
112
122
  # Until bson-ruby gets an exception hierarchy, we can only rescue
@@ -114,7 +124,7 @@ describe 'BSON Corpus spec tests' do
114
124
  # https://jira.mongodb.org/browse/RUBY-1806
115
125
  it 'raises an exception' do
116
126
  expect do
117
- parsed_extjson
127
+ parsed_value
118
128
  end.to raise_error(Exception)
119
129
  end
120
130
  end
@@ -55,6 +55,11 @@
55
55
  "canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
56
56
  "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
57
57
  },
58
+ {
59
+ "description": "subtype 0x08",
60
+ "canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
61
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
62
+ },
58
63
  {
59
64
  "description": "subtype 0x80",
60
65
  "canonical_bson": "0F0000000578000200000080FFFF00",
@@ -20,48 +20,48 @@
20
20
  },
21
21
  {
22
22
  "description": "two-byte UTF-8 (\u00e9)",
23
- "canonical_bson": "190000000261000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
24
- "canonical_extjson": "{\"a\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}"
23
+ "canonical_bson": "190000000D61000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
24
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}}"
25
25
  },
26
26
  {
27
27
  "description": "three-byte UTF-8 (\u2606)",
28
- "canonical_bson": "190000000261000D000000E29886E29886E29886E298860000",
29
- "canonical_extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}"
28
+ "canonical_bson": "190000000D61000D000000E29886E29886E29886E298860000",
29
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u2606\\u2606\\u2606\\u2606\"}}"
30
30
  },
31
31
  {
32
32
  "description": "Embedded nulls",
33
- "canonical_bson": "190000000261000D0000006162006261620062616261620000",
34
- "canonical_extjson": "{\"a\" : \"ab\\u0000bab\\u0000babab\"}"
33
+ "canonical_bson": "190000000D61000D0000006162006261620062616261620000",
34
+ "canonical_extjson": "{\"a\" : {\"$code\" : \"ab\\u0000bab\\u0000babab\"}}"
35
35
  }
36
36
  ],
37
37
  "decodeErrors": [
38
38
  {
39
39
  "description": "bad code string length: 0 (but no 0x00 either)",
40
- "bson": "0C0000000261000000000000"
40
+ "bson": "0C0000000D61000000000000"
41
41
  },
42
42
  {
43
43
  "description": "bad code string length: -1",
44
- "bson": "0C000000026100FFFFFFFF00"
44
+ "bson": "0C0000000D6100FFFFFFFF00"
45
45
  },
46
46
  {
47
47
  "description": "bad code string length: eats terminator",
48
- "bson": "10000000026100050000006200620000"
48
+ "bson": "100000000D6100050000006200620000"
49
49
  },
50
50
  {
51
51
  "description": "bad code string length: longer than rest of document",
52
- "bson": "120000000200FFFFFF00666F6F6261720000"
52
+ "bson": "120000000D00FFFFFF00666F6F6261720000"
53
53
  },
54
54
  {
55
55
  "description": "code string is not null-terminated",
56
- "bson": "1000000002610004000000616263FF00"
56
+ "bson": "100000000D610004000000616263FF00"
57
57
  },
58
58
  {
59
59
  "description": "empty code string, but extra null",
60
- "bson": "0E00000002610001000000000000"
60
+ "bson": "0E0000000D610001000000000000"
61
61
  },
62
62
  {
63
63
  "description": "invalid UTF-8",
64
- "bson": "0E00000002610002000000E90000"
64
+ "bson": "0E0000000D610002000000E90000"
65
65
  }
66
66
  ]
67
67
  }
@@ -112,6 +112,54 @@
112
112
  {
113
113
  "description": "[basx563] Near-specials (Conversion_syntax)",
114
114
  "string": "NaNs"
115
+ },
116
+ {
117
+ "description": "[dqbas939] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
118
+ "string": "-7e10000"
119
+ },
120
+ {
121
+ "description": "[dqbsr534] negatives (Rounded & Inexact)",
122
+ "string": "-1.11111111111111111111111111111234650"
123
+ },
124
+ {
125
+ "description": "[dqbsr535] negatives (Rounded & Inexact)",
126
+ "string": "-1.11111111111111111111111111111234551"
127
+ },
128
+ {
129
+ "description": "[dqbsr533] negatives (Rounded & Inexact)",
130
+ "string": "-1.11111111111111111111111111111234550"
131
+ },
132
+ {
133
+ "description": "[dqbsr532] negatives (Rounded & Inexact)",
134
+ "string": "-1.11111111111111111111111111111234549"
135
+ },
136
+ {
137
+ "description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)",
138
+ "string": "1.11111111111111111111111111111234549"
139
+ },
140
+ {
141
+ "description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)",
142
+ "string": "1.11111111111111111111111111111234550"
143
+ },
144
+ {
145
+ "description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)",
146
+ "string": "1.11111111111111111111111111111234551"
147
+ },
148
+ {
149
+ "description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)",
150
+ "string": "1.11111111111111111111111111111234650"
151
+ },
152
+ {
153
+ "description": "[dqbas938] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
154
+ "string": "7e10000"
155
+ },
156
+ {
157
+ "description": "Inexact rounding#1",
158
+ "string": "100000000000000000000000000000000000000000000000000000000001"
159
+ },
160
+ {
161
+ "description": "Inexact rounding#2",
162
+ "string": "1E-6177"
115
163
  }
116
164
  ]
117
165
  }
@@ -75,6 +75,18 @@
75
75
  "description": "Empty string",
76
76
  "string": ""
77
77
  },
78
+ {
79
+ "description": "leading white space positive number",
80
+ "string": " 1"
81
+ },
82
+ {
83
+ "description": "leading white space negative number",
84
+ "string": " -1"
85
+ },
86
+ {
87
+ "description": "trailing white space",
88
+ "string": "1 "
89
+ },
78
90
  {
79
91
  "description": "Invalid",
80
92
  "string": "E"
@@ -267,6 +267,10 @@
267
267
  "description": "[basx570] Near-specials (Conversion_syntax)",
268
268
  "string": "9Inf"
269
269
  },
270
+ {
271
+ "description": "[basx512] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
272
+ "string": "12 "
273
+ },
270
274
  {
271
275
  "description": "[basx517] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
272
276
  "string": "12-"
@@ -17,6 +17,26 @@
17
17
  "description": "Single-character key subdoc",
18
18
  "canonical_bson": "160000000378000E0000000261000200000062000000",
19
19
  "canonical_extjson": "{\"x\" : {\"a\" : \"b\"}}"
20
+ },
21
+ {
22
+ "description": "Dollar-prefixed key in sub-document",
23
+ "canonical_bson": "170000000378000F000000022461000200000062000000",
24
+ "canonical_extjson": "{\"x\" : {\"$a\" : \"b\"}}"
25
+ },
26
+ {
27
+ "description": "Dollar as key in sub-document",
28
+ "canonical_bson": "160000000378000E0000000224000200000061000000",
29
+ "canonical_extjson": "{\"x\" : {\"$\" : \"a\"}}"
30
+ },
31
+ {
32
+ "description": "Dotted key in sub-document",
33
+ "canonical_bson": "180000000378001000000002612E62000200000063000000",
34
+ "canonical_extjson": "{\"x\" : {\"a.b\" : \"c\"}}"
35
+ },
36
+ {
37
+ "description": "Dot as key in sub-document",
38
+ "canonical_bson": "160000000378000E000000022E000200000061000000",
39
+ "canonical_extjson": "{\"x\" : {\".\" : \"a\"}}"
20
40
  }
21
41
  ],
22
42
  "decodeErrors": [
@@ -50,31 +50,31 @@
50
50
  "decodeErrors": [
51
51
  {
52
52
  "description": "bad symbol length: 0 (but no 0x00 either)",
53
- "bson": "0C0000000261000000000000"
53
+ "bson": "0C0000000E61000000000000"
54
54
  },
55
55
  {
56
56
  "description": "bad symbol length: -1",
57
- "bson": "0C000000026100FFFFFFFF00"
57
+ "bson": "0C0000000E6100FFFFFFFF00"
58
58
  },
59
59
  {
60
60
  "description": "bad symbol length: eats terminator",
61
- "bson": "10000000026100050000006200620000"
61
+ "bson": "100000000E6100050000006200620000"
62
62
  },
63
63
  {
64
64
  "description": "bad symbol length: longer than rest of document",
65
- "bson": "120000000200FFFFFF00666F6F6261720000"
65
+ "bson": "120000000E00FFFFFF00666F6F6261720000"
66
66
  },
67
67
  {
68
68
  "description": "symbol is not null-terminated",
69
- "bson": "1000000002610004000000616263FF00"
69
+ "bson": "100000000E610004000000616263FF00"
70
70
  },
71
71
  {
72
72
  "description": "empty symbol, but extra null",
73
- "bson": "0E00000002610001000000000000"
73
+ "bson": "0E0000000E610001000000000000"
74
74
  },
75
75
  {
76
76
  "description": "invalid UTF-8",
77
- "bson": "0E00000002610002000000E90000"
77
+ "bson": "0E0000000E610002000000E90000"
78
78
  }
79
79
  ]
80
80
  }
@@ -3,9 +3,24 @@
3
3
  "bson_type": "0x00",
4
4
  "valid": [
5
5
  {
6
- "description": "Document with keys that start with $",
6
+ "description": "Dollar-prefixed key in top-level document",
7
7
  "canonical_bson": "0F00000010246B6579002A00000000",
8
8
  "canonical_extjson": "{\"$key\": {\"$numberInt\": \"42\"}}"
9
+ },
10
+ {
11
+ "description": "Dollar as key in top-level document",
12
+ "canonical_bson": "0E00000002240002000000610000",
13
+ "canonical_extjson": "{\"$\": \"a\"}"
14
+ },
15
+ {
16
+ "description": "Dotted key in top-level document",
17
+ "canonical_bson": "1000000002612E620002000000630000",
18
+ "canonical_extjson": "{\"a.b\": \"c\"}"
19
+ },
20
+ {
21
+ "description": "Dot as key in top-level document",
22
+ "canonical_bson": "0E000000022E0002000000610000",
23
+ "canonical_extjson": "{\".\": \"a\"}"
9
24
  }
10
25
  ],
11
26
  "decodeErrors": [
@@ -77,11 +92,11 @@
77
92
  },
78
93
  {
79
94
  "description": "Bad $regularExpression (pattern is number, not string)",
80
- "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"$options\" : \"\"}}}"
95
+ "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"options\" : \"\"}}}"
81
96
  },
82
97
  {
83
98
  "description": "Bad $regularExpression (options are number, not string)",
84
- "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"$options\" : 0}}}"
99
+ "string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"options\" : 0}}}"
85
100
  },
86
101
  {
87
102
  "description" : "Bad $regularExpression (missing pattern field)",
@@ -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");
@@ -63,6 +64,28 @@ shared_examples_for "a JSON serializable object" do
63
64
  end
64
65
  end
65
66
 
67
+ shared_examples_for "an Extended JSON serializable object" do
68
+
69
+ it "serializes the Extended JSON from #as_extended_json" do
70
+ expect(object.to_extended_json).to eq(object.as_extended_json.to_json)
71
+ end
72
+ end
73
+
74
+ shared_examples_for '#as_extended_json returns self' do
75
+
76
+ it 'returns self' do
77
+ expect(object.as_extended_json).to eq(object)
78
+ end
79
+ end
80
+
81
+ shared_examples_for '#as_json calls #as_extended_json' do
82
+
83
+ it 'calls #as_extended_json' do
84
+ expect(object).to receive(:as_extended_json).with(no_args)
85
+ object.as_json
86
+ end
87
+ end
88
+
66
89
  shared_examples_for "immutable when frozen" do |block|
67
90
 
68
91
  context "when the document is frozen" do
@@ -122,7 +145,7 @@ shared_examples_for "a validated BSON key" do
122
145
  end
123
146
  end
124
147
 
125
- context "when the string is invalid" do
148
+ context "when the string has dots/dollars" do
126
149
 
127
150
  context "when the string starts with $" do
128
151
 
@@ -130,10 +153,10 @@ shared_examples_for "a validated BSON key" do
130
153
  "$testing"
131
154
  end
132
155
 
133
- it "raises an exception" do
156
+ it "does not raise an exception" do
134
157
  expect {
135
158
  validated
136
- }.to raise_error(BSON::String::IllegalKey)
159
+ }.to_not raise_error
137
160
  end
138
161
  end
139
162
 
@@ -143,10 +166,10 @@ shared_examples_for "a validated BSON key" do
143
166
  "testing.testing"
144
167
  end
145
168
 
146
- it "raises an exception" do
169
+ it "does not raise an exception" do
147
170
  expect {
148
171
  validated
149
- }.to raise_error(BSON::String::IllegalKey)
172
+ }.to_not raise_error
150
173
  end
151
174
  end
152
175
  end
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'singleton'
2
3
 
3
4
  class SpecConfig