mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ff2af1ed98
* bootstraptest/test_method.rb: ditto. * test/ruby/test_io.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
57 lines
1.1 KiB
Ruby
57 lines
1.1 KiB
Ruby
require 'test/unit'
|
|
|
|
class TestIO < Test::Unit::TestCase
|
|
def test_gets_rs
|
|
# 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]
|
|
r, w = IO.pipe
|
|
w.print "\377xyz"
|
|
w.close
|
|
assert_equal("\377", r.gets("\377"), "[ruby-dev:24460]")
|
|
r.close
|
|
|
|
# "" [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
|
|
end
|
|
|
|
# This test cause SEGV.
|
|
def test_ungetc
|
|
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
|
|
end
|