Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jul 2, 2024, 22:36 UTC
- Message-ID
- <CAPig+cTExD6_5N63Rs4mqp+DqgLVq+aXM84Kp2T0YicMfGX9Sw@mail.gmail.com>
- In-Reply-To
- <CAPig+cQ6PLZA=s6D1XsdcFeeg-=ffib9QZGFLycsHWLZZ1ibCg@mail.gmail.com>
On Tue, Jul 2, 2024 at 5:25 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 10 quoted lines
> On Mon, Jul 1, 2024 at 8:51 PM Jeff King <peff@peff.net> wrote:
> > my $body = substr($$b, $start, pos($$b) - $start);
> > + $self->{parser}->{heredoc} .=
> > + substr($body, 0, length($body) - length($&));
> > $self->{lineno} += () = $body =~ /\n/sg;
>
> In my implementation, I use regex to strip off the ending tag before
> storing the heredoc body. When I later looked at your implementation,
> I noticed that you used substr() -- which seems preferable -- but
> discovered that it strips too much in some cases. [...]Nevermind this part. I just looked again at the misbehaving code (which I had commented out but not deleted) and noticed that I botched the implementation in two distinct ways. With those botches removed, the substr() approach works just fine.