1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ripper_state_lex.rb: chomp CR

* lib/rdoc/parser/ripper_state_lex.rb (RDoc::Parser::RipperStateLex):
  chomp newline, including CR, from here document terminator.

Closes: ruby/rdoc#694
Closes: ruby/rdoc#697
Closes: ruby/rdoc#705
This commit is contained in:
Nobuyoshi Nakada 2019-06-07 18:45:49 +09:00
parent a6a26e42b1
commit 6566919176
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 17 additions and 1 deletions

View file

@ -494,7 +494,8 @@ class RDoc::Parser::RipperStateLex
private def heredoc_end?(name, indent, tk)
result = false
if :on_heredoc_end == tk[:kind] then
tk_name = (indent ? tk[:text].gsub(/^ *(.+)\n?$/, '\1') : tk[:text].gsub(/\n\z/, ''))
tk_name = tk[:text].chomp
tk_name.lstrip! if indent
if name == tk_name
result = true
end

View file

@ -2914,6 +2914,21 @@ EXPECTED
assert_equal expected, markup_code
end
def test_parse_heredoc_end
code = "A = <<eos\n""OK\n""eos\n"
util_parser code
@parser.parse_statements @top_level
@parser.scan
c = @top_level.classes.first.constants.first
assert_equal("A", c.name)
util_parser code.gsub(/$/, "\r")
@parser.parse_statements @top_level
@parser.scan
c = @top_level.classes.first.constants.first
assert_equal("A", c.name)
end
def test_parse_statements_method_oneliner_with_regexp
util_parser <<RUBY
class Foo