Skip to content

Commit

Permalink
Add tests for RakuAST::Regex::Assertion::PredicateBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 15, 2023
1 parent 7b2264e commit 935d843
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
1 change: 0 additions & 1 deletion t/12-rakuast/TODO
Expand Up @@ -35,7 +35,6 @@ RakuAST::Regex::Assertion::Callable
RakuAST::Regex::Assertion::InterpolatedBlock
RakuAST::Regex::Assertion::InterpolatedVar
RakuAST::Regex::Assertion::Named::Args
RakuAST::Regex::Assertion::PredicateBlock
RakuAST::Regex::BackReference::Named
RakuAST::Regex::BackReference::Positional
RakuAST::Regex::Backtrack::Greedy
Expand Down
57 changes: 56 additions & 1 deletion t/12-rakuast/regex-assertion.rakutest
Expand Up @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL;
use experimental :rakuast;
use Test;

plan 21;
plan 23;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -358,4 +358,59 @@ subtest 'Fail assertion works' => {
match-nok "abc";
}

subtest 'Assertion with predicate block works' => {
# / o <?{ True }> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::Assertion::PredicateBlock.new(
block => RakuAST::Block.new(
body => RakuAST::Blockoid.new(
RakuAST::StatementList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::Term::Name.new(
RakuAST::Name.from-identifier("True")
)
)
)
)
)
)

);
is-deeply $deparsed, q:to/CODE/.chomp, 'deparse';
/ o <?{
True
}> /
CODE
match-ok "foo", 'o';
}

subtest 'Negated assertion with predicate block works' => {
# / o <!{ False }> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::Assertion::PredicateBlock.new(
negated => True,
block => RakuAST::Block.new(
body => RakuAST::Blockoid.new(
RakuAST::StatementList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::Term::Name.new(
RakuAST::Name.from-identifier("False")
)
)
)
)
)
)

);
is-deeply $deparsed, q:to/CODE/.chomp, 'deparse';
/ o <!{
False
}> /
CODE
match-ok "foo", 'o';
}

# vim: expandtab shiftwidth=4

0 comments on commit 935d843

Please sign in to comment.