bson 4.1.1 → 5.2.0
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.
- checksums.yaml +5 -5
- data/README.md +106 -7
- data/Rakefile +86 -43
- data/ext/bson/{native-endian.h → bson-endian.h} +14 -107
- data/ext/bson/bson-native.h +135 -0
- data/ext/bson/bytebuf.c +133 -0
- data/ext/bson/endian.c +117 -0
- data/ext/bson/extconf.rb +8 -3
- data/ext/bson/init.c +364 -0
- data/ext/bson/libbson-utf8.c +230 -0
- data/ext/bson/read.c +470 -0
- data/ext/bson/util.c +250 -0
- data/ext/bson/write.c +675 -0
- data/lib/bson/active_support.rb +19 -0
- data/lib/bson/array.rb +97 -30
- data/lib/bson/big_decimal.rb +77 -0
- data/lib/bson/binary.rb +510 -70
- data/lib/bson/boolean.rb +15 -4
- data/lib/bson/code.rb +25 -12
- data/lib/bson/code_with_scope.rb +41 -15
- data/lib/bson/config.rb +3 -28
- data/lib/bson/date.rb +16 -4
- data/lib/bson/date_time.rb +6 -4
- data/lib/bson/db_pointer.rb +110 -0
- data/lib/bson/dbref.rb +154 -0
- data/lib/bson/decimal128/builder.rb +456 -0
- data/lib/bson/decimal128.rb +272 -0
- data/lib/bson/document.rb +177 -7
- data/lib/bson/environment.rb +17 -2
- 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 +22 -0
- data/lib/bson/ext_json.rb +389 -0
- data/lib/bson/false_class.rb +6 -4
- data/lib/bson/float.rb +43 -7
- data/lib/bson/hash.rb +152 -37
- data/lib/bson/int32.rb +104 -6
- data/lib/bson/int64.rb +111 -8
- data/lib/bson/integer.rb +43 -9
- data/lib/bson/json.rb +3 -1
- data/lib/bson/max_key.rb +21 -10
- data/lib/bson/min_key.rb +21 -10
- data/lib/bson/nil_class.rb +7 -3
- data/lib/bson/object.rb +25 -17
- data/lib/bson/object_id.rb +98 -113
- data/lib/bson/open_struct.rb +59 -0
- data/lib/bson/regexp.rb +129 -56
- data/lib/bson/registry.rb +7 -10
- data/lib/bson/specialized.rb +8 -4
- data/lib/bson/string.rb +12 -32
- data/lib/bson/symbol.rb +107 -11
- data/lib/bson/time.rb +68 -7
- data/lib/bson/time_with_zone.rb +67 -0
- data/lib/bson/timestamp.rb +50 -10
- data/lib/bson/true_class.rb +6 -4
- data/lib/bson/undefined.rb +28 -2
- data/lib/bson/vector.rb +44 -0
- data/lib/bson/version.rb +6 -14
- data/lib/bson.rb +22 -12
- data/spec/README.md +14 -0
- data/spec/bson/array_spec.rb +38 -62
- data/spec/bson/big_decimal_spec.rb +328 -0
- data/spec/bson/binary_spec.rb +199 -53
- data/spec/bson/binary_uuid_spec.rb +190 -0
- data/spec/bson/boolean_spec.rb +2 -1
- data/spec/bson/byte_buffer_read_spec.rb +198 -0
- data/spec/bson/byte_buffer_spec.rb +122 -381
- data/spec/bson/byte_buffer_write_spec.rb +855 -0
- data/spec/bson/code_spec.rb +6 -4
- data/spec/bson/code_with_scope_spec.rb +6 -4
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +2 -1
- data/spec/bson/date_time_spec.rb +55 -1
- data/spec/bson/dbref_legacy_spec.rb +186 -0
- data/spec/bson/dbref_spec.rb +487 -0
- data/spec/bson/decimal128_spec.rb +1840 -0
- data/spec/bson/document_as_spec.rb +61 -0
- data/spec/bson/document_spec.rb +205 -32
- data/spec/bson/ext_json_parse_spec.rb +346 -0
- data/spec/bson/false_class_spec.rb +9 -1
- data/spec/bson/float_spec.rb +42 -1
- data/spec/bson/hash_as_spec.rb +58 -0
- data/spec/bson/hash_spec.rb +318 -66
- data/spec/bson/int32_spec.rb +248 -1
- data/spec/bson/int64_spec.rb +308 -1
- data/spec/bson/integer_spec.rb +61 -3
- data/spec/bson/json_spec.rb +2 -1
- data/spec/bson/max_key_spec.rb +6 -4
- data/spec/bson/min_key_spec.rb +6 -4
- data/spec/bson/nil_class_spec.rb +2 -1
- data/spec/bson/object_id_spec.rb +95 -5
- data/spec/bson/object_spec.rb +3 -2
- data/spec/bson/open_struct_spec.rb +87 -0
- data/spec/bson/raw_spec.rb +594 -0
- data/spec/bson/regexp_spec.rb +61 -8
- data/spec/bson/registry_spec.rb +3 -2
- data/spec/bson/string_spec.rb +26 -33
- data/spec/bson/symbol_raw_spec.rb +70 -0
- data/spec/bson/symbol_spec.rb +77 -20
- data/spec/bson/time_spec.rb +206 -2
- data/spec/bson/time_with_zone_spec.rb +69 -0
- data/spec/bson/timestamp_spec.rb +58 -2
- data/spec/bson/true_class_spec.rb +9 -1
- data/spec/bson/undefined_spec.rb +28 -1
- data/spec/bson/vector_spec.rb +33 -0
- data/spec/bson_spec.rb +2 -1
- data/spec/runners/binary_vector.rb +78 -0
- data/spec/runners/common_driver.rb +348 -0
- data/spec/runners/corpus.rb +191 -0
- data/spec/runners/corpus_legacy.rb +248 -0
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/release/candidate.rb +281 -0
- data/spec/shared/lib/mrss/release/product_data.rb +144 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- 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/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/lib/tasks/candidate.rake +64 -0
- data/spec/shared/share/Dockerfile.erb +251 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +84 -0
- data/spec/shared/shlib/server.sh +423 -0
- data/spec/shared/shlib/set_env.sh +110 -0
- data/spec/spec_helper.rb +61 -1
- data/spec/spec_tests/binary_vector_spec.rb +82 -0
- data/spec/spec_tests/common_driver_spec.rb +84 -0
- data/spec/spec_tests/corpus_legacy_spec.rb +72 -0
- data/spec/spec_tests/corpus_spec.rb +134 -0
- data/spec/spec_tests/data/binary_vector/README.md +61 -0
- data/spec/spec_tests/data/binary_vector/float32.json +65 -0
- data/spec/spec_tests/data/binary_vector/int8.json +57 -0
- data/spec/spec_tests/data/binary_vector/packed_bit.json +83 -0
- data/spec/spec_tests/data/corpus/README.md +15 -0
- data/spec/spec_tests/data/corpus/array.json +49 -0
- data/spec/spec_tests/data/corpus/binary.json +153 -0
- data/spec/spec_tests/data/corpus/boolean.json +27 -0
- data/spec/spec_tests/data/corpus/code.json +67 -0
- data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
- data/spec/spec_tests/data/corpus/datetime.json +42 -0
- data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
- data/spec/spec_tests/data/corpus/dbref.json +51 -0
- data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
- data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
- data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
- data/spec/spec_tests/data/corpus/decimal128-4.json +165 -0
- data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +131 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +327 -0
- data/spec/spec_tests/data/corpus/document.json +60 -0
- data/spec/spec_tests/data/corpus/double.json +87 -0
- data/spec/spec_tests/data/corpus/int32.json +43 -0
- data/spec/spec_tests/data/corpus/int64.json +43 -0
- data/spec/spec_tests/data/corpus/maxkey.json +12 -0
- data/spec/spec_tests/data/corpus/minkey.json +12 -0
- data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
- data/spec/spec_tests/data/corpus/multi-type.json +11 -0
- data/spec/spec_tests/data/corpus/null.json +12 -0
- data/spec/spec_tests/data/corpus/oid.json +28 -0
- data/spec/spec_tests/data/corpus/regex.json +65 -0
- data/spec/spec_tests/data/corpus/string.json +72 -0
- data/spec/spec_tests/data/corpus/symbol.json +80 -0
- data/spec/spec_tests/data/corpus/timestamp.json +34 -0
- data/spec/spec_tests/data/corpus/top.json +262 -0
- data/spec/spec_tests/data/corpus/undefined.json +15 -0
- data/spec/spec_tests/data/corpus_legacy/array.json +49 -0
- data/spec/spec_tests/data/corpus_legacy/binary.json +69 -0
- data/spec/spec_tests/data/corpus_legacy/boolean.json +27 -0
- data/spec/spec_tests/data/corpus_legacy/code.json +67 -0
- data/spec/spec_tests/data/corpus_legacy/code_w_scope.json +78 -0
- data/spec/spec_tests/data/corpus_legacy/document.json +36 -0
- data/spec/spec_tests/data/corpus_legacy/double.json +69 -0
- data/spec/spec_tests/data/corpus_legacy/failures/datetime.json +31 -0
- data/spec/spec_tests/data/corpus_legacy/failures/dbpointer.json +42 -0
- data/spec/spec_tests/data/corpus_legacy/failures/int64.json +38 -0
- data/spec/spec_tests/data/corpus_legacy/failures/symbol.json +62 -0
- data/spec/spec_tests/data/corpus_legacy/int32.json +38 -0
- data/spec/spec_tests/data/corpus_legacy/maxkey.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/minkey.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/null.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/oid.json +28 -0
- data/spec/spec_tests/data/corpus_legacy/regex.json +37 -0
- data/spec/spec_tests/data/corpus_legacy/string.json +67 -0
- data/spec/spec_tests/data/corpus_legacy/timestamp.json +18 -0
- data/spec/spec_tests/data/corpus_legacy/top.json +62 -0
- data/spec/spec_tests/data/corpus_legacy/undefined.json +13 -0
- data/spec/spec_tests/data/decimal128/decimal128-1.json +363 -0
- data/spec/spec_tests/data/decimal128/decimal128-2.json +793 -0
- data/spec/spec_tests/data/decimal128/decimal128-3.json +1771 -0
- data/spec/spec_tests/data/decimal128/decimal128-4.json +165 -0
- data/spec/spec_tests/data/decimal128/decimal128-5.json +402 -0
- data/spec/spec_tests/data/decimal128/decimal128-6.json +131 -0
- data/spec/spec_tests/data/decimal128/decimal128-7.json +327 -0
- data/spec/support/shared_examples.rb +32 -11
- data/spec/support/spec_config.rb +17 -0
- data/spec/support/utils.rb +58 -0
- metadata +284 -45
- checksums.yaml.gz.sig +0 -3
- data/ext/bson/native.c +0 -722
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# rubocop:todo all
|
|
2
|
+
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require "spec_helper"
|
|
17
|
+
require "base64"
|
|
18
|
+
|
|
19
|
+
describe "BSON::Binary - UUID spec tests" do
|
|
20
|
+
def make_binary(uuid_hex_str, type)
|
|
21
|
+
uuid_binary_str = uuid_hex_str.scan(/../).map(&:hex).map(&:chr).join
|
|
22
|
+
BSON::Binary.new(uuid_binary_str, type)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'explicit encoding' do
|
|
26
|
+
let(:uuid_str) { '00112233-4455-6677-8899-aabbccddeeff' }
|
|
27
|
+
|
|
28
|
+
shared_examples_for 'creates binary' do
|
|
29
|
+
it 'creates subtype 4 binary' do
|
|
30
|
+
expect(binary.type).to eq(expected_type)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'creates binary with correct value' do
|
|
34
|
+
expect(binary.data).to eq(expected_hex_value.scan(/../).map(&:hex).map(&:chr).join)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context 'no representation' do
|
|
39
|
+
let(:binary) { BSON::Binary.from_uuid(uuid_str) }
|
|
40
|
+
let(:expected_type) { :uuid }
|
|
41
|
+
let(:expected_hex_value) { '00112233445566778899AABBCCDDEEFF' }
|
|
42
|
+
|
|
43
|
+
it_behaves_like 'creates binary'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'standard representation' do
|
|
47
|
+
let(:binary) { BSON::Binary.from_uuid(uuid_str, :standard) }
|
|
48
|
+
let(:expected_type) { :uuid }
|
|
49
|
+
let(:expected_hex_value) { '00112233445566778899AABBCCDDEEFF' }
|
|
50
|
+
|
|
51
|
+
it_behaves_like 'creates binary'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'csharp legacy representation' do
|
|
55
|
+
let(:binary) { BSON::Binary.from_uuid(uuid_str, :csharp_legacy) }
|
|
56
|
+
let(:expected_type) { :uuid_old }
|
|
57
|
+
let(:expected_hex_value) { '33221100554477668899AABBCCDDEEFF' }
|
|
58
|
+
|
|
59
|
+
it_behaves_like 'creates binary'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'java legacy representation' do
|
|
63
|
+
let(:binary) { BSON::Binary.from_uuid(uuid_str, :java_legacy) }
|
|
64
|
+
let(:expected_type) { :uuid_old }
|
|
65
|
+
let(:expected_hex_value) { '7766554433221100FFEEDDCCBBAA9988' }
|
|
66
|
+
|
|
67
|
+
it_behaves_like 'creates binary'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context 'python legacy representation' do
|
|
71
|
+
let(:binary) { BSON::Binary.from_uuid(uuid_str, :python_legacy) }
|
|
72
|
+
let(:expected_type) { :uuid_old }
|
|
73
|
+
let(:expected_hex_value) { '00112233445566778899AABBCCDDEEFF' }
|
|
74
|
+
|
|
75
|
+
it_behaves_like 'creates binary'
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe 'explicit decoding' do
|
|
80
|
+
context ':uuid, standard encoded' do
|
|
81
|
+
let(:binary) { make_binary("00112233445566778899AABBCCDDEEFF", :uuid) }
|
|
82
|
+
|
|
83
|
+
it 'decodes without arguments' do
|
|
84
|
+
expect(binary.to_uuid.gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'decodes as standard' do
|
|
88
|
+
expect(binary.to_uuid(:standard).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'does not decode as csharp legacy' do
|
|
92
|
+
expect do
|
|
93
|
+
binary.to_uuid(:csharp_legacy)
|
|
94
|
+
end.to raise_error(ArgumentError, /Binary of type :uuid can only be stringified to :standard representation/)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'does not decode as java legacy' do
|
|
98
|
+
expect do
|
|
99
|
+
binary.to_uuid(:java_legacy)
|
|
100
|
+
end.to raise_error(ArgumentError, /Binary of type :uuid can only be stringified to :standard representation/)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'does not decode as python legacy' do
|
|
104
|
+
expect do
|
|
105
|
+
binary.to_uuid(:python_legacy)
|
|
106
|
+
end.to raise_error(ArgumentError, /Binary of type :uuid can only be stringified to :standard representation/)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
shared_examples_for 'a legacy uuid' do
|
|
111
|
+
it 'does not decode without arguments' do
|
|
112
|
+
expect do
|
|
113
|
+
binary.to_uuid
|
|
114
|
+
end.to raise_error(ArgumentError, /Representation must be specified for BSON::Binary objects of type :uuid_old/)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'does not decode as standard' do
|
|
118
|
+
expect do
|
|
119
|
+
binary.to_uuid(:standard)
|
|
120
|
+
end.to raise_error(ArgumentError, /BSON::Binary objects of type :uuid_old cannot be stringified to :standard representation/)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context ':uuid_old, csharp legacy encoded' do
|
|
125
|
+
let(:binary) { make_binary("33221100554477668899AABBCCDDEEFF", :uuid_old) }
|
|
126
|
+
|
|
127
|
+
it_behaves_like 'a legacy uuid'
|
|
128
|
+
|
|
129
|
+
it 'decodes as csharp legacy' do
|
|
130
|
+
expect(binary.to_uuid(:csharp_legacy).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'decodes as java legacy' do
|
|
134
|
+
expect(binary.to_uuid(:java_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'decodes as python legacy' do
|
|
138
|
+
expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'expects four dashes when output as String' do
|
|
142
|
+
expect(binary.to_uuid(:csharp_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context ':uuid_old, java legacy encoded' do
|
|
147
|
+
let(:binary) { make_binary("7766554433221100FFEEDDCCBBAA9988", :uuid_old) }
|
|
148
|
+
|
|
149
|
+
it_behaves_like 'a legacy uuid'
|
|
150
|
+
|
|
151
|
+
it 'decodes as csharp legacy' do
|
|
152
|
+
expect(binary.to_uuid(:csharp_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'decodes as java legacy' do
|
|
156
|
+
expect(binary.to_uuid(:java_legacy).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'decodes as python legacy' do
|
|
160
|
+
expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'expects four dashes when output as String' do
|
|
164
|
+
expect(binary.to_uuid(:java_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
context ':uuid_old, python legacy encoded' do
|
|
169
|
+
let(:binary) { make_binary("00112233445566778899AABBCCDDEEFF", :uuid_old) }
|
|
170
|
+
|
|
171
|
+
it_behaves_like 'a legacy uuid'
|
|
172
|
+
|
|
173
|
+
it 'decodes as csharp legacy' do
|
|
174
|
+
expect(binary.to_uuid(:csharp_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'decodes as java legacy' do
|
|
178
|
+
expect(binary.to_uuid(:java_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'decodes as python legacy' do
|
|
182
|
+
expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'expects four dashes when output as String' do
|
|
186
|
+
expect(binary.to_uuid(:python_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
data/spec/bson/boolean_spec.rb
CHANGED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# rubocop:todo all
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BSON::ByteBuffer do
|
|
5
|
+
|
|
6
|
+
describe '#get_byte' do
|
|
7
|
+
|
|
8
|
+
let(:buffer) do
|
|
9
|
+
described_class.new(BSON::Int32::BSON_TYPE)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let!(:byte) do
|
|
13
|
+
buffer.get_byte
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'gets the byte from the buffer' do
|
|
17
|
+
expect(byte).to eq(BSON::Int32::BSON_TYPE)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'increments the read position by 1' do
|
|
21
|
+
expect(buffer.read_position).to eq(1)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#get_bytes' do
|
|
26
|
+
|
|
27
|
+
let(:string) do
|
|
28
|
+
"#{BSON::Int32::BSON_TYPE}#{BSON::Int32::BSON_TYPE}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
let(:buffer) do
|
|
32
|
+
described_class.new(string)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
let!(:bytes) do
|
|
36
|
+
buffer.get_bytes(2)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'gets the bytes from the buffer' do
|
|
40
|
+
expect(bytes).to eq(string)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'increments the position by the length' do
|
|
44
|
+
expect(buffer.read_position).to eq(string.bytesize)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe '#get_cstring' do
|
|
49
|
+
|
|
50
|
+
let(:buffer) do
|
|
51
|
+
described_class.new("testing#{BSON::NULL_BYTE}")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let!(:string) do
|
|
55
|
+
buffer.get_cstring
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'gets the cstring from the buffer' do
|
|
59
|
+
expect(string).to eq("testing")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'increments the position by string length + 1' do
|
|
63
|
+
expect(buffer.read_position).to eq(8)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe '#get_double' do
|
|
68
|
+
|
|
69
|
+
let(:buffer) do
|
|
70
|
+
described_class.new(12.5.to_bson.to_s)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
let!(:double) do
|
|
74
|
+
buffer.get_double
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'gets the double from the buffer' do
|
|
78
|
+
expect(double).to eq(12.5)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'increments the read position by 8' do
|
|
82
|
+
expect(buffer.read_position).to eq(8)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#get_int32' do
|
|
87
|
+
|
|
88
|
+
let(:buffer) do
|
|
89
|
+
described_class.new(12.to_bson.to_s)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
let!(:int32) do
|
|
93
|
+
buffer.get_int32
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'gets the int32 from the buffer' do
|
|
97
|
+
expect(int32).to eq(12)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'increments the position by 4' do
|
|
101
|
+
expect(buffer.read_position).to eq(4)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#get_uint32' do
|
|
106
|
+
context 'when using 2^32-1' do
|
|
107
|
+
let(:buffer) do
|
|
108
|
+
described_class.new(4294967295.to_bson.to_s)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
let!(:int32) do
|
|
112
|
+
buffer.get_uint32
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'gets the uint32 from the buffer' do
|
|
116
|
+
expect(int32).to eq(4294967295)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'increments the position by 4' do
|
|
120
|
+
expect(buffer.read_position).to eq(4)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'when using 2^32-2' do
|
|
125
|
+
let(:buffer) do
|
|
126
|
+
described_class.new(4294967294.to_bson.to_s)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
let!(:int32) do
|
|
130
|
+
buffer.get_uint32
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'gets the uint32 from the buffer' do
|
|
134
|
+
expect(int32).to eq(4294967294)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'increments the position by 4' do
|
|
138
|
+
expect(buffer.read_position).to eq(4)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
context 'when using 0' do
|
|
143
|
+
let(:buffer) do
|
|
144
|
+
described_class.new(0.to_bson.to_s)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
let!(:int32) do
|
|
148
|
+
buffer.get_uint32
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'gets the uint32 from the buffer' do
|
|
152
|
+
expect(int32).to eq(0)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'increments the position by 4' do
|
|
156
|
+
expect(buffer.read_position).to eq(4)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe '#get_int64' do
|
|
162
|
+
|
|
163
|
+
let(:buffer) do
|
|
164
|
+
described_class.new((Integer::MAX_64BIT - 1).to_bson.to_s)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
let!(:int64) do
|
|
168
|
+
buffer.get_int64
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'gets the int64 from the buffer' do
|
|
172
|
+
expect(int64).to eq(Integer::MAX_64BIT - 1)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'increments the position by 8' do
|
|
176
|
+
expect(buffer.read_position).to eq(8)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe '#get_string' do
|
|
181
|
+
|
|
182
|
+
let(:buffer) do
|
|
183
|
+
described_class.new("#{8.to_bson.to_s}testing#{BSON::NULL_BYTE}")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
let!(:string) do
|
|
187
|
+
buffer.get_string
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'gets the string from the buffer' do
|
|
191
|
+
expect(string).to eq("testing")
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it 'increments the position by string length + 5' do
|
|
195
|
+
expect(buffer.read_position).to eq(12)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|