summaryrefslogtreecommitdiff
path: root/ext/dbm/testdbm.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dbm/testdbm.rb')
-rw-r--r--ext/dbm/testdbm.rb28
1 files changed, 24 insertions, 4 deletions
diff --git a/ext/dbm/testdbm.rb b/ext/dbm/testdbm.rb
index c6b26e0cdf2..0be627d346e 100644
--- a/ext/dbm/testdbm.rb
+++ b/ext/dbm/testdbm.rb
@@ -165,7 +165,7 @@ class TestDBM < RUNIT::TestCase
assert_nil(dbm.close)
# closed DBM file
- assert_exception(RuntimeError) { dbm.close }
+ assert_exception(DBMError) { dbm.close }
end
def test_aref
@@ -245,6 +245,25 @@ class TestDBM < RUNIT::TestCase
assert_equals(values.reverse, @dbm.indexes(*keys.reverse))
end
+ def test_select
+ keys = %w(foo bar baz)
+ values = %w(FOO BAR BAZ)
+ @dbm[keys[0]], @dbm[keys[1]], @dbm[keys[2]] = values
+ assert_equals(values.reverse, @dbm.select(*keys.reverse))
+ end
+
+ def test_select_with_block
+ keys = %w(foo bar baz)
+ values = %w(FOO BAR BAZ)
+ @dbm[keys[0]], @dbm[keys[1]], @dbm[keys[2]] = values
+ ret = @dbm.select {|k,v|
+ assert_equals(k.upcase, v)
+ k != "bar"
+ }
+ assert_equals([['baz', 'BAZ'], ['foo', 'FOO']],
+ ret.sort)
+ end
+
def test_length
num = 10
assert_equals(0, @dbm.size)
@@ -377,7 +396,7 @@ class TestDBM < RUNIT::TestCase
@dbm[keys[0]], @dbm[keys[1]], @dbm[keys[2]] = values
- assert_equals(@dbm, @dbm.delete(key))
+ assert_equals('BAR', @dbm.delete(key))
assert_nil(@dbm[key])
assert_equals(2, @dbm.size)
@@ -394,12 +413,13 @@ class TestDBM < RUNIT::TestCase
def test_delete_with_block
key = 'no called block'
@dbm[key] = 'foo'
- assert_equals(@dbm, @dbm.delete(key) {|k| k.replace 'called block'})
+ assert_equals('foo', @dbm.delete(key) {|k| k.replace 'called block'})
assert_equals('no called block', key)
assert_equals(0, @dbm.size)
key = 'no called block'
- assert_nil(@dbm.delete(key) {|k| k.replace 'called block'})
+ assert_equals(:blockval,
+ @dbm.delete(key) {|k| k.replace 'called block'; :blockval})
assert_equals('called block', key)
assert_equals(0, @dbm.size)
end