diff options
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f02ce6d31a..9ce05e93fd 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -405,19 +405,6 @@ class TestIO < Test::Unit::TestCase } end - def test_each_codepoint_enumerator - make_tempfile {|t| - a = "" - b = "" - File.open(t, 'rt') {|f| - a = f.each_codepoint.take(4).pack('U*') - b = f.read(8) - } - assert_equal("foo\n", a) - assert_equal("bar\nbaz\n", b) - } - end - def test_rubydev33072 t = make_tempfile path = t.path @@ -1822,6 +1809,61 @@ class TestIO < Test::Unit::TestCase end) end + def test_each_line + pipe(proc do |w| + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_line + } + assert_equal("foo\n", e.next) + assert_equal("bar\n", e.next) + assert_equal("baz\n", e.next) + assert_raise(StopIteration) { e.next } + end) + end + + def test_each_byte + pipe(proc do |w| + w.binmode + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_byte + } + (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| + assert_equal(c.ord, e.next) + end + assert_raise(StopIteration) { e.next } + end) + end + + def test_each_char + pipe(proc do |w| + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_char + } + (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| + assert_equal(c, e.next) + end + assert_raise(StopIteration) { e.next } + end) + end + def test_readbyte pipe(proc do |w| w.binmode |