summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-30 10:30:56 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-30 10:30:56 +0000
commit5024abe0cf17fa479487bf9741b694e20986c085 (patch)
treec33797956837abafcdc3b1f40a5265d16ff5f367 /test
parent6aac76353a3a9d57a2ad26f93bb98d6b1a2cb8be (diff)
merge revision(s) 58545,58584: [Backport #13536]
ripper/lexer.rb: nested indented heredoc * ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): fix for nested indedented here documents, where `Elem`s are nested too. [ruby-core:80977] [Bug #13536] ripper/lexer.rb: nested indented heredoc * ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): insert stripped leading spaces as `on_ignored_sp` elements, so that the original source can be reconsructed. [ruby-core:80977] [Bug #13536] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_lexer.rb35
-rw-r--r--test/ripper/test_scanner_events.rb1
2 files changed, 36 insertions, 0 deletions
diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb
new file mode 100644
index 0000000000..72b7f1b5fd
--- /dev/null
+++ b/test/ripper/test_lexer.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+begin
+ require_relative 'dummyparser'
+ require 'test/unit'
+ ripper_test = true
+ module TestRipper; end
+rescue LoadError
+end
+
+class TestRipper::Lexer < Test::Unit::TestCase
+ def test_nested_dedent_heredoc
+ bug = '[ruby-core:80977] [Bug #13536]'
+ str = <<~'E'
+ <<~"D"
+ #{
+ <<~"B"
+ this must be a valid ruby
+ B
+ }
+ D
+ E
+ assert_equal(str, Ripper.tokenize(str).join(""), bug)
+
+ str = <<~'E'
+ <<~"D"
+ #{
+ <<~"B"
+ this must be a valid ruby
+ B
+ }
+ D
+ E
+ assert_equal(str, Ripper.tokenize(str).join(""), bug)
+ end
+end
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 8c950041a2..9f185b2a7e 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -105,6 +105,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
Ripper.lex("1r\n2i\n3ri\n4.2r\n5.6ri")
assert_equal [[[1, 0], :on_heredoc_beg, "<<~EOS"],
[[1, 6], :on_nl, "\n"],
+ [[2, 0], :on_ignored_sp, " "],
[[2, 2], :on_tstring_content, "heredoc\n"],
[[3, 0], :on_heredoc_end, "EOS"]
],