diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-25 10:21:37 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-25 10:21:37 +0000 |
commit | f4af54f212907bd2ecd0be9d1e9a6237641b24b3 (patch) | |
tree | 6ebc61f647a6bd5fdf6c2bfcde8b2c8fd85fc600 | |
parent | 82a408fb9d755b106be2cc23dd08831f158893f5 (diff) | |
download | ruby-f4af54f212907bd2ecd0be9d1e9a6237641b24b3.tar.gz |
add tests for IO#seek.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_io.rb | 35 |
1 files changed, 34 insertions, 1 deletions
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 |