From 7e35d6fcaa773afc4f492689471f5687cc41c814 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 24 Nov 2011 03:08:52 +0000 Subject: [PATCH] add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index d877f5e832..af161eae26 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2122,4 +2122,39 @@ End end assert_equal(File.size(__FILE__), buf.unpack('i!')[0]) end + + def test_setpos + mkcdtmpdir { + File.open("tmp.txt", "w") {|f| + f.puts "a" + f.puts "bc" + f.puts "def" + } + pos1 = pos2 = pos3 = nil + File.open("tmp.txt") {|f| + assert_equal("a\n", f.gets) + pos1 = f.pos + assert_equal("bc\n", f.gets) + pos2 = f.pos + assert_equal("def\n", f.gets) + pos3 = f.pos + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos1 + assert_equal("bc\n", f.gets) + assert_equal("def\n", f.gets) + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos2 + assert_equal("def\n", f.gets) + assert_equal(nil, f.gets) + } + File.open("tmp.txt") {|f| + f.pos = pos3 + assert_equal(nil, f.gets) + } + } + end end