aboutsummaryrefslogtreecommitdiffstats
path: root/test/stringio
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-10 08:54:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-10 08:54:40 +0000
commit53f3fb6e551f68a64a08d471140aebff64345a96 (patch)
treedde00c0acb36d195dbea52b14403e9e07cd45233 /test/stringio
parent71dc2cfe04b7b560b87d95f32d3bb06233c726e8 (diff)
downloadruby-53f3fb6e551f68a64a08d471140aebff64345a96.tar.gz
stringio.c: chomp CR
* ext/stringio/stringio.c (strio_getline): chomp CR not only LF, as well as String#chomp. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/stringio')
-rw-r--r--test/stringio/test_stringio.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 07435008ad..d4df7b2617 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -96,6 +96,21 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("def", stringio.gets("", chomp: true))
end
+ def test_gets_chomp_eol
+ assert_equal(nil, StringIO.new("").gets(chomp: true))
+ assert_equal("", StringIO.new("\r\n").gets(chomp: true))
+ assert_equal("a", StringIO.new("a\r\n").gets(chomp: true))
+ assert_equal("a", StringIO.new("a\r\nb\r\n").gets(chomp: true))
+ assert_equal("a", StringIO.new("a").gets(chomp: true))
+ assert_equal("a", StringIO.new("a\r\nb").gets(chomp: true))
+ assert_equal("abc", StringIO.new("abc\r\n\r\ndef\r\n").gets(chomp: true))
+ assert_equal("abc\r\n\r\ndef", StringIO.new("abc\r\n\r\ndef\r\n").gets(nil, chomp: true))
+ assert_equal("abc\r\n", StringIO.new("abc\r\n\r\ndef\r\n").gets("", chomp: true))
+ stringio = StringIO.new("abc\r\n\r\ndef\r\n")
+ assert_equal("abc\r\n", stringio.gets("", chomp: true))
+ assert_equal("def", stringio.gets("", chomp: true))
+ end
+
def test_readlines
assert_equal([], StringIO.new("").readlines)
assert_equal(["\n"], StringIO.new("\n").readlines)
@@ -497,6 +512,11 @@ class TestStringIO < Test::Unit::TestCase
assert_equal(["foo\nbar\n\n", "baz\n"], f.each("").to_a)
f.rewind
assert_equal(["foo\nbar\n", "baz"], f.each("", chomp: true).to_a)
+
+ f = StringIO.new("foo\r\nbar\r\n\r\nbaz\r\n")
+ assert_equal(["foo\r\nbar\r\n\r\n", "baz\r\n"], f.each("").to_a)
+ f.rewind
+ assert_equal(["foo\r\nbar\r\n", "baz"], f.each("", chomp: true).to_a)
end
def test_putc