aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_syntax.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 14:39:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 14:39:52 +0000
commit9a28a29b870b5f45d370bc8f16c431b435f0bbb3 (patch)
tree1a8a83e8ca857731116ed37273b53d6812afd011 /test/ruby/test_syntax.rb
parent9f51e95fc18002939505ce352dee3f97efde3ada (diff)
downloadruby-9a28a29b870b5f45d370bc8f16c431b435f0bbb3.tar.gz
parse.y: indented hereoc
* parse.y: add heredoc <<~ syntax. [Feature #9098] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52916 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_syntax.rb')
-rw-r--r--test/ruby/test_syntax.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index e2cd389a07..82af7817e7 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -475,6 +475,94 @@ e"
assert_equal(expected, actual, "#{Bug7559}: ")
end
+ def test_dedented_heredoc_without_indentation
+ assert_equal(" y\nz\n", <<~eos)
+ y
+z
+ eos
+ end
+
+ def test_dedented_heredoc_with_indentation
+ assert_equal(" a\nb\n", <<~eos)
+ a
+ b
+ eos
+ 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)
+ 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)
+ 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)
+ 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)
+ 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
+ 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
+ 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
+ end
+
def test_lineno_after_heredoc
bug7559 = '[ruby-dev:46737]'
expected, _, actual = __LINE__, <<eom, __LINE__