[ruby/yarp] test: backfill tests for %q/%Q spanning a heredoc

Also rename the fixture file

https://github.com/ruby/yarp/commit/c148d955fd
This commit is contained in:
Mike Dalessio 2023-08-27 16:19:12 -04:00 committed by git
parent 2b9a053740
commit 8926fd20f6
5 changed files with 141 additions and 94 deletions

View File

@ -0,0 +1,25 @@
# test regex, string, and lists that span a heredoc thanks to an escaped newline
# ripper incorrectly creates a "b\nb" token instead of two separate string tokens
pp <<-A.gsub(/b\
a
A
b/, "")
# ripper incorrectly creates a "d\nd" token instead of two separate string tokens
pp <<-A, "d\
c
A
d"
# ripper gets this right
pp <<-A, %q[f\
e
A
f]
# ripper incorrectly creates a "h\nh" token instead of two separate string tokens
pp <<-A, %Q[h\
g
A
h]

View File

@ -1,13 +0,0 @@
# test regex, string, and lists that wrap a heredoc thanks to an escaped newline
# ripper incorrectly creates a "b\nc" string instead of two separate string tokens
pp <<-A.gsub(/b\
a
A
c/, "")
# ripper incorrectly creates a "e\nf" string instead of two separate string tokens
pp <<-A + "e\
d
A
f"

View File

@ -77,7 +77,7 @@ class ParseTest < Test::Unit::TestCase
# into a single token. See https://bugs.ruby-lang.org/issues/19838.
#
# Additionally, Ripper cannot parse the %w[] fixture in this file, so set ripper_should_parse to false.
ripper_should_match = false if relative == "wrapping_heredoc.txt"
ripper_should_match = false if relative == "spanning_heredoc.txt"
define_method "test_filepath_#{relative}" do
# First, read the source from the filepath. Use binmode to avoid converting CRLF on Windows,

View File

@ -0,0 +1,115 @@
ProgramNode(164...448)(
[],
StatementsNode(164...448)(
[CallNode(164...192)(
nil,
nil,
(164...166),
nil,
ArgumentsNode(167...192)(
[CallNode(167...192)(
InterpolatedStringNode(167...171)(
(167...171),
[StringNode(181...183)(nil, (181...183), nil, "a\n")],
(183...185)
),
(171...172),
(172...176),
(176...177),
ArgumentsNode(177...191)(
[InterpolatedRegularExpressionNode(177...187)(
(177...178),
[StringNode(178...181)(nil, (178...181), nil, "b"),
StringNode(185...186)(nil, (185...186), nil, "b")],
(186...187),
0
),
StringNode(189...191)(
(189...190),
(190...190),
(190...191),
""
)]
),
(191...192),
nil,
0,
"gsub"
)]
),
nil,
nil,
0,
"pp"
),
CallNode(276...295)(
nil,
nil,
(276...278),
nil,
ArgumentsNode(279...295)(
[InterpolatedStringNode(279...283)(
(279...283),
[StringNode(289...291)(nil, (289...291), nil, "c\n")],
(291...293)
),
InterpolatedStringNode(285...295)(
(285...286),
[StringNode(286...289)(nil, (286...289), nil, "d"),
StringNode(293...294)(nil, (293...294), nil, "d")],
(294...295)
)]
),
nil,
nil,
0,
"pp"
),
CallNode(322...343)(
nil,
nil,
(322...324),
nil,
ArgumentsNode(325...343)(
[InterpolatedStringNode(325...329)(
(325...329),
[StringNode(337...339)(nil, (337...339), nil, "e\n")],
(339...341)
),
InterpolatedStringNode(331...343)(
(331...334),
[StringNode(334...337)(nil, (334...337), nil, "f\\\n"),
StringNode(341...342)(nil, (341...342), nil, "f")],
(342...343)
)]
),
nil,
nil,
0,
"pp"
),
CallNode(427...448)(
nil,
nil,
(427...429),
nil,
ArgumentsNode(430...448)(
[InterpolatedStringNode(430...434)(
(430...434),
[StringNode(442...444)(nil, (442...444), nil, "g\n")],
(444...446)
),
InterpolatedStringNode(436...448)(
(436...439),
[StringNode(439...442)(nil, (439...442), nil, "h"),
StringNode(446...447)(nil, (446...447), nil, "h")],
(447...448)
)]
),
nil,
nil,
0,
"pp"
)]
)
)

View File

@ -1,80 +0,0 @@
ProgramNode(165...298)(
[],
StatementsNode(165...298)(
[CallNode(165...193)(
nil,
nil,
(165...167),
nil,
ArgumentsNode(168...193)(
[CallNode(168...193)(
InterpolatedStringNode(168...172)(
(168...172),
[StringNode(182...184)(nil, (182...184), nil, "a\n")],
(184...186)
),
(172...173),
(173...177),
(177...178),
ArgumentsNode(178...192)(
[InterpolatedRegularExpressionNode(178...188)(
(178...179),
[StringNode(179...182)(nil, (179...182), nil, "b"),
StringNode(186...187)(nil, (186...187), nil, "c")],
(187...188),
0
),
StringNode(190...192)(
(190...191),
(191...191),
(191...192),
""
)]
),
(192...193),
nil,
0,
"gsub"
)]
),
nil,
nil,
0,
"pp"
),
CallNode(278...298)(
nil,
nil,
(278...280),
nil,
ArgumentsNode(281...298)(
[CallNode(281...298)(
InterpolatedStringNode(281...285)(
(281...285),
[StringNode(292...294)(nil, (292...294), nil, "d\n")],
(294...296)
),
nil,
(286...287),
nil,
ArgumentsNode(288...298)(
[InterpolatedStringNode(288...298)(
(288...289),
[StringNode(289...292)(nil, (289...292), nil, "e"),
StringNode(296...297)(nil, (296...297), nil, "f")],
(297...298)
)]
),
nil,
nil,
0,
"+"
)]
),
nil,
nil,
0,
"pp"
)]
)
)