bson 4.2.0.rc1-java → 4.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson/array.rb +1 -1
- data/lib/bson/binary.rb +4 -2
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +1 -1
- data/lib/bson/date.rb +1 -1
- data/lib/bson/date_time.rb +1 -1
- data/lib/bson/decimal128.rb +2 -2
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +1 -1
- data/lib/bson/integer.rb +1 -1
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/open_struct.rb +1 -1
- data/lib/bson/regexp.rb +87 -19
- data/lib/bson/specialized.rb +1 -1
- data/lib/bson/string.rb +1 -1
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/time.rb +1 -1
- data/lib/bson/timestamp.rb +1 -1
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/version.rb +1 -1
- data/spec/bson/array_spec.rb +1 -1
- data/spec/bson/binary_spec.rb +2 -1
- data/spec/bson/corpus_spec.rb +68 -0
- data/spec/bson/decimal128_spec.rb +5 -1
- data/spec/bson/int64_spec.rb +47 -0
- data/spec/bson/raw_spec.rb +562 -0
- data/spec/bson/regexp_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -0
- data/spec/support/corpus-tests/array.json +43 -0
- data/spec/support/corpus-tests/boolean.json +27 -0
- data/spec/support/corpus-tests/code.json +67 -0
- data/spec/support/corpus-tests/code_w_scope.json +78 -0
- data/spec/support/corpus-tests/document.json +36 -0
- data/spec/support/corpus-tests/double.json +69 -0
- data/spec/support/corpus-tests/failures/binary.json +69 -0
- data/spec/support/corpus-tests/failures/datetime.json +31 -0
- data/spec/support/corpus-tests/failures/dbpointer.json +42 -0
- data/spec/support/corpus-tests/failures/int64.json +38 -0
- data/spec/support/corpus-tests/failures/symbol.json +62 -0
- data/spec/support/corpus-tests/failures/undefined.json +13 -0
- data/spec/support/corpus-tests/int32.json +38 -0
- data/spec/support/corpus-tests/maxkey.json +12 -0
- data/spec/support/corpus-tests/minkey.json +12 -0
- data/spec/support/corpus-tests/null.json +12 -0
- data/spec/support/corpus-tests/oid.json +28 -0
- data/spec/support/corpus-tests/regex.json +37 -0
- data/spec/support/corpus-tests/string.json +67 -0
- data/spec/support/corpus-tests/timestamp.json +18 -0
- data/spec/support/corpus-tests/top.json +62 -0
- data/spec/support/corpus.rb +265 -0
- data/spec/support/shared_examples.rb +1 -1
- metadata +51 -3
- metadata.gz.sig +0 -0
@@ -49,6 +49,10 @@ describe BSON::Decimal128 do
|
|
49
49
|
described_class.from_bson(buffer)
|
50
50
|
end
|
51
51
|
|
52
|
+
let(:expected_bson) do
|
53
|
+
[expected_low_bits].pack(BSON::Int64::PACK) + [expected_high_bits].pack(BSON::Int64::PACK)
|
54
|
+
end
|
55
|
+
|
52
56
|
it 'sets the correct high order bits' do
|
53
57
|
expect(high_bits).to eq(expected_high_bits)
|
54
58
|
end
|
@@ -58,7 +62,7 @@ describe BSON::Decimal128 do
|
|
58
62
|
end
|
59
63
|
|
60
64
|
it 'serializes to bson' do
|
61
|
-
expect(buffer.
|
65
|
+
expect(buffer.to_s).to eq(expected_bson)
|
62
66
|
end
|
63
67
|
|
64
68
|
it 'deserializes to the correct bits' do
|
data/spec/bson/int64_spec.rb
CHANGED
@@ -60,6 +60,53 @@ describe BSON::Int64 do
|
|
60
60
|
|
61
61
|
it_behaves_like "a bson element"
|
62
62
|
it_behaves_like "a deserializable bson element"
|
63
|
+
|
64
|
+
|
65
|
+
context "when the integer is within the MRI Fixnum range" do
|
66
|
+
|
67
|
+
let(:integer) { BSON::Integer::MAX_32BIT + 1 }
|
68
|
+
|
69
|
+
let(:bson) do
|
70
|
+
BSON::ByteBuffer.new(integer.to_bson.to_s)
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when on JRuby", if: BSON::Environment.jruby? do
|
74
|
+
|
75
|
+
it "deserializes to a Fixnum object" do
|
76
|
+
expect(described_class.from_bson(bson).class).to be(Fixnum)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when using MRI", unless: BSON::Environment.jruby? do
|
81
|
+
|
82
|
+
it "deserializes to a Fixnum object" do
|
83
|
+
expect(described_class.from_bson(bson).class).to be(Fixnum)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the 64-bit integer is the BSON max and thus larger than the MRI Fixnum range" do
|
89
|
+
|
90
|
+
let(:integer) { Integer::MAX_64BIT }
|
91
|
+
|
92
|
+
let(:bson) do
|
93
|
+
BSON::ByteBuffer.new(integer.to_bson.to_s)
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when on JRuby", if: BSON::Environment.jruby? do
|
97
|
+
|
98
|
+
it "deserializes to a Fixnum object" do
|
99
|
+
expect(described_class.from_bson(bson).class).to be(Fixnum)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when using MRI", unless: BSON::Environment.jruby? do
|
104
|
+
|
105
|
+
it "deserializes to a Bignum object" do
|
106
|
+
expect(described_class.from_bson(bson).class).to be(Bignum)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
63
110
|
end
|
64
111
|
|
65
112
|
describe "#to_bson" do
|
@@ -0,0 +1,562 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Regexp::Raw do
|
4
|
+
|
5
|
+
let(:pattern) { '\W+' }
|
6
|
+
let(:options) { '' }
|
7
|
+
let(:bson) { "#{pattern}#{BSON::NULL_BYTE}#{options}#{BSON::NULL_BYTE}" }
|
8
|
+
|
9
|
+
describe "#as_json" do
|
10
|
+
|
11
|
+
let(:object) do
|
12
|
+
described_class.new(pattern, 'im')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the regex pattern and options" do
|
16
|
+
expect(object.as_json).to eq({ "$regex" => "\\W+", "$options" => "im" })
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like "a JSON serializable object"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#to_bson/#from_bson" do
|
23
|
+
|
24
|
+
let(:options) { 'ilmsux' }
|
25
|
+
let(:obj) { described_class.new(pattern, options) }
|
26
|
+
let(:type) { 11.chr }
|
27
|
+
let(:bson) { "#{pattern}#{BSON::NULL_BYTE}#{options}#{BSON::NULL_BYTE}" }
|
28
|
+
|
29
|
+
let(:klass) { ::Regexp }
|
30
|
+
|
31
|
+
it_behaves_like "a bson element"
|
32
|
+
it_behaves_like "a serializable bson element"
|
33
|
+
it_behaves_like "a deserializable bson element"
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#initialize" do
|
37
|
+
|
38
|
+
let(:object) do
|
39
|
+
described_class.new(pattern, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when options are not passed" do
|
43
|
+
|
44
|
+
it "sets the options on the raw regex" do
|
45
|
+
expect(object.options). to eq(options)
|
46
|
+
end
|
47
|
+
|
48
|
+
context "When the raw regexp is compiled" do
|
49
|
+
|
50
|
+
let(:regexp) do
|
51
|
+
object.compile
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sets the options on the compiled regexp object" do
|
55
|
+
expect(regexp.options).to eq(0)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when options are passed" do
|
61
|
+
|
62
|
+
context "when options are an Integer" do
|
63
|
+
|
64
|
+
let(:options) { ::Regexp::EXTENDED }
|
65
|
+
|
66
|
+
it "sets the options on the raw regex" do
|
67
|
+
expect(object.options). to eq(options)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "When the raw regexp is compiled" do
|
71
|
+
|
72
|
+
let(:regexp) do
|
73
|
+
object.compile
|
74
|
+
end
|
75
|
+
|
76
|
+
it "sets the options on the compiled regexp object" do
|
77
|
+
expect(regexp.options).to eq(options)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when options are a String" do
|
83
|
+
|
84
|
+
let(:options) { 'x' }
|
85
|
+
|
86
|
+
it "sets the options on the raw regex" do
|
87
|
+
expect(object.options). to eq(options)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "When the raw regexp is compiled" do
|
91
|
+
|
92
|
+
let(:regexp) do
|
93
|
+
object.compile
|
94
|
+
end
|
95
|
+
|
96
|
+
it "sets the options on the compiled regexp object" do
|
97
|
+
expect(regexp.options).to eq(::Regexp::EXTENDED)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when options are not passed' do
|
104
|
+
|
105
|
+
let(:object) do
|
106
|
+
described_class.new(pattern)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "sets no options on the raw regex" do
|
110
|
+
expect(object.options). to eq('')
|
111
|
+
end
|
112
|
+
|
113
|
+
context "When the raw regexp is compiled" do
|
114
|
+
|
115
|
+
let(:regexp) do
|
116
|
+
object.compile
|
117
|
+
end
|
118
|
+
|
119
|
+
it "sets the options on the compiled regexp object" do
|
120
|
+
expect(regexp.options).to eq(0)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#from_bson" do
|
127
|
+
|
128
|
+
let(:obj) { ::Regexp.from_bson(io) }
|
129
|
+
let(:io) { BSON::ByteBuffer.new(bson) }
|
130
|
+
|
131
|
+
it "deserializes to a Regexp::Raw object" do
|
132
|
+
expect(obj).to be_a(Regexp::Raw)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "deserializes the pattern" do
|
136
|
+
expect(obj.pattern).to eq(pattern)
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when there are no options" do
|
140
|
+
|
141
|
+
it "does not set any options on the raw regexp object" do
|
142
|
+
expect(obj.options).to eq(options)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when there are options" do
|
147
|
+
|
148
|
+
context "when there is the i ignorecase option" do
|
149
|
+
|
150
|
+
let(:options) { 'i' }
|
151
|
+
|
152
|
+
it "deserializes the pattern" do
|
153
|
+
expect(obj.pattern).to eq(pattern)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "sets the i option on the raw regexp object" do
|
157
|
+
expect(obj.options).to eq(options)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when there is the l locale dependent option" do
|
162
|
+
|
163
|
+
let(:options) { 'l' }
|
164
|
+
|
165
|
+
it "deserializes the pattern" do
|
166
|
+
expect(obj.pattern).to eq(pattern)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "sets the l option on the raw regexp object" do
|
170
|
+
expect(obj.options).to eq(options)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "when there is the m multiline option" do
|
175
|
+
|
176
|
+
let(:options) { 'm' }
|
177
|
+
|
178
|
+
it "deserializes the pattern" do
|
179
|
+
expect(obj.pattern).to eq(pattern)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "sets the m option on the raw regexp object" do
|
183
|
+
expect(obj.options).to eq(options)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when there is the s dotall option" do
|
188
|
+
|
189
|
+
let(:options) { 's' }
|
190
|
+
|
191
|
+
it "deserializes the pattern" do
|
192
|
+
expect(obj.pattern).to eq(pattern)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "sets the s option on the raw regexp object" do
|
196
|
+
expect(obj.options).to eq(options)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when there is the u match unicode option" do
|
201
|
+
|
202
|
+
let(:options) { 'u' }
|
203
|
+
|
204
|
+
it "deserializes the pattern" do
|
205
|
+
expect(obj.pattern).to eq(pattern)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "sets the u option on the raw regexp object" do
|
209
|
+
expect(obj.options).to eq(options)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when there is the x verbose option" do
|
214
|
+
|
215
|
+
let(:options) { 'x' }
|
216
|
+
|
217
|
+
it "deserializes the pattern" do
|
218
|
+
expect(obj.pattern).to eq(pattern)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "sets the x option on the raw regexp object" do
|
222
|
+
expect(obj.options).to eq(options)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context "when all options are set" do
|
227
|
+
|
228
|
+
let(:options) { 'ilmsux' }
|
229
|
+
|
230
|
+
it "deserializes the pattern" do
|
231
|
+
expect(obj.pattern).to eq(pattern)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "sets all options on the raw regexp object" do
|
235
|
+
expect(obj.options).to eq(options)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "when a method is called on a Raw regexp object" do
|
242
|
+
|
243
|
+
let(:obj) { ::Regexp.from_bson(io) }
|
244
|
+
let(:io) { BSON::ByteBuffer.new(bson) }
|
245
|
+
|
246
|
+
it "forwards the method call on to the compiled Ruby Regexp object" do
|
247
|
+
expect(obj.source).to eq(pattern)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "when respond_to? is called on the Raw Regexp object" do
|
252
|
+
|
253
|
+
let(:obj) { Regexp::Raw.new(pattern, options) }
|
254
|
+
|
255
|
+
context "when include_private is false" do
|
256
|
+
|
257
|
+
it "does not consider private methods" do
|
258
|
+
expect(obj.respond_to?(:initialize_copy)).to eq(false)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "when include private is true" do
|
263
|
+
|
264
|
+
it "considers private methods" do
|
265
|
+
expect(obj.respond_to?(:initialize_copy, true)).to eq(true)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context "when include_private is not specified" do
|
270
|
+
|
271
|
+
it "does not consider private methods" do
|
272
|
+
expect(obj.respond_to?(:initialize_copy)).to eq(false)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "#to_bson" do
|
278
|
+
|
279
|
+
let(:obj) { Regexp::Raw.new(pattern, options) }
|
280
|
+
let(:options) { '' }
|
281
|
+
let(:bson) { "#{pattern}#{BSON::NULL_BYTE}#{options}#{BSON::NULL_BYTE}" }
|
282
|
+
let(:serialized) { obj.to_bson.to_s }
|
283
|
+
|
284
|
+
it "serializes the pattern" do
|
285
|
+
expect(serialized).to eq(bson)
|
286
|
+
end
|
287
|
+
|
288
|
+
context "where there are no options" do
|
289
|
+
|
290
|
+
it "does not set any options on the bson regex object" do
|
291
|
+
expect(serialized).to eq(bson)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "when there are options" do
|
296
|
+
|
297
|
+
context "when options are specified as an Integer" do
|
298
|
+
|
299
|
+
let(:options) { ::Regexp::EXTENDED }
|
300
|
+
let(:bson) { "#{pattern}#{BSON::NULL_BYTE}mx#{BSON::NULL_BYTE}" }
|
301
|
+
|
302
|
+
it "sets the option on the serialized bson object" do
|
303
|
+
expect(serialized).to eq(bson)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context "when there is the i ignorecase option" do
|
308
|
+
|
309
|
+
let(:options) { 'i' }
|
310
|
+
|
311
|
+
it "sets the option on the serialized bson object" do
|
312
|
+
expect(serialized).to eq(bson)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context "when there is the l locale dependent option" do
|
317
|
+
|
318
|
+
let(:options) { 'l' }
|
319
|
+
|
320
|
+
it "sets the option on the serialized bson object" do
|
321
|
+
expect(serialized).to eq(bson)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
context "when there is the m multiline option" do
|
326
|
+
|
327
|
+
let(:options) { 'm' }
|
328
|
+
|
329
|
+
it "sets the option on the serialized bson object" do
|
330
|
+
expect(serialized).to eq(bson)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context "when there is the s dotall option" do
|
335
|
+
|
336
|
+
let(:options) { 's' }
|
337
|
+
|
338
|
+
it "sets the option on the serialized bson object" do
|
339
|
+
expect(serialized).to eq(bson)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context "when there is the u match unicode option" do
|
344
|
+
|
345
|
+
let(:options) { 'u' }
|
346
|
+
|
347
|
+
it "sets the option on the serialized bson object" do
|
348
|
+
expect(serialized).to eq(bson)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
context "when there is the x verbose option" do
|
353
|
+
|
354
|
+
let(:options) { 'x' }
|
355
|
+
|
356
|
+
it "sets the option on the serialized bson object" do
|
357
|
+
expect(serialized).to eq(bson)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
context "when all options are set" do
|
362
|
+
|
363
|
+
let(:options) { 'ilmsux' }
|
364
|
+
|
365
|
+
it "sets all options on the serialized bson object" do
|
366
|
+
expect(serialized).to eq(bson)
|
367
|
+
end
|
368
|
+
|
369
|
+
context "when the options are not provided in alphabetical order" do
|
370
|
+
|
371
|
+
let(:options) { 'mislxu' }
|
372
|
+
let(:bson) { "#{pattern}#{BSON::NULL_BYTE}ilmsux#{BSON::NULL_BYTE}" }
|
373
|
+
|
374
|
+
it "serializes the options in alphabetical order" do
|
375
|
+
expect(serialized).to eq(bson)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
describe "#compile" do
|
383
|
+
|
384
|
+
let(:obj) { Regexp.from_bson(io) }
|
385
|
+
let(:io) { BSON::ByteBuffer.new(bson) }
|
386
|
+
let(:ruby_regexp) { obj.compile }
|
387
|
+
|
388
|
+
it "sets the pattern on the Ruby Regexp object" do
|
389
|
+
expect(obj.pattern).to eq(ruby_regexp.source)
|
390
|
+
end
|
391
|
+
|
392
|
+
context "when there are no options set" do
|
393
|
+
|
394
|
+
it "does not set any options on the Ruby Regexp object" do
|
395
|
+
expect(ruby_regexp.options).to eq(0)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
context "when there are options set" do
|
400
|
+
|
401
|
+
context "when there is the i ignorecase option" do
|
402
|
+
|
403
|
+
let(:options) { 'i' }
|
404
|
+
|
405
|
+
it "sets the i option on the Ruby Regexp object" do
|
406
|
+
expect(ruby_regexp.options).to eq(::Regexp::IGNORECASE)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
context "when there is the l locale dependent option" do
|
411
|
+
|
412
|
+
let(:options) { 'l' }
|
413
|
+
|
414
|
+
it "does not set an option on the Ruby Regexp object" do
|
415
|
+
expect(ruby_regexp.options).to eq(0)
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
context "when there is the m multiline option" do
|
420
|
+
|
421
|
+
let(:options) { 'm' }
|
422
|
+
|
423
|
+
it "does not set an option on the Ruby Regexp object" do
|
424
|
+
expect(ruby_regexp.options).to eq(0)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context "when there is the s dotall option" do
|
429
|
+
|
430
|
+
let(:options) { 's' }
|
431
|
+
|
432
|
+
# s in a bson regex maps to a Ruby Multiline Regexp option
|
433
|
+
it "sets the m option on the Ruby Regexp object" do
|
434
|
+
expect(ruby_regexp.options).to eq(::Regexp::MULTILINE)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
context "when there is the u match unicode option" do
|
439
|
+
|
440
|
+
let(:options) { 'u' }
|
441
|
+
|
442
|
+
it "does not set an option on the Ruby Regexp object" do
|
443
|
+
expect(ruby_regexp.options).to eq(0)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "when there is the x verbose option" do
|
448
|
+
|
449
|
+
let(:options) { 'x' }
|
450
|
+
|
451
|
+
it "sets the x option on the Ruby Regexp object" do
|
452
|
+
expect(ruby_regexp.options).to eq(::Regexp::EXTENDED)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
context "when all options are set" do
|
457
|
+
|
458
|
+
let(:options) { 'ilmsux' }
|
459
|
+
|
460
|
+
# s in a bson regex maps to a Ruby Multiline Regexp option
|
461
|
+
it "sets the i, m, and x options on the Ruby Regexp object" do
|
462
|
+
expect(ruby_regexp.options).to eq(::Regexp::IGNORECASE | ::Regexp::MULTILINE | ::Regexp::EXTENDED)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context "when a Regexp::Raw object is roundtripped" do
|
469
|
+
|
470
|
+
let(:obj) { Regexp::Raw.new(pattern, options) }
|
471
|
+
let(:serialized) { obj.to_bson.to_s }
|
472
|
+
let(:roundtripped) { Regexp.from_bson(BSON::ByteBuffer.new(serialized)) }
|
473
|
+
|
474
|
+
it "roundtrips the pattern" do
|
475
|
+
expect(roundtripped.pattern).to eq(pattern)
|
476
|
+
end
|
477
|
+
|
478
|
+
context "when there are no options" do
|
479
|
+
|
480
|
+
let(:options) { '' }
|
481
|
+
|
482
|
+
it "does not set any options on the roundtripped Regexp::Raw object" do
|
483
|
+
expect(roundtripped.options).to eq(options)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "when there are options set" do
|
488
|
+
|
489
|
+
context "when there is the i ignorecase option" do
|
490
|
+
|
491
|
+
let(:options) { 'i' }
|
492
|
+
|
493
|
+
it "sets the i option on the roundtripped Regexp::Raw object" do
|
494
|
+
expect(roundtripped.options).to eq(options)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
context "when there is the l locale dependent option" do
|
499
|
+
|
500
|
+
let(:options) { 'l' }
|
501
|
+
|
502
|
+
it "sets the l option on the roundtripped Regexp::Raw object" do
|
503
|
+
expect(roundtripped.options).to eq(options)
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
context "when there is the m multiline option" do
|
508
|
+
|
509
|
+
let(:options) { 'm' }
|
510
|
+
|
511
|
+
it "sets the m option on the roundtripped Regexp::Raw object" do
|
512
|
+
expect(roundtripped.options).to eq(options)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
context "when there is the s dotall option" do
|
517
|
+
|
518
|
+
let(:options) { 's' }
|
519
|
+
|
520
|
+
it "sets the s option on the roundtripped Regexp::Raw object" do
|
521
|
+
expect(roundtripped.options).to eq(options)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
context "when there is the u match unicode option" do
|
526
|
+
|
527
|
+
let(:options) { 'u' }
|
528
|
+
|
529
|
+
it "sets the u option on the roundtripped Regexp::Raw object" do
|
530
|
+
expect(roundtripped.options).to eq(options)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
context "when there is the x verbose option" do
|
535
|
+
|
536
|
+
let(:options) { 'x' }
|
537
|
+
|
538
|
+
it "sets the x option on the roundtripped Regexp::Raw object" do
|
539
|
+
expect(roundtripped.options).to eq(options)
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
context "when all options are set" do
|
544
|
+
|
545
|
+
let(:options) { 'ilmsux' }
|
546
|
+
|
547
|
+
it "sets all the options on the roundtripped Regexp::Raw object" do
|
548
|
+
expect(roundtripped.options).to eq(options)
|
549
|
+
end
|
550
|
+
|
551
|
+
context "when the options are passed in not in alphabetical order" do
|
552
|
+
|
553
|
+
let(:options) { 'sumlxi' }
|
554
|
+
|
555
|
+
it "sets all the options on the roundtripped Regexp::Raw object in order" do
|
556
|
+
expect(roundtripped.options).to eq(options.chars.sort.join)
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|