about summary refs log tree commit homepage
path: root/test/test_tdb.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_tdb.rb')
-rw-r--r--test/test_tdb.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/test_tdb.rb b/test/test_tdb.rb
index d7a6a8a..7e77f14 100644
--- a/test/test_tdb.rb
+++ b/test/test_tdb.rb
@@ -275,6 +275,50 @@ class TestTdb < Test::Unit::TestCase
     assert ! @tdb.include?("hello")
   end
 
+  def test_fetch_reuse_buf
+    assert_nothing_raised do
+      @tmp = Tempfile.new('tdb')
+      File.unlink(@tmp.path)
+    end
+    @tdb = TDB.new(@tmp.path)
+    @tdb["HELLO"] = "WORLD"
+    rbuf = "HI"
+    rv = @tdb.fetch("HELLO", rbuf)
+    assert_equal rbuf.object_id, rv.object_id
+
+    assert_equal "WORLD", rbuf
+    assert_nil @tdb.fetch("HELLO!", rbuf)
+    assert_equal "", rbuf
+
+    @tdb["HELLO"] = "WORLD" * 100
+    rv = @tdb.fetch("HELLO", rbuf)
+    assert_equal rbuf.object_id, rv.object_id
+    assert_equal "WORLD" * 100, rbuf
+  end
+
+  def test_delete_reuse_buf
+    assert_nothing_raised do
+      @tmp = Tempfile.new('tdb')
+      File.unlink(@tmp.path)
+    end
+    @tdb = TDB.new(@tmp.path)
+    @tdb["HELLO"] = "WORLD"
+    rbuf = "HI"
+    rv = @tdb.delete("HELLO", rbuf)
+    assert_equal rbuf.object_id, rv.object_id
+    assert_equal "WORLD", rbuf
+    assert ! @tdb.include?("HELLO")
+
+    assert_nil @tdb.delete("HELLO!", rbuf)
+    assert_equal "", rbuf
+
+    @tdb["HELLO"] = "WORLD" * 100
+    rv = @tdb.delete("HELLO", rbuf)
+    assert_equal rbuf.object_id, rv.object_id
+    assert_equal "WORLD" * 100, rbuf
+    assert ! @tdb.include?("HELLO")
+  end
+
   def test_repack_file
     assert_nothing_raised do
       @tmp = Tempfile.new('tdb')