From c37ac198fccdd896deefca469f800adf3341d1c3 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 22 Apr 2014 02:27:17 +0000 Subject: test_io.rb: test with holes * test/ruby/test_io.rb (test_seek, test_seek_symwhence): add tests of SEEK_DATA and SEEK_HOLE with holes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index b375754878..5f62fe11bc 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1696,12 +1696,22 @@ class TestIO < Test::Unit::TestCase f.seek(0, IO::SEEK_DATA) assert_equal("foo\nbar\nbaz\n", f.read) } + open(t.path, 'r+') { |f| + pos = f.pos + f.seek(100*1024, IO::SEEK_SET) + f.print("zot\n") + f.seek(50*1024, IO::SEEK_DATA) + assert_operator(f.pos, :>=, 50*1024) + assert_match(/\A\0*zot\n\z/, f.read) + } end if defined?(IO::SEEK_HOLE) open(t.path) { |f| assert_equal("foo\n", f.gets) f.seek(0, IO::SEEK_HOLE) + assert_operator(f.pos, :>, 20) + f.seek(100*1024, IO::SEEK_HOLE) assert_equal("", f.read) } end @@ -1732,12 +1742,22 @@ class TestIO < Test::Unit::TestCase f.seek(0, :DATA) assert_equal("foo\nbar\nbaz\n", f.read) } + open(t.path, 'r+') { |f| + pos = f.pos + f.seek(100*1024, :SET) + f.print("zot\n") + f.seek(50*1024, :DATA) + assert_operator(f.pos, :>=, 50*1024) + assert_match(/\A\0*zot\n\z/, f.read) + } end if defined?(IO::SEEK_HOLE) open(t.path) { |f| assert_equal("foo\n", f.gets) f.seek(0, :HOLE) + assert_operator(f.pos, :>, 20) + f.seek(100*1024, :HOLE) assert_equal("", f.read) } end -- cgit v1.2.3