diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-03 14:18:03 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-03 14:18:03 +0000 |
commit | 96e9bbca342dedc9fd91e5599d92c66d5006bb92 (patch) | |
tree | d5e2cef413e9569158ae6fa8021dd85f13a04589 /test/ruby | |
parent | 6be30a5cda127d4fb75e21b4097cdcc4850cdeea (diff) | |
download | ruby-96e9bbca342dedc9fd91e5599d92c66d5006bb92.tar.gz |
string.c: chomp option
* string.c (rb_str_enumerate_lines): implement chomp option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_string.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 433f7743c4..7ee7fa7e97 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -816,6 +816,35 @@ CODE $/ = save end + def test_each_line_chomp + res = [] + S("hello\nworld").each_line("\n", chomp: true) {|x| res << x} + assert_equal(S("hello"), res[0]) + assert_equal(S("world"), res[1]) + + res = [] + S("hello\n\n\nworld").each_line(S(''), chomp: true) {|x| res << x} + assert_equal(S("hello\n\n"), res[0]) + assert_equal(S("world"), res[1]) + + res = [] + S("hello!world").each_line(S('!'), chomp: true) {|x| res << x} + assert_equal(S("hello"), res[0]) + assert_equal(S("world"), res[1]) + + res = [] + S("a").each_line(S('ab'), chomp: true).each {|x| res << x} + assert_equal(1, res.size) + assert_equal(S("a"), res[0]) + + s = nil + "foo\nbar".each_line(nil, chomp: true) {|s2| s = s2 } + assert_equal("foo\nbar", s) + + assert_equal "hello", S("hello\nworld").each_line(chomp: true).next + assert_equal "hello\nworld", S("hello\nworld").each_line(nil, chomp: true).next + end + def test_lines s = S("hello\nworld") assert_equal ["hello\n", "world"], s.lines |