From f4af54f212907bd2ecd0be9d1e9a6237641b24b3 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 25 Jun 2012 10:21:37 +0000 Subject: add tests for IO#seek. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 8dd1f10480..05cfacf225 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1224,7 +1224,15 @@ class TestIO < Test::Unit::TestCase t.puts "bar" t.puts "baz" t.close - t + if block_given? + begin + yield t + ensure + t.close(true) + end + else + t + end end def test_set_lineno @@ -1444,6 +1452,31 @@ class TestIO < Test::Unit::TestCase end + def test_seek + make_tempfile {|t| + open(t.path) { |f| + f.seek(9) + assert_equal("az\n", f.read) + } + + open(t.path) { |f| + f.seek(9, IO::SEEK_SET) + assert_equal("az\n", f.read) + } + + open(t.path) { |f| + f.seek(-4, IO::SEEK_END) + assert_equal("baz\n", f.read) + } + + open(t.path) { |f| + assert_equal("foo\n", f.gets) + f.seek(2, IO::SEEK_CUR) + assert_equal("r\nbaz\n", f.read) + } + } + end + def test_sysseek t = make_tempfile -- cgit v1.2.3