From 40fd465e821e08cd2a1d58c0fc490ff9e8abb095 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 12 May 2005 09:04:49 +0000 Subject: add tests for reading an extended file git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_file.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 1a12491fc2..5589e1236d 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -245,4 +245,49 @@ class TestFile < Test::Unit::TestCase f.truncate(3) assert_equal(nil, f.gets) end + + def test_truncate_beyond_eof + f = Tempfile.new("test-truncate") + f.print "abc" + f.truncate 10 + assert_equal("\0" * 7, f.read(100), "[ruby-dev:24532]") + end + + def test_read_all_extended_file + f = Tempfile.new("test-extended-file") + assert_nil(f.getc) + open(f.path, "w") {|g| g.print "a" } + assert_equal("a", f.read) + end + + def test_gets_extended_file + f = Tempfile.new("test-extended-file") + assert_nil(f.getc) + open(f.path, "w") {|g| g.print "a" } + assert_equal("a", f.gets("a")) + end + + def test_gets_para_extended_file + f = Tempfile.new("test-extended-file") + assert_nil(f.getc) + open(f.path, "w") {|g| g.print "\na" } + assert_equal("a", f.gets("")) + end + + def test_each_byte_extended_file + f = Tempfile.new("test-extended-file") + assert_nil(f.getc) + open(f.path, "w") {|g| g.print "a" } + result = [] + f.each_byte {|b| result << b } + assert_equal([?a], result) + end + + def test_getc_extended_file + f = Tempfile.new("test-extended-file") + assert_nil(f.getc) + open(f.path, "w") {|g| g.print "a" } + assert_equal(?a, f.getc) + end + end -- cgit v1.2.3