bson 1.12.5-java → 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bson might be problematic. Click here for more details.

Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +80 -0
  5. data/CONTRIBUTING.md +42 -0
  6. data/NOTICE +2 -0
  7. data/README.md +190 -0
  8. data/Rakefile +109 -0
  9. data/lib/bson-ruby.jar +0 -0
  10. data/lib/bson.rb +60 -87
  11. data/lib/bson/array.rb +104 -0
  12. data/lib/bson/binary.rb +193 -0
  13. data/lib/bson/boolean.rb +48 -0
  14. data/lib/bson/code.rb +109 -0
  15. data/lib/bson/code_with_scope.rb +120 -0
  16. data/lib/bson/document.rb +549 -0
  17. data/lib/bson/encodable.rb +86 -0
  18. data/lib/bson/environment.rb +98 -0
  19. data/lib/bson/false_class.rb +61 -0
  20. data/lib/bson/float.rb +82 -0
  21. data/lib/bson/hash.rb +84 -0
  22. data/lib/bson/int32.rb +59 -0
  23. data/lib/bson/int64.rb +59 -0
  24. data/lib/bson/integer.rb +185 -0
  25. data/lib/bson/json.rb +37 -0
  26. data/lib/bson/max_key.rb +70 -0
  27. data/lib/bson/min_key.rb +70 -0
  28. data/lib/bson/nil_class.rb +70 -0
  29. data/lib/bson/object_id.rb +395 -0
  30. data/lib/bson/regexp.rb +124 -0
  31. data/lib/bson/registry.rb +70 -0
  32. data/lib/bson/specialized.rb +74 -0
  33. data/lib/bson/string.rb +203 -0
  34. data/lib/bson/symbol.rb +87 -0
  35. data/lib/bson/time.rb +72 -0
  36. data/lib/bson/timestamp.rb +113 -0
  37. data/lib/bson/true_class.rb +61 -0
  38. data/lib/bson/undefined.rb +74 -0
  39. data/lib/bson/version.rb +17 -0
  40. data/spec/bson/array_spec.rb +58 -0
  41. data/spec/bson/binary_spec.rb +115 -0
  42. data/spec/bson/boolean_spec.rb +48 -0
  43. data/spec/bson/code_spec.rb +42 -0
  44. data/spec/bson/code_with_scope_spec.rb +74 -0
  45. data/spec/bson/document_spec.rb +778 -0
  46. data/spec/bson/false_class_spec.rb +28 -0
  47. data/spec/bson/float_spec.rb +29 -0
  48. data/spec/bson/hash_spec.rb +56 -0
  49. data/spec/bson/int32_spec.rb +28 -0
  50. data/spec/bson/int64_spec.rb +28 -0
  51. data/spec/bson/integer_spec.rb +76 -0
  52. data/spec/bson/json_spec.rb +53 -0
  53. data/spec/bson/max_key_spec.rb +75 -0
  54. data/spec/bson/min_key_spec.rb +75 -0
  55. data/spec/bson/nil_class_spec.rb +29 -0
  56. data/spec/bson/object_id_spec.rb +527 -0
  57. data/spec/bson/regexp_spec.rb +89 -0
  58. data/spec/bson/registry_spec.rb +55 -0
  59. data/spec/bson/string_spec.rb +298 -0
  60. data/spec/bson/symbol_spec.rb +55 -0
  61. data/spec/bson/time_spec.rb +43 -0
  62. data/spec/bson/timestamp_spec.rb +74 -0
  63. data/spec/bson/true_class_spec.rb +28 -0
  64. data/spec/bson/undefined_spec.rb +29 -0
  65. data/{lib/bson/types/dbref.rb → spec/bson_spec.rb} +22 -16
  66. data/spec/spec_helper.rb +32 -0
  67. data/spec/support/shared_examples.rb +95 -0
  68. metadata +116 -48
  69. metadata.gz.sig +1 -1
  70. data/VERSION +0 -1
  71. data/bin/b2json +0 -63
  72. data/bin/j2bson +0 -64
  73. data/bson.gemspec +0 -34
  74. data/ext/jbson/lib/java-bson.jar +0 -0
  75. data/ext/jbson/target/jbson.jar +0 -0
  76. data/lib/bson/bson_c.rb +0 -37
  77. data/lib/bson/bson_java.rb +0 -49
  78. data/lib/bson/bson_ruby.rb +0 -645
  79. data/lib/bson/byte_buffer.rb +0 -241
  80. data/lib/bson/exceptions.rb +0 -37
  81. data/lib/bson/grow.rb +0 -173
  82. data/lib/bson/ordered_hash.rb +0 -197
  83. data/lib/bson/support/hash_with_indifferent_access.rb +0 -174
  84. data/lib/bson/types/binary.rb +0 -52
  85. data/lib/bson/types/code.rb +0 -55
  86. data/lib/bson/types/min_max_keys.rb +0 -56
  87. data/lib/bson/types/object_id.rb +0 -226
  88. data/lib/bson/types/regex.rb +0 -116
  89. data/lib/bson/types/timestamp.rb +0 -72
