bson 4.2.2 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +25 -7
  5. data/Rakefile +16 -9
  6. data/ext/bson/{native-endian.h → bson-endian.h} +5 -99
  7. data/ext/bson/bson-native.h +125 -0
  8. data/ext/bson/bytebuf.c +133 -0
  9. data/ext/bson/endian.c +117 -0
  10. data/ext/bson/init.c +355 -0
  11. data/ext/bson/libbson-utf8.c +230 -0
  12. data/ext/bson/read.c +411 -0
  13. data/ext/bson/util.c +95 -0
  14. data/ext/bson/write.c +680 -0
  15. data/lib/bson.rb +6 -3
  16. data/lib/bson/active_support.rb +17 -0
  17. data/lib/bson/array.rb +57 -17
  18. data/lib/bson/binary.rb +185 -13
  19. data/lib/bson/boolean.rb +12 -3
  20. data/lib/bson/code.rb +16 -2
  21. data/lib/bson/code_with_scope.rb +32 -5
  22. data/lib/bson/config.rb +1 -1
  23. data/lib/bson/date.rb +12 -2
  24. data/lib/bson/date_time.rb +2 -2
  25. data/lib/bson/db_pointer.rb +110 -0
  26. data/lib/bson/decimal128.rb +17 -3
  27. data/lib/bson/decimal128/builder.rb +1 -1
  28. data/lib/bson/document.rb +152 -5
  29. data/lib/bson/environment.rb +2 -1
  30. data/lib/bson/error.rb +27 -0
  31. data/lib/bson/ext_json.rb +383 -0
  32. data/lib/bson/false_class.rb +1 -1
  33. data/lib/bson/float.rb +48 -2
  34. data/lib/bson/hash.rb +68 -17
  35. data/lib/bson/int32.rb +52 -13
  36. data/lib/bson/int64.rb +59 -15
  37. data/lib/bson/integer.rb +36 -2
  38. data/lib/bson/json.rb +1 -1
  39. data/lib/bson/max_key.rb +13 -1
  40. data/lib/bson/min_key.rb +13 -1
  41. data/lib/bson/nil_class.rb +4 -2
  42. data/lib/bson/object.rb +28 -1
  43. data/lib/bson/object_id.rb +16 -2
  44. data/lib/bson/open_struct.rb +1 -1
  45. data/lib/bson/regexp.rb +27 -4
  46. data/lib/bson/registry.rb +3 -3
  47. data/lib/bson/specialized.rb +4 -2
  48. data/lib/bson/string.rb +5 -3
  49. data/lib/bson/symbol.rb +99 -7
  50. data/lib/bson/time.rb +63 -4
  51. data/lib/bson/time_with_zone.rb +54 -0
  52. data/lib/bson/timestamp.rb +44 -6
  53. data/lib/bson/true_class.rb +1 -1
  54. data/lib/bson/undefined.rb +12 -1
  55. data/lib/bson/version.rb +2 -2
  56. data/spec/bson/array_spec.rb +18 -1
  57. data/spec/bson/binary_spec.rb +100 -3
  58. data/spec/bson/binary_uuid_spec.rb +189 -0
  59. data/spec/bson/boolean_spec.rb +1 -1
  60. data/spec/bson/byte_buffer_read_spec.rb +197 -0
  61. data/spec/bson/byte_buffer_spec.rb +121 -381
  62. data/spec/bson/byte_buffer_write_spec.rb +854 -0
  63. data/spec/bson/code_spec.rb +1 -1
  64. data/spec/bson/code_with_scope_spec.rb +1 -1
  65. data/spec/bson/date_spec.rb +1 -1
  66. data/spec/bson/date_time_spec.rb +54 -1
  67. data/spec/bson/decimal128_spec.rb +35 -35
  68. data/spec/bson/document_as_spec.rb +46 -0
  69. data/spec/bson/document_spec.rb +197 -30
  70. data/spec/bson/ext_json_parse_spec.rb +308 -0
  71. data/spec/bson/false_class_spec.rb +1 -1
  72. data/spec/bson/float_spec.rb +37 -1
  73. data/spec/bson/hash_as_spec.rb +57 -0
  74. data/spec/bson/hash_spec.rb +209 -1
  75. data/spec/bson/int32_spec.rb +180 -6
  76. data/spec/bson/int64_spec.rb +199 -6
  77. data/spec/bson/integer_spec.rb +29 -3
  78. data/spec/bson/json_spec.rb +1 -1
  79. data/spec/bson/max_key_spec.rb +1 -1
  80. data/spec/bson/min_key_spec.rb +1 -1
  81. data/spec/bson/nil_class_spec.rb +1 -1
  82. data/spec/bson/object_id_spec.rb +1 -1
  83. data/spec/bson/object_spec.rb +1 -1
  84. data/spec/bson/open_struct_spec.rb +1 -1
  85. data/spec/bson/raw_spec.rb +34 -2
  86. data/spec/bson/regexp_spec.rb +1 -1
  87. data/spec/bson/registry_spec.rb +1 -1
  88. data/spec/bson/string_spec.rb +19 -1
  89. data/spec/bson/symbol_raw_spec.rb +45 -0
  90. data/spec/bson/symbol_spec.rb +63 -3
  91. data/spec/bson/time_spec.rb +205 -2
  92. data/spec/bson/time_with_zone_spec.rb +68 -0
  93. data/spec/bson/timestamp_spec.rb +56 -1
  94. data/spec/bson/true_class_spec.rb +1 -1
  95. data/spec/bson/undefined_spec.rb +1 -1
  96. data/spec/bson_spec.rb +1 -1
  97. data/spec/{support → runners}/common_driver.rb +1 -1
  98. data/spec/runners/corpus.rb +185 -0
  99. data/spec/{support/corpus.rb → runners/corpus_legacy.rb} +41 -59
  100. data/spec/spec_helper.rb +40 -3
  101. data/spec/{bson/driver_bson_spec.rb → spec_tests/common_driver_spec.rb} +1 -0
  102. data/spec/{bson/corpus_spec.rb → spec_tests/corpus_legacy_spec.rb} +10 -7
  103. data/spec/spec_tests/corpus_spec.rb +124 -0
  104. data/spec/spec_tests/data/corpus/README.md +15 -0
  105. data/spec/spec_tests/data/corpus/array.json +49 -0
  106. data/spec/spec_tests/data/corpus/binary.json +113 -0
  107. data/spec/spec_tests/data/corpus/boolean.json +27 -0
  108. data/spec/spec_tests/data/corpus/code.json +67 -0
  109. data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
  110. data/spec/spec_tests/data/corpus/datetime.json +42 -0
  111. data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
  112. data/spec/spec_tests/data/corpus/dbref.json +31 -0
  113. data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
  114. data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
  115. data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
  116. data/spec/spec_tests/data/corpus/decimal128-4.json +117 -0
  117. data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
  118. data/spec/spec_tests/data/corpus/decimal128-6.json +119 -0
  119. data/spec/spec_tests/data/corpus/decimal128-7.json +323 -0
  120. data/spec/spec_tests/data/corpus/document.json +36 -0
  121. data/spec/spec_tests/data/corpus/double.json +87 -0
  122. data/spec/spec_tests/data/corpus/int32.json +43 -0
  123. data/spec/spec_tests/data/corpus/int64.json +43 -0
  124. data/spec/spec_tests/data/corpus/maxkey.json +12 -0
  125. data/spec/spec_tests/data/corpus/minkey.json +12 -0
  126. data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
  127. data/spec/spec_tests/data/corpus/multi-type.json +11 -0
  128. data/spec/spec_tests/data/corpus/null.json +12 -0
  129. data/spec/spec_tests/data/corpus/oid.json +28 -0
  130. data/spec/spec_tests/data/corpus/regex.json +65 -0
  131. data/spec/spec_tests/data/corpus/string.json +72 -0
  132. data/spec/spec_tests/data/corpus/symbol.json +80 -0
  133. data/spec/spec_tests/data/corpus/timestamp.json +34 -0
  134. data/spec/spec_tests/data/corpus/top.json +236 -0
  135. data/spec/spec_tests/data/corpus/undefined.json +15 -0
  136. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/array.json +8 -2
  137. data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/binary.json +0 -0
  138. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/boolean.json +0 -0
  139. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code.json +1 -1
  140. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code_w_scope.json +1 -1
  141. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/document.json +1 -1
  142. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/double.json +1 -1
  143. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/datetime.json +0 -0
  144. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/dbpointer.json +0 -0
  145. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/int64.json +0 -0
  146. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/symbol.json +0 -0
  147. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/int32.json +1 -1
  148. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/maxkey.json +1 -1
  149. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/minkey.json +1 -1
  150. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/null.json +1 -1
  151. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/oid.json +0 -0
  152. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/regex.json +1 -1
  153. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/string.json +0 -0
  154. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/timestamp.json +1 -1
  155. data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/top.json +0 -0
  156. data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/undefined.json +0 -0
  157. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-1.json +0 -0
  158. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-2.json +0 -0
  159. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-3.json +0 -0
  160. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-4.json +0 -0
  161. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-5.json +0 -0
  162. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-6.json +0 -0
  163. data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-7.json +0 -0
  164. data/spec/support/shared_examples.rb +3 -5
  165. data/spec/support/spec_config.rb +16 -0
  166. data/spec/support/utils.rb +10 -0
  167. metadata +227 -124
  168. metadata.gz.sig +0 -0
  169. data/ext/bson/bson_native.c +0 -762
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2020 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,9 +13,11 @@
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
 
