Skip to content

Commit

Permalink
Add tests for RakuAST::Regex::BackReference::(Positional|Named)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 17, 2023
1 parent 63d49ac commit 1eee636
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 0 additions & 2 deletions t/12-rakuast/TODO
Expand Up @@ -31,8 +31,6 @@ RakuAST::QuoteWordsAtom
RakuAST::QuotedMatchConstruct
RakuAST::Regex::Assertion::Callable
RakuAST::Regex::Assertion::Named::Args
RakuAST::Regex::BackReference::Named
RakuAST::Regex::BackReference::Positional
RakuAST::Regex::Backtrack::Greedy
RakuAST::Regex::BacktrackModifiedAtom
RakuAST::Regex::Block
Expand Down
29 changes: 28 additions & 1 deletion t/12-rakuast/regex.rakutest
Expand Up @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL;
use experimental :rakuast;
use Test;

plan 40;
plan 42;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -539,4 +539,31 @@ subtest 'Match involving quote words works' => {
match-ok "slinky sprint", 'linky';
}

subtest 'Match with positional backreference' => {
# / (o) $0 }> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::CapturingGroup.new(
RakuAST::Regex::Literal.new("o"),
),
RakuAST::Regex::BackReference::Positional.new(0)
);
is-deeply $deparsed, '/ (o) $0 /', 'deparse';

match-ok "foo", 'oo';
}

subtest 'Match with named backreference' => {
# / $<bar>=o $<bar> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::NamedCapture.new(
name => 'bar',
regex => RakuAST::Regex::Literal.new("o"),
),
RakuAST::Regex::BackReference::Named.new("bar")
);
is-deeply $deparsed, '/ $<bar>=o $<bar> /', 'deparse';

match-ok "foo", 'oo';
}

# vim: expandtab shiftwidth=4

0 comments on commit 1eee636

Please sign in to comment.