ruby-changes:21778
From: akr <ko1@a...>
Date: Thu, 24 Nov 2011 12:09:01 +0900 (JST)
Subject: [ruby-changes:21778] akr:r33827 (trunk): add a test.
akr 2011-11-24 12:08:52 +0900 (Thu, 24 Nov 2011) New Revision: 33827 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33827 Log: add a test. Modified files: trunk/test/ruby/test_io.rb Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 33826) +++ test/ruby/test_io.rb (revision 33827) @@ -2122,4 +2122,39 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/