20
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "shared", "lib"))
19
21
  $LOAD_PATH.unshift(File.dirname(__FILE__))
20
22
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
21
23
 
@@ -25,6 +27,22 @@ require "json"
25
27
  require "rspec"
26
28
  require "yaml"
27
29
 
30
+ require 'support/spec_config'
31
+
32
+ if SpecConfig.instance.active_support?
33
+ require "active_support/time"
34
+ require 'bson/active_support'
35
+ end
36
+
37
+ unless ENV['CI'] || BSON::Environment.jruby?
38
+ begin
39
+ require 'byebug'
40
+ rescue Exception
41
+ end
42
+ end
43
+
44
+ require 'mrss/lite_constraints'
45
+
28
46
  Dir["./spec/support/**/*.rb"].each { |file| require file }
29
47
 
30
48
  # Alternate IO class that returns a String from #readbyte.
@@ -40,3 +58,22 @@ class AlternateIO < StringIO
40
58
  super.chr
41
59
  end
42
60
  end
61
+
62
+ RSpec.configure do |config|
63
+ config.expect_with :rspec do |c|
64
+ c.syntax = [:should, :expect]
65
+ end
66
+
67
+ # To ensure that calling GC.compact does not produce unexpected behavior,
68
+ # randomly call GC.compact after a small percentage of tests in the suite.
69
+ # This behavior is only enabled when the COMPACT environment variable is true.
70
+ if SpecConfig.instance.compact?
71
+ config.after do
72
+ if rand < SpecConfig::COMPACTION_CHANCE
73
+ GC.compact
74
+ end
75
+ end
76
+ end
77
+
78
+ config.extend Mrss::LiteConstraints
79
+ 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,12 +1,16 @@
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
- specs = BSON_CORPUS_TESTS.map { |file| BSON::Corpus::Spec.new(file) }
6
+ BSON_CORPUS_LEGACY_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\//, '')
6
10
 
