Skip to content
Browse files

Improve RangesIO test coverage.

* Test translation of ranges to start/len pairs and optional combining.
* Add test of rewind.
  • Loading branch information...
1 parent cb0de79 commit 975365ba8202bd4a52db2962892171297972efd6 @aquasync committed Jul 18, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 test/test_ranges_io.rb
View
10 test/test_ranges_io.rb
@@ -29,6 +29,14 @@ def test_open
assert_equal true, f.closed?
end
+ def test_combine
+ ranges = [[0, 100], 100...200, [200, 100]]
+ io = RangesIO.new STDOUT, 'r+', :ranges => ranges
+ assert_equal [[0, 300]], io.ranges
+ io = RangesIO.new STDOUT, 'r+', :ranges => ranges, :combine => false
+ assert_equal [[0, 100], [100, 100], [200, 100]], io.ranges
+ end
+
def test_basics
assert_equal 160, @io.size
assert_match %r{size=160}, @io.inspect
@@ -44,6 +52,8 @@ def test_seek
@io.seek(-10, IO::SEEK_CUR)
@io.pos += 20
assert_equal 70, @io.pos
+ @io.rewind
+ assert_equal 0, @io.pos
# seeking past the end doesn't throw an exception for normal
# files, even in read mode, but RangesIO does
assert_raises(Errno::EINVAL) { @io.seek 500 }

0 comments on commit 975365b

Please sign in to comment.
Something went wrong with that request. Please try again.