2004-10-09 11:53:16 +00:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestIO < Test::Unit::TestCase
|
|
|
|
def test_gets_rs
|
2004-11-20 17:29:18 +00:00
|
|
|
# default_rs
|
|
|
|
r, w = IO.pipe
|
|
|
|
w.print "aaa\nbbb\n"
|
|
|
|
w.close
|
|
|
|
assert_equal "aaa\n", r.gets
|
|
|
|
assert_equal "bbb\n", r.gets
|
|
|
|
assert_nil r.gets
|
|
|
|
r.close
|
|
|
|
|
|
|
|
# nil
|
|
|
|
r, w = IO.pipe
|
|
|
|
w.print "a\n\nb\n\n"
|
|
|
|
w.close
|
|
|
|
assert_equal "a\n\nb\n\n", r.gets(nil)
|
|
|
|
assert_nil r.gets("")
|
|
|
|
r.close
|
|
|
|
|
2007-11-18 07:18:56 +00:00
|
|
|
# "\377"
|
2008-01-10 10:35:52 +00:00
|
|
|
r, w = IO.pipe('ascii-8bit')
|
2004-10-09 11:53:16 +00:00
|
|
|
w.print "\377xyz"
|
|
|
|
w.close
|
2007-12-24 02:40:55 +00:00
|
|
|
r.binmode
|
2004-10-09 11:53:16 +00:00
|
|
|
assert_equal("\377", r.gets("\377"), "[ruby-dev:24460]")
|
|
|
|
r.close
|
2004-11-20 17:29:18 +00:00
|
|
|
|
2007-11-18 07:18:56 +00:00
|
|
|
# ""
|
2004-11-20 17:29:18 +00:00
|
|
|
r, w = IO.pipe
|
|
|
|
w.print "a\n\nb\n\n"
|
|
|
|
w.close
|
2007-11-18 07:18:56 +00:00
|
|
|
assert_equal "a\n\n", r.gets(""), "[ruby-core:03771]"
|
2004-11-20 17:29:18 +00:00
|
|
|
assert_equal "b\n\n", r.gets("")
|
|
|
|
assert_nil r.gets("")
|
|
|
|
r.close
|
2004-10-09 11:53:16 +00:00
|
|
|
end
|
2007-09-08 15:59:05 +00:00
|
|
|
|
2007-09-14 08:31:24 +00:00
|
|
|
# This test cause SEGV.
|
2007-09-26 11:01:18 +00:00
|
|
|
def test_ungetc
|
2007-09-08 15:59:05 +00:00
|
|
|
r, w = IO.pipe
|
|
|
|
w.close
|
|
|
|
assert_raise(IOError, "[ruby-dev:31650]") { 20000.times { r.ungetc "a" } }
|
|
|
|
ensure
|
|
|
|
r.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_each_byte
|
|
|
|
r, w = IO.pipe
|
|
|
|
w << "abc def"
|
|
|
|
w.close
|
|
|
|
r.each_byte {|byte| break if byte == 32 }
|
|
|
|
assert_equal("def", r.read, "[ruby-dev:31659]")
|
|
|
|
ensure
|
|
|
|
r.close
|
|
|
|
end
|
2004-10-09 11:53:16 +00:00
|
|
|
end
|