From 8d7c52dbe21f1bbd423860c7bab21a9f8ce487c2 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 29 Mar 2013 07:51:08 +0000 Subject: io.c: get rid of IOError when skipped while iteration * io.c (argf_close): deal with init flag. * io.c (argf_block_call_i, argf_block_call): forward next file if skipped while iteration, to get rid of IOError. [ruby-list:49185] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_argf.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/ruby/test_argf.rb') diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 1bccac0ffa..979b66765b 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -683,6 +683,44 @@ class TestArgf < Test::Unit::TestCase end end + def test_skip_in_each_line + ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| + ARGF.each_line {|l| print l; ARGF.skip} + SRC + assert_equal("1\n3\n5\n", f.read, '[ruby-list:49185]') + end + end + + def test_skip_in_each_byte + ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| + ARGF.each_byte {|l| print l; ARGF.skip} + SRC + assert_equal("135".unpack("C*").join(""), f.read, '[ruby-list:49185]') + end + end + + def test_skip_in_each_char + [[@t1, "\u{3042}"], [@t2, "\u{3044}"], [@t3, "\u{3046}"]].each do |f, s| + File.write(f.path, s, mode: "w:utf-8") + end + ruby('-Eutf-8', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| + ARGF.each_char {|l| print l; ARGF.skip} + SRC + assert_equal("\u{3042 3044 3046}", f.read, '[ruby-list:49185]') + end + end + + def test_skip_in_each_codepoint + [[@t1, "\u{3042}"], [@t2, "\u{3044}"], [@t3, "\u{3046}"]].each do |f, s| + File.write(f.path, s, mode: "w:utf-8") + end + ruby('-Eutf-8', '-Eutf-8', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| + ARGF.each_codepoint {|l| printf "%x:", l; ARGF.skip} + SRC + assert_equal("3042:3044:3046:", f.read, '[ruby-list:49185]') + end + end + def test_close ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| ARGF.close -- cgit v1.2.3