diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-05-26 12:22:42 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2022-07-21 12:55:24 -0700 |
commit | 7223c0da152114c84e1c4261a282faaea21646fb (patch) | |
tree | 92ec924c4c538126b2552e42190dd2d2844d0cd0 /test/ruby | |
parent | 3a5ea7c688b5c029ee8f69d84f49bc10b817714e (diff) | |
download | ruby-7223c0da152114c84e1c4261a282faaea21646fb.tar.gz |
Do not chomp trailing line separator IO#each with nil separator and chomp
nil separator means no sepator, so chomp should not remove a line
separator.
Partially Fixes [Bug #18770]
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 0f42d8e164..b8530e7400 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -312,7 +312,7 @@ class TestIO < Test::Unit::TestCase w.print "a\n\nb\n\n" w.close end, proc do |r| - assert_equal "a\n\nb\n", r.gets(nil, chomp: true) + assert_equal("a\n\nb\n\n", r.gets(nil, chomp: true), "[Bug #18770]") assert_nil r.gets("") r.close end) @@ -1894,6 +1894,20 @@ class TestIO < Test::Unit::TestCase assert_equal("baz\n", e.next) assert_raise(StopIteration) { e.next } end) + + pipe(proc do |w| + w.write "foo\n" + w.close + end, proc do |r| + assert_equal(["foo\n"], r.each_line(nil, chomp: true).to_a, "[Bug #18770]") + end) + + pipe(proc do |w| + w.write "foo\n" + w.close + end, proc do |r| + assert_equal(["fo", "o\n"], r.each_line(nil, 2, chomp: true).to_a, "[Bug #18770]") + end) end def test_each_byte2 |