summaryrefslogtreecommitdiff
path: root/test/ruby/test_argf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-29 07:51:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-29 07:51:08 +0000
commit8d7c52dbe21f1bbd423860c7bab21a9f8ce487c2 (patch)
treead7db745219ad3beae52cec06d7a6d4f2e36e78f /test/ruby/test_argf.rb
parent2e26edb633606f1e99d22817678e11c25f7d2882 (diff)
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
Diffstat (limited to 'test/ruby/test_argf.rb')
-rw-r--r--test/ruby/test_argf.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 1bccac0ffa1..979b66765b1 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