ruby-changes:24166
From: akr <ko1@a...>
Date: Mon, 25 Jun 2012 19:21:47 +0900 (JST)
Subject: [ruby-changes:24166] akr:r36217 (trunk): add tests for IO#seek.
akr 2012-06-25 19:21:37 +0900 (Mon, 25 Jun 2012) New Revision: 36217 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36217 Log: add tests for IO#seek. Modified files: trunk/test/ruby/test_io.rb Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 36216) +++ test/ruby/test_io.rb (revision 36217) @@ -1224,7 +1224,15 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/