diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-29 16:40:05 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-29 16:40:05 +0000 |
commit | 4310b5d9ce709225c594ba1e04b2cfe13b105d25 (patch) | |
tree | 2f3668175da80ef4684c1fcf68f62a171cd3de4f /test/ruby/test_file.rb | |
parent | e16ca20e84705cdd59a3f4a74c2e062e2eb384d9 (diff) | |
download | ruby-4310b5d9ce709225c594ba1e04b2cfe13b105d25.tar.gz ruby-4310b5d9ce709225c594ba1e04b2cfe13b105d25.tar.xz ruby-4310b5d9ce709225c594ba1e04b2cfe13b105d25.zip |
* io.c (rb_io_rewind): should reset fptr->readconv if it's
available.
* io.c (more_char): clear readconv at EOF.
* test/ruby/test_file.rb: should not read after EOF. use rewind
instead.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_file.rb')
-rw-r--r-- | test/ruby/test_file.rb | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 0732c76a8..b4666ad4a 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -42,8 +42,9 @@ class TestFile < Test::Unit::TestCase f.print "abc" f.truncate(0) f.print "def" - f.close + f.flush assert_equal("\0\0\0def", File.read(f.path), "[ruby-dev:24191]") + f.close end def test_truncate_rbuf @@ -68,7 +69,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal("a", f.read, "mode = <#{mode}>") end end @@ -77,7 +79,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal("a", f.gets("a"), "mode = <#{mode}>") end end @@ -86,7 +89,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "wb") {|g| g.print "\na" } + f.print "\na" + f.rewind assert_equal("a", f.gets(""), "mode = <#{mode}>") end end @@ -95,7 +99,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind result = [] f.each_char {|b| result << b } assert_equal([?a], result, "mode = <#{mode}>") @@ -106,7 +111,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind result = [] f.each_byte {|b| result << b.chr } assert_equal([?a], result, "mode = <#{mode}>") @@ -117,7 +123,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal(?a, f.getc, "mode = <#{mode}>") end end @@ -126,7 +133,8 @@ class TestFile < Test::Unit::TestCase [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal(?a, f.getbyte.chr, "mode = <#{mode}>") end end |