animehunter-mongo 0.9

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 (79) hide show
  1. data/README.rdoc +311 -0
  2. data/Rakefile +62 -0
  3. data/bin/bson_benchmark.rb +59 -0
  4. data/bin/mongo_console +21 -0
  5. data/bin/run_test_script +19 -0
  6. data/bin/standard_benchmark +109 -0
  7. data/examples/admin.rb +41 -0
  8. data/examples/benchmarks.rb +42 -0
  9. data/examples/blog.rb +76 -0
  10. data/examples/capped.rb +23 -0
  11. data/examples/cursor.rb +47 -0
  12. data/examples/gridfs.rb +87 -0
  13. data/examples/index_test.rb +125 -0
  14. data/examples/info.rb +30 -0
  15. data/examples/queries.rb +69 -0
  16. data/examples/simple.rb +23 -0
  17. data/examples/strict.rb +34 -0
  18. data/examples/types.rb +40 -0
  19. data/lib/mongo.rb +19 -0
  20. data/lib/mongo/admin.rb +87 -0
  21. data/lib/mongo/collection.rb +235 -0
  22. data/lib/mongo/cursor.rb +227 -0
  23. data/lib/mongo/db.rb +538 -0
  24. data/lib/mongo/gridfs.rb +16 -0
  25. data/lib/mongo/gridfs/chunk.rb +96 -0
  26. data/lib/mongo/gridfs/grid_store.rb +468 -0
  27. data/lib/mongo/message.rb +20 -0
  28. data/lib/mongo/message/get_more_message.rb +37 -0
  29. data/lib/mongo/message/insert_message.rb +35 -0
  30. data/lib/mongo/message/kill_cursors_message.rb +36 -0
  31. data/lib/mongo/message/message.rb +84 -0
  32. data/lib/mongo/message/message_header.rb +50 -0
  33. data/lib/mongo/message/msg_message.rb +33 -0
  34. data/lib/mongo/message/opcodes.rb +32 -0
  35. data/lib/mongo/message/query_message.rb +77 -0
  36. data/lib/mongo/message/remove_message.rb +36 -0
  37. data/lib/mongo/message/update_message.rb +37 -0
  38. data/lib/mongo/mongo.rb +164 -0
  39. data/lib/mongo/query.rb +119 -0
  40. data/lib/mongo/types/binary.rb +42 -0
  41. data/lib/mongo/types/code.rb +34 -0
  42. data/lib/mongo/types/dbref.rb +37 -0
  43. data/lib/mongo/types/objectid.rb +137 -0
  44. data/lib/mongo/types/regexp_of_holding.rb +44 -0
  45. data/lib/mongo/types/undefined.rb +31 -0
  46. data/lib/mongo/util/bson.rb +534 -0
  47. data/lib/mongo/util/byte_buffer.rb +167 -0
  48. data/lib/mongo/util/ordered_hash.rb +96 -0
  49. data/lib/mongo/util/xml_to_ruby.rb +107 -0
  50. data/mongo-ruby-driver.gemspec +99 -0
  51. data/tests/mongo-qa/_common.rb +8 -0
  52. data/tests/mongo-qa/admin +26 -0
  53. data/tests/mongo-qa/capped +22 -0
  54. data/tests/mongo-qa/count1 +18 -0
  55. data/tests/mongo-qa/dbs +22 -0
  56. data/tests/mongo-qa/find +10 -0
  57. data/tests/mongo-qa/find1 +15 -0
  58. data/tests/mongo-qa/gridfs_in +16 -0
  59. data/tests/mongo-qa/gridfs_out +17 -0
  60. data/tests/mongo-qa/indices +49 -0
  61. data/tests/mongo-qa/remove +25 -0
  62. data/tests/mongo-qa/stress1 +35 -0
  63. data/tests/mongo-qa/test1 +11 -0
  64. data/tests/mongo-qa/update +18 -0
  65. data/tests/test_admin.rb +69 -0
  66. data/tests/test_bson.rb +246 -0
  67. data/tests/test_byte_buffer.rb +69 -0
  68. data/tests/test_chunk.rb +84 -0
  69. data/tests/test_cursor.rb +121 -0
  70. data/tests/test_db.rb +160 -0
  71. data/tests/test_db_api.rb +701 -0
  72. data/tests/test_db_connection.rb +18 -0
  73. data/tests/test_grid_store.rb +284 -0
  74. data/tests/test_message.rb +35 -0
  75. data/tests/test_mongo.rb +78 -0
  76. data/tests/test_objectid.rb +98 -0
  77. data/tests/test_ordered_hash.rb +129 -0
  78. data/tests/test_round_trip.rb +116 -0
  79. metadata +133 -0
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ # NOTE: assumes Mongo is running
6
+ class DBConnectionTest < Test::Unit::TestCase
7
+
8
+ include XGen::Mongo::Driver
9
+
10
+ def test_no_exceptions
11
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
+ db = Mongo.new(host, port).db('ruby-mongo-demo')
14
+ coll = db.collection('test')
15
+ coll.clear
16
+ db.error
17
+ end
18
+ end
@@ -0,0 +1,284 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'test/unit'
3
+ require 'mongo'
4
+ require 'mongo/gridfs'
5
+
6
+ class GridStoreTest < Test::Unit::TestCase
7
+
8
+ include XGen::Mongo::Driver
9
+ include XGen::Mongo::GridFS
10
+
11
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
12
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
13
+ @@files = @@db.collection('fs.files')
14
+ @@chunks = @@db.collection('fs.chunks')
15
+
16
+ def setup
17
+ @@chunks.clear
18
+ @@files.clear
19
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write("hello, world!") }
20
+ end
21
+
22
+ def teardown
23
+ @@chunks.clear
24
+ @@files.clear
25
+ @@db.error
26
+ end
27
+
28
+ def test_exist
29
+ assert GridStore.exist?(@@db, 'foobar')
30
+ assert !GridStore.exist?(@@db, 'does_not_exist')
31
+ assert !GridStore.exist?(@@db, 'foobar', 'another_root')
32
+ end
33
+
34
+ def test_list
35
+ assert_equal ['foobar'], GridStore.list(@@db)
36
+ assert_equal ['foobar'], GridStore.list(@@db, 'fs')
37
+ assert_equal [], GridStore.list(@@db, 'my_fs')
38
+
39
+ GridStore.open(@@db, 'test', 'w') { |f| f.write("my file") }
40
+
41
+ assert_equal ['foobar', 'test'], GridStore.list(@@db)
42
+ end
43
+
44
+ def test_small_write
45
+ rows = @@files.find({'filename' => 'foobar'}).to_a
46
+ assert_not_nil rows
47
+ assert_equal 1, rows.length
48
+ row = rows[0]
49
+ assert_not_nil row
50
+
51
+ file_id = row['_id']
52
+ assert_kind_of ObjectID, file_id
53
+ rows = @@chunks.find({'files_id' => file_id}).to_a
54
+ assert_not_nil rows
55
+ assert_equal 1, rows.length
56
+ end
57
+
58
+ def test_small_file
59
+ rows = @@files.find({'filename' => 'foobar'}).to_a
60
+ assert_not_nil rows
61
+ assert_equal 1, rows.length
62
+ row = rows[0]
63
+ assert_not_nil row
64
+ assert_equal "hello, world!", GridStore.read(@@db, 'foobar')
65
+ end
66
+
67
+ def test_overwrite
68
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write("overwrite") }
69
+ assert_equal "overwrite", GridStore.read(@@db, 'foobar')
70
+ end
71
+
72
+ def test_read_length
73
+ assert_equal "hello", GridStore.read(@@db, 'foobar', 5)
74
+ end
75
+
76
+ # Also tests seek
77
+ def test_read_with_offset
78
+ assert_equal "world", GridStore.read(@@db, 'foobar', 5, 7)
79
+ assert_equal "world!", GridStore.read(@@db, 'foobar', nil, 7)
80
+ end
81
+
82
+ def test_seek
83
+ GridStore.open(@@db, 'foobar', 'r') { |f|
84
+ f.seek(0)
85
+ assert_equal 'h', f.getc.chr
86
+ f.seek(7)
87
+ assert_equal 'w', f.getc.chr
88
+ f.seek(4)
89
+ assert_equal 'o', f.getc.chr
90
+
91
+ f.seek(-1, IO::SEEK_END)
92
+ assert_equal '!', f.getc.chr
93
+ f.seek(-6, IO::SEEK_END)
94
+ assert_equal 'w', f.getc.chr
95
+
96
+ f.seek(0)
97
+ f.seek(7, IO::SEEK_CUR)
98
+ assert_equal 'w', f.getc.chr
99
+ f.seek(-1, IO::SEEK_CUR)
100
+ assert_equal 'w', f.getc.chr
101
+ f.seek(-4, IO::SEEK_CUR)
102
+ assert_equal 'o', f.getc.chr
103
+ f.seek(3, IO::SEEK_CUR)
104
+ assert_equal 'o', f.getc.chr
105
+ }
106
+ end
107
+
108
+ def test_multi_chunk
109
+ @@chunks.clear
110
+ @@files.clear
111
+
112
+ size = 512
113
+ GridStore.open(@@db, 'biggie', 'w') { |f|
114
+ f.chunk_size = size
115
+ f.write('x' * size)
116
+ f.write('y' * size)
117
+ f.write('z' * size)
118
+ }
119
+
120
+ assert_equal 3, @@chunks.count
121
+ assert_equal ('x' * size) + ('y' * size) + ('z' * size), GridStore.read(@@db, 'biggie')
122
+ end
123
+
124
+ def test_puts_and_readlines
125
+ GridStore.open(@@db, 'multiline', 'w') { |f|
126
+ f.puts "line one"
127
+ f.puts "line two\n"
128
+ f.puts "line three"
129
+ }
130
+
131
+ lines = GridStore.readlines(@@db, 'multiline')
132
+ assert_equal ["line one\n", "line two\n", "line three\n"], lines
133
+ end
134
+
135
+ def test_unlink
136
+ assert_equal 1, @@files.count
137
+ assert_equal 1, @@chunks.count
138
+ GridStore.unlink(@@db, 'foobar')
139
+ assert_equal 0, @@files.count
140
+ assert_equal 0, @@chunks.count
141
+ end
142
+
143
+ def test_append
144
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") }
145
+ assert_equal 1, @@chunks.count
146
+ assert_equal "hello, world! how are you?", GridStore.read(@@db, 'foobar')
147
+ end
148
+
149
+ def test_rewind_and_truncate_on_write
150
+ GridStore.open(@@db, 'foobar', 'w') { |f|
151
+ f.write("some text is inserted here")
152
+ f.rewind
153
+ f.write("abc")
154
+ }
155
+ assert_equal "abc", GridStore.read(@@db, 'foobar')
156
+ end
157
+
158
+ def test_tell
159
+ GridStore.open(@@db, 'foobar', 'r') { |f|
160
+ f.read(5)
161
+ assert_equal 5, f.tell
162
+ }
163
+ end
164
+
165
+ def test_empty_block_ok
166
+ GridStore.open(@@db, 'empty', 'w')
167
+ end
168
+
169
+ def test_save_empty_file
170
+ @@chunks.clear
171
+ @@files.clear
172
+ GridStore.open(@@db, 'empty', 'w') {} # re-write with zero bytes
173
+ assert_equal 1, @@files.count
174
+ assert_equal 0, @@chunks.count
175
+ end
176
+
177
+ def test_empty_file_eof
178
+ GridStore.open(@@db, 'empty', 'w')
179
+ GridStore.open(@@db, 'empty', 'r') { |f|
180
+ assert f.eof?
181
+ }
182
+ end
183
+
184
+ def test_cannot_change_chunk_size_on_read
185
+ begin
186
+ GridStore.open(@@db, 'foobar', 'r') { |f| f.chunk_size = 42 }
187
+ fail "should have seen error"
188
+ rescue => ex
189
+ assert_match /error: can only change chunk size/, ex.to_s
190
+ end
191
+ end
192
+
193
+ def test_cannot_change_chunk_size_after_data_written
194
+ begin
195
+ GridStore.open(@@db, 'foobar', 'w') { |f|
196
+ f.write("some text")
197
+ f.chunk_size = 42
198
+ }
199
+ fail "should have seen error"
200
+ rescue => ex
201
+ assert_match /error: can only change chunk size/, ex.to_s
202
+ end
203
+ end
204
+
205
+ def test_change_chunk_size
206
+ GridStore.open(@@db, 'new-file', 'w') { |f|
207
+ f.chunk_size = 42
208
+ f.write("foo")
209
+ }
210
+ GridStore.open(@@db, 'new-file', 'r') { |f|
211
+ assert f.chunk_size == 42
212
+ }
213
+ end
214
+
215
+ def test_chunk_size_in_option
216
+ GridStore.open(@@db, 'new-file', 'w', :chunk_size => 42) { |f| f.write("foo") }
217
+ GridStore.open(@@db, 'new-file', 'r') { |f|
218
+ assert f.chunk_size == 42
219
+ }
220
+ end
221
+
222
+ def test_md5
223
+ GridStore.open(@@db, 'new-file', 'w') { |f| f.write("hello world\n")}
224
+ GridStore.open(@@db, 'new-file', 'r') { |f|
225
+ assert f.md5 == '6f5902ac237024bdd0c176cb93063dc4'
226
+ begin
227
+ f.md5 = 'cant do this'
228
+ fail "should have seen error"
229
+ rescue => ex
230
+ true
231
+ end
232
+ }
233
+ GridStore.open(@@db, 'new-file', 'w') {}
234
+ GridStore.open(@@db, 'new-file', 'r') { |f|
235
+ assert f.md5 == 'd41d8cd98f00b204e9800998ecf8427e'
236
+ }
237
+ end
238
+
239
+ def test_upload_date
240
+ now = Time.now
241
+ orig_file_upload_date = nil
242
+ GridStore.open(@@db, 'foobar', 'r') { |f| orig_file_upload_date = f.upload_date }
243
+ assert_not_nil orig_file_upload_date
244
+ assert (orig_file_upload_date - now) < 5 # even a really slow system < 5 secs
245
+
246
+ sleep(2)
247
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write "new data" }
248
+ file_upload_date = nil
249
+ GridStore.open(@@db, 'foobar', 'r') { |f| file_upload_date = f.upload_date }
250
+ assert_equal orig_file_upload_date, file_upload_date
251
+ end
252
+
253
+ def test_content_type
254
+ ct = nil
255
+ GridStore.open(@@db, 'foobar', 'r') { |f| ct = f.content_type }
256
+ assert_equal GridStore::DEFAULT_CONTENT_TYPE, ct
257
+
258
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.content_type = 'text/html' }
259
+ ct2 = nil
260
+ GridStore.open(@@db, 'foobar', 'r') { |f| ct2 = f.content_type }
261
+ assert_equal 'text/html', ct2
262
+ end
263
+
264
+ def test_content_type_option
265
+ GridStore.open(@@db, 'new-file', 'w', :content_type => 'image/jpg') { |f| f.write('foo') }
266
+ ct = nil
267
+ GridStore.open(@@db, 'new-file', 'r') { |f| ct = f.content_type }
268
+ assert_equal 'image/jpg', ct
269
+ end
270
+
271
+ def test_unknown_mode
272
+ GridStore.open(@@db, 'foobar', 'x')
273
+ fail 'should have seen "illegal mode" error raised'
274
+ rescue => ex
275
+ assert_equal "error: illegal mode x", ex.to_s
276
+ end
277
+
278
+ def test_metadata
279
+ GridStore.open(@@db, 'foobar', 'r') { |f| assert_nil f.metadata }
280
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.metadata = {'a' => 1} }
281
+ GridStore.open(@@db, 'foobar', 'r') { |f| assert_equal({'a' => 1}, f.metadata) }
282
+ end
283
+
284
+ end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ class MessageTest < Test::Unit::TestCase
6
+
7
+ include XGen::Mongo::Driver
8
+
9
+ def setup
10
+ @msg = Message.new(42)
11
+ end
12
+
13
+ def test_initial_info
14
+ assert_equal Message::HEADER_SIZE, @msg.buf.length
15
+ @msg.write_long(1029)
16
+ @msg.buf.rewind
17
+ assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
18
+ @msg.buf.get_int # skip message id
19
+ assert_equal 0, @msg.buf.get_int
20
+ assert_equal 42, @msg.buf.get_int
21
+ assert_equal 1029, @msg.buf.get_long
22
+ end
23
+
24
+ def test_update_length
25
+ @msg.update_message_length
26
+ @msg.buf.rewind
27
+ assert_equal Message::HEADER_SIZE, @msg.buf.get_int
28
+ end
29
+
30
+ def test_long_length
31
+ @msg.write_long(1027)
32
+ assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
33
+ end
34
+
35
+ end
@@ -0,0 +1,78 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ # NOTE: assumes Mongo is running
6
+ class MongoTest < Test::Unit::TestCase
7
+
8
+ include XGen::Mongo::Driver
9
+
10
+ def setup
11
+ @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
+ @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
+ @mongo = Mongo.new(@host, @port)
14
+ end
15
+
16
+ def teardown
17
+ @mongo.db('ruby-mongo-test').error
18
+ end
19
+
20
+ def test_database_info
21
+ @mongo.drop_database('ruby-mongo-info-test')
22
+ @mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
23
+
24
+ info = @mongo.database_info
25
+ assert_not_nil info
26
+ assert_kind_of Hash, info
27
+ assert_not_nil info['ruby-mongo-info-test']
28
+ assert info['ruby-mongo-info-test'] > 0
29
+
30
+ @mongo.drop_database('ruby-mongo-info-test')
31
+ end
32
+
33
+ def test_database_names
34
+ @mongo.drop_database('ruby-mongo-info-test')
35
+ @mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
36
+
37
+ names = @mongo.database_names
38
+ assert_not_nil names
39
+ assert_kind_of Array, names
40
+ assert names.length >= 1
41
+ assert names.include?('ruby-mongo-info-test')
42
+
43
+ @mongo.drop_database('ruby-mongo-info-test')
44
+ end
45
+
46
+ def test_drop_database
47
+ db = @mongo.db('ruby-mongo-will-be-deleted')
48
+ coll = db.collection('temp')
49
+ coll.clear
50
+ coll.insert(:name => 'temp')
51
+ assert_equal 1, coll.count()
52
+ assert @mongo.database_names.include?('ruby-mongo-will-be-deleted')
53
+
54
+ @mongo.drop_database('ruby-mongo-will-be-deleted')
55
+ assert !@mongo.database_names.include?('ruby-mongo-will-be-deleted')
56
+ end
57
+
58
+ def test_pair
59
+ db = Mongo.new({:left => ['foo', 123]})
60
+ pair = db.instance_variable_get('@pair')
61
+ assert_equal 2, pair.length
62
+ assert_equal ['foo', 123], pair[0]
63
+ assert_equal ['localhost', Mongo::DEFAULT_PORT], pair[1]
64
+
65
+ db = Mongo.new({:right => 'bar'})
66
+ pair = db.instance_variable_get('@pair')
67
+ assert_equal 2, pair.length
68
+ assert_equal ['localhost', Mongo::DEFAULT_PORT], pair[0]
69
+ assert_equal ['bar', Mongo::DEFAULT_PORT], pair[1]
70
+
71
+ db = Mongo.new({:right => ['foo', 123], :left => 'bar'})
72
+ pair = db.instance_variable_get('@pair')
73
+ assert_equal 2, pair.length
74
+ assert_equal ['bar', Mongo::DEFAULT_PORT], pair[0]
75
+ assert_equal ['foo', 123], pair[1]
76
+ end
77
+
78
+ end
@@ -0,0 +1,98 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ class ObjectIDTest < Test::Unit::TestCase
6
+
7
+ include XGen::Mongo::Driver
8
+
9
+ def setup
10
+ @t = 42
11
+ @o = ObjectID.new(nil, @t)
12
+ end
13
+
14
+ def test_index_for_time
15
+ t = 99
16
+ assert_equal 0, @o.index_for_time(t)
17
+ assert_equal 1, @o.index_for_time(t)
18
+ assert_equal 2, @o.index_for_time(t)
19
+ t = 100
20
+ assert_equal 0, @o.index_for_time(t)
21
+ end
22
+
23
+ def test_time_bytes
24
+ a = @o.to_a
25
+ assert_equal @t, a[0]
26
+ 3.times { |i| assert_equal 0, a[i+1] }
27
+
28
+ t = 43
29
+ o = ObjectID.new(nil, t)
30
+ a = o.to_a
31
+ assert_equal t, a[0]
32
+ 3.times { |i| assert_equal 0, a[i+1] }
33
+ assert_equal 1, o.index_for_time(t) # 0 was used for o
34
+ end
35
+
36
+ def test_different
37
+ o2 = ObjectID.new(nil, @t)
38
+ assert @o.to_a != o2.to_a
39
+ end
40
+
41
+ def test_eql?
42
+ o2 = ObjectID.new(@o.to_a)
43
+ assert @o.eql?(o2)
44
+ assert @o == o2
45
+ end
46
+
47
+ def test_to_s
48
+ s = @o.to_s
49
+ assert_equal 24, s.length
50
+ s =~ /^([0-9a-f]+)$/
51
+ assert_equal 24, $1.length
52
+ end
53
+
54
+ def test_save_and_restore
55
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
56
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
57
+ db = Mongo.new(host, port).db('ruby-mongo-test')
58
+ coll = db.collection('test')
59
+
60
+ coll.clear
61
+ coll << {'a' => 1, '_id' => @o}
62
+
63
+ row = coll.find().collect.first
64
+ assert_equal 1, row['a']
65
+ assert_equal @o, row['_id']
66
+ end
67
+
68
+ def test_from_string
69
+ hex_str = @o.to_s
70
+ o2 = ObjectID.from_string(hex_str)
71
+ assert_equal hex_str, o2.to_s
72
+ assert_equal @o, o2
73
+ assert_equal @o.to_s, o2.to_s
74
+ end
75
+
76
+ def test_legal
77
+ assert !ObjectID.legal?(nil)
78
+ assert !ObjectID.legal?("fred")
79
+ assert !ObjectID.legal?("0000")
80
+ assert !ObjectID.legal?('000102030405060708090A0')
81
+ assert ObjectID.legal?('000102030405060708090A0B')
82
+ assert ObjectID.legal?('abcdefABCDEF123456789012')
83
+ assert !ObjectID.legal?('abcdefABCDEF12345678901x')
84
+ end
85
+
86
+ def test_from_string_leading_zeroes
87
+ hex_str = '000000000000000000abcdef'
88
+ o = ObjectID.from_string(hex_str)
89
+ assert_equal hex_str, o.to_s
90
+ end
91
+
92
+ def test_byte_order
93
+ hex_str = '000102030405060708090A0B'
94
+ o = ObjectID.from_string(hex_str)
95
+ assert_equal [0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0b, 0x0a, 0x09, 0x08], o.to_a
96
+ end
97
+
98
+ end