From abce8583e253e96cf1268926ee7fd790f980ea96 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 18 Jul 2023 14:37:26 -0700 Subject: [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(< --- .../seattlerb/pct_w_heredoc_interp_nested.txt | 28 ++++++++++++++++++++++ test/yarp/parse_test.rb | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/snapshots/seattlerb/pct_w_heredoc_interp_nested.txt (limited to 'test') 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) -- cgit v1.2.3