@@ -0,0 +1,89 @@
1
+ # Copyright (C) 2009-2013 MongoDB Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "spec_helper"
16
+
17
+ describe Regexp do
18
+
19
+ describe "#as_json" do
20
+
21
+ let(:object) do
22
+ /\W+/i
23
+ end
24
+
25
+ it "returns the binary data plus type" do
26
+ expect(object.as_json).to eq(
27
+ { "$regex" => "\\W+", "$options" => "i" }
28
+ )
29
+ end
30
+
31
+ it_behaves_like "a JSON serializable object"
32
+ end
33
+
34
+ describe "#to_bson/#from_bson" do
35
+
36
+ let(:type) { 11.chr }
37
+ let(:obj) { /test/ }
38
+
39
+ it_behaves_like "a bson element"
40
+
41
+ context "when the regexp has no options" do
42
+
43
+ let(:obj) { /\d+/ }
44
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}" }
45
+
46
+ it_behaves_like "a serializable bson element"
47
+ it_behaves_like "a deserializable bson element"
48
+ end
49
+
50
+ context "when the regexp has options" do
51
+
52
+ context "when ignoring case" do
53
+
54
+ let(:obj) { /\W+/i }
55
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}i#{BSON::NULL_BYTE}" }
56
+
57
+ it_behaves_like "a serializable bson element"
58
+ it_behaves_like "a deserializable bson element"
59
+ end
60
+
61
+ context "when matching multiline" do
62
+
63
+ let(:obj) { /\W+/m }
64
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}ms#{BSON::NULL_BYTE}" }
65
+
66
+ it_behaves_like "a serializable bson element"
67
+ it_behaves_like "a deserializable bson element"
68
+ end
69
+
70
+ context "when matching extended" do
71
+
72
+ let(:obj) { /\W+/x }
73
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}x#{BSON::NULL_BYTE}" }
74
+
75
+ it_behaves_like "a serializable bson element"
76
+ it_behaves_like "a deserializable bson element"
77
+ end
78
+
79
+ context "when all options are present" do
80
+
81
+ let(:obj) { /\W+/xim }
82
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}imsx#{BSON::NULL_BYTE}" }
83
+
84
+ it_behaves_like "a serializable bson element"
85
+ it_behaves_like "a deserializable bson element"
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2009-2013 MongoDB Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "spec_helper"
16
+
17
+ describe BSON::Registry do
18
+
19
+ describe ".get" do
20
+
21
+ context "when the type has a correspoding class" do
22
+
23
+ before do
24
+ described_class.register(BSON::MinKey::BSON_TYPE, BSON::MinKey)
25
+ end
26
+
27
+ let(:klass) do
28
+ described_class.get(BSON::MinKey::BSON_TYPE)
29
+ end
30
+
31
+ it "returns the class" do
32
+ expect(klass).to eq(BSON::MinKey)
33
+ end
34
+ end
35
+
36
+ context "when the type has no corresponding class" do
37
+
38
+ unless BSON::Environment.ruby_18?
39
+
40
+ it "raises an error" do
41
+ expect {
42
+ described_class.get("test")
43
+ }.to raise_error(KeyError)
44
+ end
45
+ else
46
+
47
+ it "raises an error" do
48
+ expect {
49
+ described_class.get("test")
50
+ }.to raise_error(IndexError)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,298 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (C) 2009-2013 MongoDB Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "spec_helper"
18
+
19
+ describe String do
20
+
21
+ describe "#to_bson/#from_bson" do
22
+
23
+ let(:type) { 2.chr }
24
+ let(:obj) { "test" }
25
+ let(:bson) { "#{5.to_bson}test#{BSON::NULL_BYTE}" }
26
+
27
+ it_behaves_like "a bson element"
28
+ it_behaves_like "a serializable bson element"
29
+ it_behaves_like "a deserializable bson element"
30
+ end
31
+
32
+ describe "#to_bson_cstring" do
33
+
34
+ context "when the string is valid" do
35
+
36
+ let(:string) do
37
+ "test"
38
+ end
39
+
40
+ let(:encoded) do
41
+ string.to_bson_cstring
42
+ end
43
+
44
+ let(:previous_content) do
45
+ 'previous_content'.force_encoding(BSON::BINARY)
46
+ end
47
+
48
+ it "returns the encoded string" do
49
+ expect(encoded).to eq("test#{BSON::NULL_BYTE}")
50
+ end
51
+
52
+ it_behaves_like "a binary encoded string"
53
+
54
+ it "appends to optional previous content" do
55
+ expect(string.to_bson_cstring(previous_content)).to eq(previous_content << encoded)
56
+ end
57
+ end
58
+
59
+ context "when the string contains a null byte" do
60
+
61
+ let(:string) do
62
+ "test#{BSON::NULL_BYTE}ing"
63
+ end
64
+
65
+ it "raises an error" do
66
+ expect {
67
+ string.to_bson_cstring
68
+ }.to raise_error(ArgumentError)
69
+ end
70
+ end
71
+
72
+ context "when the string contains utf-8 characters" do
73
+
74
+ let(:string) do
75
+ "Straße"
76
+ end
77
+
78
+ let(:encoded) do
79
+ string.to_bson_cstring
80
+ end
81
+
82
+ let(:char) do
83
+ "ß".chr.force_encoding(BSON::BINARY)
84
+ end
85
+
86
+ it "returns the encoded string" do
87
+ expect(encoded).to eq("Stra#{char}e#{BSON::NULL_BYTE}")
88
+ end
89
+
90
+ it_behaves_like "a binary encoded string"
91
+ end
92
+
93
+ context "when the string is encoded in non utf-8" do
94
+
95
+ let(:string) do
96
+ "Straße".encode("iso-8859-1")
97
+ end
98
+
99
+ let(:encoded) do
100
+ string.to_bson_cstring
101
+ end
102
+
103
+ let(:char) do
104
+ "ß".chr.force_encoding(BSON::BINARY)
105
+ end
106
+
107
+ it "returns the encoded string" do
108
+ expect(encoded).to eq("Stra#{char}e#{BSON::NULL_BYTE}")
109
+ end
110
+
111
+ it_behaves_like "a binary encoded string"
112
+ end
113
+
114
+ unless BSON::Environment.ruby_18?
115
+
116
+ context "when the string contains non utf-8 characters" do
117
+
118
+ let(:string) do
119
+ 255.chr
120
+ end
121
+
122
+ it "raises an error" do
123
+ expect {
124
+ string.to_bson_cstring
125
+ }.to raise_error(EncodingError)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "#to_bson_object_id" do
132
+
133
+ context "when the string has 12 characters" do
134
+
135
+ let(:string) do
136
+ "123456789012"
137
+ end
138
+
139
+ let(:converted) do
140
+ string.to_bson_object_id
141
+ end
142
+
143
+ it "returns the array as a string" do
144
+ expect(converted).to eq(string)
145
+ end
146
+ end
147
+
148
+ context "when the array does not have 12 elements" do
149
+
150
+ it "raises an exception" do
151
+ expect {
152
+ "test".to_bson_object_id
153
+ }.to raise_error(BSON::ObjectId::Invalid)
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "#to_bson_string" do
159
+
160
+ context "when the string is valid" do
161
+
162
+ let(:string) do
163
+ "test"
164
+ end
165
+
166
+ let(:encoded) do
167
+ string.to_bson_string
168
+ end
169
+
170
+ let(:previous_content) do
171
+ 'previous_content'.force_encoding(BSON::BINARY)
172
+ end
173
+
174
+ it "returns the string" do
175
+ expect(encoded).to eq(string)
176
+ end
177
+
178
+ it_behaves_like "a binary encoded string"
179
+
180
+ it "appends to optional previous content" do
181
+ expect(string.to_bson_string(previous_content)).to eq(previous_content << encoded)
182
+ end
183
+
184
+ end
185
+
186
+ context "when the string contains a null byte" do
187
+
188
+ let(:string) do
189
+ "test#{BSON::NULL_BYTE}ing"
190
+ end
191
+
192
+ let(:encoded) do
193
+ string.to_bson_string
194
+ end
195
+
196
+ it "retains the null byte" do
197
+ expect(encoded).to eq(string)
198
+ end
199
+
200
+ it_behaves_like "a binary encoded string"
201
+ end
202
+
203
+ context "when the string contains utf-8 characters" do
204
+
205
+ let(:string) do
206
+ "Straße"
207
+ end
208
+
209
+ let(:encoded) do
210
+ string.to_bson_string
211
+ end
212
+
213
+ let(:char) do
214
+ "ß".chr.force_encoding(BSON::BINARY)
215
+ end
216
+
217
+ it "returns the encoded string" do
218
+ expect(encoded).to eq("Stra#{char}e")
219
+ end
220
+
221
+ it_behaves_like "a binary encoded string"
222
+ end
223
+
224
+ context "when the string is encoded in non utf-8" do
225
+
226
+ let(:string) do
227
+ "Straße".encode("iso-8859-1")
228
+ end
229
+
230
+ let(:encoded) do
231
+ string.to_bson_string
232
+ end
233
+
234
+ let(:char) do
235
+ "ß".chr.force_encoding(BSON::BINARY)
236
+ end
237
+
238
+ it "returns the encoded string" do
239
+ expect(encoded).to eq("Stra#{char}e")
240
+ end
241
+
242
+ it_behaves_like "a binary encoded string"
243
+ end
244
+
245
+ unless BSON::Environment.ruby_18?
246
+
247
+ context "when the string contains non utf-8 characters" do
248
+
249
+ let(:string) do
250
+ 255.chr
251
+ end
252
+
253
+ it "raises an error" do
254
+ expect {
255
+ string.to_bson_string
256
+ }.to raise_error(EncodingError)
257
+ end
258
+ end
259
+ end
260
+ end
261
+
262
+ context "when the class is loaded" do
263
+
264
+ let(:registered) do
265
+ BSON::Registry.get(String::BSON_TYPE)
266
+ end
267
+
268
+ it "registers the type" do
269
+ expect(registered).to eq(String)
270
+ end
271
+ end
272
+
273
+ describe "#to_bson_key" do
274
+
275
+ let(:string) { "test" }
276
+ let(:encoded) { string.to_s + BSON::NULL_BYTE }
277
+ let(:previous_content) { 'previous_content'.force_encoding(BSON::BINARY) }
278
+
279
+ it "returns the encoded string" do
280
+ expect(string.to_bson_key).to eq(encoded)
281
+ end
282
+
283
+ it "appends to optional previous content" do
284
+ expect(string.to_bson_key(previous_content)).to eq(previous_content << encoded)
285
+ end
286
+ end
287
+
288
+ describe "#to_hex_string" do
289
+
290
+ let(:string) do
291
+ "testing123"
292
+ end
293
+
294
+ it "converts the string to hex" do
295
+ expect(string.to_hex_string).to eq("74657374696e67313233")
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2009-2013 MongoDB Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "spec_helper"
16
+
17
+ describe Symbol do
18
+
19
+ describe "#to_bson/#from_bson" do
20
+
21
+ let(:type) { 14.chr }
22
+ let(:obj) { :test }
23
+ let(:bson) { "#{5.to_bson}test#{BSON::NULL_BYTE}" }
24
+
25
+ it_behaves_like "a bson element"
26
+ it_behaves_like "a serializable bson element"
27
+ it_behaves_like "a deserializable bson element"
28
+
29
+ end
30
+
31
+ describe "#to_bson_key" do
32
+
33
+ let(:symbol) { :test }
34
+ let(:encoded) { symbol.to_s + BSON::NULL_BYTE }
35
+ let(:previous_content) { 'previous_content'.force_encoding(BSON::BINARY) }
36
+
37
+ it "returns the encoded string" do
38
+ expect(symbol.to_bson_key).to eq(encoded)
39
+ end
40
+
41
+ it "appends to optional previous content" do
42
+ expect(symbol.to_bson_key(previous_content)).to eq(previous_content << encoded)
43
+ end
44
+
45
+ context 'when the symbol contains a null byte' do
46
+ let(:symbol) { :"test#{BSON::NULL_BYTE}ing" }
47
+
48
+ it 'raises an error' do
49
+ expect {
50
+ symbol.to_bson_key
51
+ }.to raise_error(ArgumentError)
52
+ end
53
+ end
54
+ end
55
+ end