7
- specs.each do |spec|
11
+ spec = BSON::CorpusLegacy::Spec.new(path)
8
12
 
9
- context(spec.description) do
13
+ context("(#{basename}): #{spec.description}") do
10
14
 
11
15
  spec.valid_tests.each do |test|
12
16
 
@@ -26,7 +30,6 @@ describe 'Driver BSON Corpus spec tests' do
26
30
  context 'when the document can be represented as extended json', if: test.test_extjson? do
27
31
 
28
32
  it 'decodes from the given bson, then encodes the document as extended json correctly' do
29
- skip 'The extended json in this test case does not match' unless (test.extjson_from_bson == test.correct_extjson)
30
33
  expect(test.extjson_from_bson).to eq(test.correct_extjson)
31
34
  expect(test.extjson_from_bson[test.test_key]).to eq(test.correct_extjson[test.test_key])
32
35
  end
@@ -57,9 +60,9 @@ describe 'Driver BSON Corpus spec tests' do
57
60
 
58
61
  it 'raises an error' do
59
62
  skip 'This test case does not raise and error but should' unless error
60
- expect {
63
+ expect do
61
64
  test.reencoded_bson
62
- }.to raise_error
65
+ end.to raise_error(error.class)
63
66
  end
64
67
  end
65
68
  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
