about summary refs log tree commit homepage
path: root/test/test_raindrops.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_raindrops.rb')
-rw-r--r--test/test_raindrops.rb45
1 files changed, 44 insertions, 1 deletions
diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb
index 67089b7..165766e 100644
--- a/test/test_raindrops.rb
+++ b/test/test_raindrops.rb
@@ -1,6 +1,8 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require 'test/unit'
 require 'raindrops'
+require 'tempfile'
 
 class TestRaindrops < Test::Unit::TestCase
 
@@ -134,7 +136,7 @@ class TestRaindrops < Test::Unit::TestCase
     assert_equal 0, rd[rd.capa - 1]
     assert_equal 1, rd.incr(rd.capa - 1)
     assert_raises(ArgumentError) { rd[rd.capa] }
-    rescue RangeError
+  rescue RangeError
   end # if RUBY_PLATFORM =~ /linux/
 
   def test_evaporate
@@ -162,4 +164,45 @@ class TestRaindrops < Test::Unit::TestCase
     assert status.success?
     assert_equal [ 1, 2 ], tmp.to_ary
   end
+
+  def test_io_backed
+    file = Tempfile.new('test_io_backed')
+    rd = Raindrops.new(4, io: file, zero: true)
+    rd[0] = 123
+    rd[1] = 456
+
+    assert_equal 123, rd[0]
+    assert_equal 456, rd[1]
+
+    rd.evaporate!
+
+    file.rewind
+    data = file.read
+    assert_equal 123, data.unpack('L!')[0]
+    assert_equal 456, data[Raindrops::SIZE..data.size].unpack('L!')[0]
+  end
+
+  def test_io_backed_reuse
+    file = Tempfile.new('test_io_backed')
+    rd = Raindrops.new(4, io: file, zero: true)
+    rd[0] = 123
+    rd[1] = 456
+    rd.evaporate!
+
+    rd = Raindrops.new(4, io: file, zero: false)
+    assert_equal 123, rd[0]
+    assert_equal 456, rd[1]
+  end
+
+  def test_iobacked_noreuse
+    file = Tempfile.new('test_io_backed')
+    rd = Raindrops.new(4, io: file, zero: true)
+    rd[0] = 123
+    rd[1] = 456
+    rd.evaporate!
+
+    rd = Raindrops.new(4, io: file, zero: true)
+    assert_equal 0, rd[0]
+    assert_equal 0, rd[1]
+  end
 end