2003-11-18 04:23:07 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'stringio'
|
2003-12-04 21:54:48 -05:00
|
|
|
dir = File.expand_path(__FILE__)
|
|
|
|
2.times {dir = File.dirname(dir)}
|
|
|
|
$:.replace([File.join(dir, "ruby")] | $:)
|
|
|
|
require 'ut_eof'
|
2003-11-18 04:23:07 -05:00
|
|
|
|
|
|
|
class TestStringIO < Test::Unit::TestCase
|
2003-12-04 21:54:48 -05:00
|
|
|
include TestEOF
|
|
|
|
def open_file(content)
|
|
|
|
f = StringIO.new(content)
|
|
|
|
yield f
|
2003-11-18 04:23:07 -05:00
|
|
|
end
|
2003-12-09 00:35:16 -05:00
|
|
|
alias open_file_rw open_file
|
2003-12-10 03:16:14 -05:00
|
|
|
|
|
|
|
include TestEOF::Seek
|
2004-09-07 01:32:26 -04:00
|
|
|
|
|
|
|
def test_truncate # [ruby-dev:24190]
|
|
|
|
io = StringIO.new("")
|
|
|
|
io.puts "abc"
|
|
|
|
io.truncate(0)
|
|
|
|
io.puts "def"
|
2004-09-08 05:44:46 -04:00
|
|
|
assert_equal("\0\0\0\0def\n", io.string)
|
2004-09-07 01:32:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_seek_beyond_eof # [ruby-dev:24194]
|
|
|
|
io = StringIO.new
|
|
|
|
n = 100
|
|
|
|
io.seek(n)
|
|
|
|
io.print "last"
|
|
|
|
assert_equal("\0" * n + "last", io.string)
|
|
|
|
end
|
2004-11-29 02:06:21 -05:00
|
|
|
|
|
|
|
def test_overwrite # [ruby-core:03836]
|
|
|
|
stringio = StringIO.new
|
|
|
|
responses = ['', 'just another ruby', 'hacker']
|
|
|
|
responses.each do |resp|
|
|
|
|
stringio.puts(resp)
|
|
|
|
stringio.rewind
|
|
|
|
end
|
|
|
|
assert_equal("hacker\nother ruby\n", stringio.string)
|
|
|
|
end
|
2003-11-18 04:23:07 -05:00
|
|
|
end
|