From 8a43d162722bf84a0e57f5864e4d3e0b14f48464 Mon Sep 17 00:00:00 2001 From: mame Date: Fri, 1 Aug 2008 12:50:17 +0000 Subject: [PATCH] * test/sdbm/test_sdbm.rb: add some tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/sdbm/test_sdbm.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ChangeLog b/ChangeLog index b7e62ab2e9..5f89d2ae00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Aug 1 21:49:41 2008 Yusuke Endoh + + * test/sdbm/test_sdbm.rb: add some tests. + Fri Aug 1 21:36:00 2008 Yusuke Endoh * gc.c (allocate_heaps, assign_heap_slot, rb_newobj_from_heap): diff --git a/test/sdbm/test_sdbm.rb b/test/sdbm/test_sdbm.rb index 0badf7c4b7..0c6df66fb2 100644 --- a/test/sdbm/test_sdbm.rb +++ b/test/sdbm/test_sdbm.rb @@ -525,5 +525,39 @@ class TestSDBM < Test::Unit::TestCase assert_equal(key.to_i, val.to_i) } end + + def test_closed + assert_equal(false, @sdbm.closed?) + @sdbm.close + assert_equal(true, @sdbm.closed?) + @sdbm = SDBM.new(@path) + end + + def test_index + assert_equal(nil, @sdbm.index("foo")) + @sdbm["bar"] = "foo" + assert_equal("bar", @sdbm.index("foo")) + end + + def test_readonly + @sdbm["bar"] = "baz" + @sdbm.close + File.chmod(0444, @path + ".dir") + File.chmod(0444, @path + ".pag") + @sdbm = SDBM.new(@path) + assert_raise(SDBMError) { @sdbm["bar"] = "foo" } + assert_raise(SDBMError) { @sdbm.delete("bar") } + assert_raise(SDBMError) { @sdbm.delete_if { true } } + assert_raise(SDBMError) { @sdbm.clear } + assert_nil(@sdbm.store("bar", nil)) + end + + def test_update2 + obj = Object.new + def obj.each_pair + yield [] + end + assert_raise(ArgumentError) { @sdbm.update(obj) } + end end