aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-25 10:21:37 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-25 10:21:37 +0000
commitf4af54f212907bd2ecd0be9d1e9a6237641b24b3 (patch)
tree6ebc61f647a6bd5fdf6c2bfcde8b2c8fd85fc600 /test
parent82a408fb9d755b106be2cc23dd08831f158893f5 (diff)
downloadruby-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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io.rb35
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