diff options
| author | Aaron Patterson <tenderlove@ruby-lang.org> | 2023-07-18 14:37:26 -0700 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-07-20 14:58:11 +0000 |
| commit | abce8583e253e96cf1268926ee7fd790f980ea96 (patch) | |
| tree | bbcb060f1e2f5ff47482ef0064186bf5c4ecb920 /test | |
| parent | 5c219c1b7f6898faf3b13d545f896dc8302ce02a (diff) | |
[ruby/yarp] Fix heredocs inside %W and %w lists
The problem was that we were treating heredoc bodies as part of the %W
list because we didn't push the scanning cursor past the heredoc after
lexing out the here doc. To fix this, we changed the whitespace
scanning function to quit scanning when it reaches a newline but only in
the case that a heredoc is present.
Additionally, we need to prevent double counting newlines in the case of
a heredoc. For example:
```ruby
%W(<<foo 123)
foo
```
The newline after the `)` is counted as part of scanning the heredoc, so
we added logic to prevent double counting the newline when scanning the
rest of the %W list.
https://github.com/ruby/yarp/commit/eb090d8126
Co-authored-by: Jemma Issroff <jemmaissroff@gmail.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/snapshots/seattlerb/pct_w_heredoc_interp_nested.txt | 28 | ||||
| -rw-r--r-- | test/yarp/parse_test.rb | 1 |
2 files changed, 28 insertions, 1 deletions
diff --git a/test/snapshots/seattlerb/pct_w_heredoc_interp_nested.txt b/test/snapshots/seattlerb/pct_w_heredoc_interp_nested.txt new file mode 100644 index 0000000000..89ce74ce19 --- /dev/null +++ b/test/snapshots/seattlerb/pct_w_heredoc_interp_nested.txt @@ -0,0 +1,28 @@ +ProgramNode(0...30)( + [], + StatementsNode(0...30)( + [ArrayNode(0...30)( + [StringNode(4...5)(nil, (4...5), nil, "1"), + InterpolatedStringNode(0...12)( + nil, + [EmbeddedStatementsNode(6...12)( + (6...8), + StatementsNode(8...19)( + [InterpolatedStringNode(8...19)( + (8...11), + [StringNode(15...17)(nil, (15...17), nil, "2\n")], + (17...19) + )] + ), + (11...12) + )], + nil + ), + StringNode(13...14)(nil, (13...14), nil, "3"), + StringNode(25...26)(nil, (25...26), nil, "4"), + StringNode(27...28)(nil, (27...28), nil, "5")], + (0...3), + (29...30) + )] + ) +) diff --git a/test/yarp/parse_test.rb b/test/yarp/parse_test.rb index 3eff7d447f..b6020b82db 100644 --- a/test/yarp/parse_test.rb +++ b/test/yarp/parse_test.rb @@ -28,7 +28,6 @@ class ParseTest < Test::Unit::TestCase known_failures = %w[ seattlerb/heredoc_nested.txt - seattlerb/pct_w_heredoc_interp_nested.txt ] def find_source_file_node(node) |
