diff options
author | eileencodes <eileencodes@gmail.com> | 2021-07-20 13:53:22 -0400 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2021-07-21 10:06:33 -0700 |
commit | b940a453572b5c3ed5c0951647929e14f5843a7d (patch) | |
tree | 41d75724ad08b32809de0f7723b31d34f7d13cd6 /test/ruby/test_parse.rb | |
parent | fa308a683d507996ee68352753bbb1813dceff31 (diff) | |
download | ruby-b940a453572b5c3ed5c0951647929e14f5843a7d.tar.gz |
Fix interpolated heredoc
This fixes https://bugs.ruby-lang.org/issues/18038. The provided
reproduction showed that this happens in heredocs with double
interpolation. In this case `DSTR` was getting returned but needs to be
convered to a `EVSTR` which is what is returned by the function. There
may be an additional bug here that we weren't able to produce. It seems
odd that `STR` returns `DSTR` while everything else should return
`EVSTR` since the function is `new_evstr`.
[Bug #18038][ruby-core:104597]
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Diffstat (limited to 'test/ruby/test_parse.rb')
-rw-r--r-- | test/ruby/test_parse.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 0acbaed30f..65b8f87ad0 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1080,6 +1080,32 @@ x = __ENCODING__ end; end + def test_heredoc_interpolation + var = 1 + + v1 = <<~HEREDOC + something + #{"/#{var}"} + HEREDOC + + v2 = <<~HEREDOC + something + #{other = "/#{var}"} + HEREDOC + + v3 = <<~HEREDOC + something + #{("/#{var}")} + HEREDOC + + assert_equal "something\n/1\n", v1 + assert_equal "something\n/1\n", v2 + assert_equal "something\n/1\n", v3 + assert_equal v1, v2 + assert_equal v2, v3 + assert_equal v1, v3 + end + def test_unexpected_token_error assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/) end |