mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
parse.y: single-quote indented heredoc
* parse.y (parser_here_document): update indent for each line in indented here document with single-quotes. [ruby-core:72479] [Bug #11871] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d6c769a5fe
commit
b1796737cf
3 changed files with 99 additions and 76 deletions
|
@ -492,92 +492,92 @@ e"
|
|||
assert_equal(expected, actual, "#{Bug7559}: ")
|
||||
end
|
||||
|
||||
def assert_dedented_heredoc(expect, result, mesg = "")
|
||||
%w[eos "eos" 'eos'].each do |eos|
|
||||
assert_equal(eval("<<-#{eos}\n#{expect}eos\n"),
|
||||
eval("<<~#{eos}\n#{result}eos\n"),
|
||||
message(mesg) {"with #{eos}"})
|
||||
end
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_without_indentation
|
||||
assert_equal(" y\nz\n", <<~eos)
|
||||
y
|
||||
z
|
||||
eos
|
||||
result = " y\n" \
|
||||
"z\n"
|
||||
expect = result
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_indentation
|
||||
assert_equal(" a\nb\n", <<~eos)
|
||||
a
|
||||
b
|
||||
eos
|
||||
result = " a\n" \
|
||||
" b\n"
|
||||
expect = " a\n" \
|
||||
"b\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_blank_less_indented_line
|
||||
# the blank line has two leading spaces
|
||||
result = eval("<<~eos\n" \
|
||||
" a\n" \
|
||||
" \n" \
|
||||
" b\n" \
|
||||
" eos\n")
|
||||
assert_equal("a\n\nb\n", result)
|
||||
result = " a\n" \
|
||||
" \n" \
|
||||
" b\n"
|
||||
expect = "a\n" \
|
||||
"\n" \
|
||||
"b\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_blank_less_indented_line_escaped
|
||||
result = eval("<<~eos\n" \
|
||||
" a\n" \
|
||||
"\\ \\ \n" \
|
||||
" b\n" \
|
||||
" eos\n")
|
||||
assert_equal(" a\n \n b\n", result)
|
||||
result = " a\n" \
|
||||
"\\ \\ \n" \
|
||||
" b\n"
|
||||
expect = result
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_blank_more_indented_line
|
||||
# the blank line has six leading spaces
|
||||
result = eval("<<~eos\n" \
|
||||
" a\n" \
|
||||
" \n" \
|
||||
" b\n" \
|
||||
" eos\n")
|
||||
assert_equal("a\n \nb\n", result)
|
||||
result = " a\n" \
|
||||
" \n" \
|
||||
" b\n"
|
||||
expect = "a\n" \
|
||||
" \n" \
|
||||
"b\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_blank_more_indented_line_escaped
|
||||
result = eval("<<~eos\n" \
|
||||
" a\n" \
|
||||
"\\ \\ \\ \\ \\ \\ \n" \
|
||||
" b\n" \
|
||||
" eos\n")
|
||||
assert_equal(" a\n \n b\n", result)
|
||||
result = " a\n" \
|
||||
"\\ \\ \\ \\ \\ \\ \n" \
|
||||
" b\n"
|
||||
expect = result
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_empty_line
|
||||
result = eval("<<~eos\n" \
|
||||
" This would contain specially formatted text.\n" \
|
||||
"\n" \
|
||||
" That might span many lines\n" \
|
||||
" eos\n")
|
||||
assert_equal(<<-eos, result)
|
||||
This would contain specially formatted text.
|
||||
|
||||
That might span many lines
|
||||
eos
|
||||
result = " This would contain specially formatted text.\n" \
|
||||
"\n" \
|
||||
" That might span many lines\n"
|
||||
expect = 'This would contain specially formatted text.'"\n" \
|
||||
''"\n" \
|
||||
'That might span many lines'"\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_interpolated_expression
|
||||
result = eval(" <<~eos\n" \
|
||||
" #{1}a\n" \
|
||||
" zy\n" \
|
||||
" eos\n")
|
||||
assert_equal(<<-eos, result)
|
||||
#{1}a
|
||||
zy
|
||||
eos
|
||||
result = ' #{1}a'"\n" \
|
||||
" zy\n"
|
||||
expect = ' #{1}a'"\n" \
|
||||
"zy\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_with_interpolated_string
|
||||
w = ""
|
||||
result = eval("<<~eos\n" \
|
||||
" \#{w} a\n" \
|
||||
" zy\n" \
|
||||
" eos\n")
|
||||
assert_equal(<<-eos, result)
|
||||
#{w} a
|
||||
zy
|
||||
eos
|
||||
result = " \#{mesg} a\n" \
|
||||
" zy\n"
|
||||
expect = '#{mesg} a'"\n" \
|
||||
' zy'"\n"
|
||||
assert_dedented_heredoc(expect, result)
|
||||
end
|
||||
|
||||
def test_lineno_after_heredoc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue