diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-07 22:39:38 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-08 10:13:29 +0900 |
commit | 32a13591e0bb6e96b05452e214f14eda21ee3aa9 (patch) | |
tree | 27515ac48fffd1e064b484e476ed90a982ef5ef2 /test | |
parent | 99f54c08953a96ebaa822f4fdce6d9de47f99814 (diff) |
[ruby/stringio] Check if closed in loop
[Bug #17675] https://bugs.ruby-lang.org/issues/17675
https://github.com/ruby/stringio/commit/1ed61d0cbc
Diffstat (limited to 'test')
-rw-r--r-- | test/stringio/test_stringio.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 036e374b98..e0b4504b54 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -446,6 +446,15 @@ class TestStringIO < Test::Unit::TestCase f.close unless f.closed? end + def test_each_byte_closed + f = StringIO.new("1234") + assert_equal("1".ord, f.each_byte {|c| f.close; break c }) + f = StringIO.new("1234") + assert_raise(IOError) do + f.each_byte { f.close } + end + end + def test_getbyte f = StringIO.new("1234") assert_equal("1".ord, f.getbyte) @@ -520,11 +529,29 @@ class TestStringIO < Test::Unit::TestCase assert_equal(%w(1 2 3 4), f.each_char.to_a) end + def test_each_char_closed + f = StringIO.new("1234") + assert_equal("1", f.each_char {|c| f.close; break c }) + f = StringIO.new("1234") + assert_raise(IOError) do + f.each_char { f.close } + end + end + def test_each_codepoint f = StringIO.new("1234") assert_equal([49, 50, 51, 52], f.each_codepoint.to_a) end + def test_each_codepoint_closed + f = StringIO.new("1234") + assert_equal("1".ord, f.each_codepoint {|c| f.close; break c }) + f = StringIO.new("1234") + assert_raise(IOError) do + f.each_codepoint { f.close } + end + end + def test_each_codepoint_enumerator io = StringIO.new('你好построить') |