2004-10-09 07:53:16 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestIO < Test::Unit::TestCase
|
|
|
|
def test_gets_rs
|
2004-11-20 12:29:18 -05: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
|
|
|
|
|
|
|
|
# "\377" [ruby-dev:24460]
|
2004-10-09 07:53:16 -04:00
|
|
|
r, w = IO.pipe
|
|
|
|
w.print "\377xyz"
|
|
|
|
w.close
|
|
|
|
assert_equal("\377", r.gets("\377"), "[ruby-dev:24460]")
|
|
|
|
r.close
|
2004-11-20 12:29:18 -05:00
|
|
|
|
|
|
|
# "" [ruby-core:03771]
|
|
|
|
r, w = IO.pipe
|
|
|
|
w.print "a\n\nb\n\n"
|
|
|
|
w.close
|
|
|
|
assert_equal "a\n\n", r.gets("")
|
|
|
|
assert_equal "b\n\n", r.gets("")
|
|
|
|
assert_nil r.gets("")
|
|
|
|
r.close
|
2004-10-09 07:53:16 -04:00
|
|
|
end
|
|
|
|
end
|