+ }
@@ -0,0 +1,113 @@
1
+ {
2
+ "description": "Binary type",
3
+ "bson_type": "0x05",
4
+ "test_key": "x",
5
+ "valid": [
6
+ {
7
+ "description": "subtype 0x00 (Zero-length)",
8
+ "canonical_bson": "0D000000057800000000000000",
9
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}"
10
+ },
11
+ {
12
+ "description": "subtype 0x00 (Zero-length, keys reversed)",
13
+ "canonical_bson": "0D000000057800000000000000",
14
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}",
15
+ "degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}"
16
+ },
17
+ {
18
+ "description": "subtype 0x00",
19
+ "canonical_bson": "0F0000000578000200000000FFFF00",
20
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}"
21
+ },
22
+ {
23
+ "description": "subtype 0x01",
24
+ "canonical_bson": "0F0000000578000200000001FFFF00",
25
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}"
26
+ },
27
+ {
28
+ "description": "subtype 0x02",
29
+ "canonical_bson": "13000000057800060000000202000000FFFF00",
30
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}"
31
+ },
32
+ {
33
+ "description": "subtype 0x03",
34
+ "canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
35
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}"
36
+ },
37
+ {
38
+ "description": "subtype 0x04",
39
+ "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
40
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
41
+ },
42
+ {
43
+ "description": "subtype 0x04 UUID",
44
+ "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
45
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
46
+ "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
47
+ },
48
+ {
49
+ "description": "subtype 0x05",
50
+ "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
51
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}"
52
+ },
53
+ {
54
+ "description": "subtype 0x80",
55
+ "canonical_bson": "0F0000000578000200000080FFFF00",
56
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}"
57
+ },
58
+ {
59
+ "description": "$type query operator (conflicts with legacy $binary form with $type field)",
60
+ "canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000",
61
+ "canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}"
62
+ },
63
+ {
64
+ "description": "$type query operator (conflicts with legacy $binary form with $type field)",
65
+ "canonical_bson": "180000000378001000000010247479706500020000000000",
66
+ "canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}"
67
+ }
68
+ ],
69
+ "decodeErrors": [
70
+ {
71
+ "description": "Length longer than document",
72
+ "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
73
+ },
74
+ {
75
+ "description": "Negative length",
76
+ "bson": "0D000000057800FFFFFFFF0000"
77
+ },
78
+ {
79
+ "description": "subtype 0x02 length too long ",
80
+ "bson": "13000000057800060000000203000000FFFF00"
81
+ },
82
+ {
83
+ "description": "subtype 0x02 length too short",
84
+ "bson": "13000000057800060000000201000000FFFF00"
85
+ },
86
+ {
87
+ "description": "subtype 0x02 length negative one",
88
+ "bson": "130000000578000600000002FFFFFFFFFFFF00"
89
+ }
90
+ ],
91
+ "parseErrors": [
92
+ {
93
+ "description": "$uuid wrong type",
94
+ "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
95
+ },
96
+ {
97
+ "description": "$uuid invalid value--too short",
98
+ "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
99
+ },
100
+ {
101
+ "description": "$uuid invalid value--too long",
102
+ "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}"
103
+ },
104
+ {
105
+ "description": "$uuid invalid value--misplaced hyphens",
106
+ "string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}"
107
+ },
108
+ {
109
+ "description": "$uuid invalid value--too many hyphens",
110
+ "string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}"
111
+ }
112
+ ]
113
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "description": "Boolean",
3
+ "bson_type": "0x08",
4
+ "test_key": "b",
5
+ "valid": [
6
+ {
7
+ "description": "True",
8
+ "canonical_bson": "090000000862000100",
9
+ "canonical_extjson": "{\"b\" : true}"
10
+ },
11
+ {
12
+ "description": "False",
13
+ "canonical_bson": "090000000862000000",
14
+ "canonical_extjson": "{\"b\" : false}"
15
+ }
16
+ ],
17
+ "decodeErrors": [
18
+ {
19
+ "description": "Invalid boolean value of 2",
20
+ "bson": "090000000862000200"
21
+ },
22
+ {
23
+ "description": "Invalid boolean value of -1",
24
+ "bson": "09000000086200FF00"
25
+ }
26
+ ]
27
+ }