Skip to content

Commit

Permalink
Added tests for RakuAST::Regex::CharClassElement::Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 14, 2023
1 parent c45c258 commit 1f4eb03
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
1 change: 0 additions & 1 deletion t/12-rakuast/TODO
Expand Up @@ -44,7 +44,6 @@ RakuAST::Regex::BackReference::Positional
RakuAST::Regex::Backtrack::Greedy
RakuAST::Regex::BacktrackModifiedAtom
RakuAST::Regex::Block
RakuAST::Regex::CharClassElement::Rule
RakuAST::Regex::InternalModifier::IgnoreCase
RakuAST::Regex::InternalModifier::IgnoreMark
RakuAST::Regex::InternalModifier::Ratchet
Expand Down
77 changes: 76 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 14;
plan 19;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -263,4 +263,79 @@ subtest 'Multiple character property assertion works' => {
match-ok "Fooa9cbar", 'o';
}

subtest 'Character property with expression assertion works' => {
# / <+:Block("Basic Latin")> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Property.new(
property => 'Block',
predicate => RakuAST::Circumfix::Parentheses.new(
RakuAST::StrLiteral.new("Basic Latin")
),
)
)
);
is-deeply $deparsed, '/ <+:Block("Basic Latin")> /', 'deparse';
match-ok "🦋:Fooa9cbar", ':';
}

subtest 'Negated character property with expression assertion works' => {
# / <-:Block("Basic Latin")> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Property.new(
negated => True,
property => 'Block',
predicate => RakuAST::Circumfix::Parentheses.new(
RakuAST::StrLiteral.new("Basic Latin")
),
)
)
);
is-deeply $deparsed, '/ <-:Block("Basic Latin")> /', 'deparse';
match-ok ":🦋Fooa9cbar", '🦋';
}

subtest 'Rule assertion works' => {
# / <+alpha> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Rule.new(
name => "alpha"
)
)
);
is-deeply $deparsed, '/ <+alpha> /', 'deparse';
match-ok "🦋:Fooa9cbar", 'F';
}

subtest 'Negated rule assertion works' => {
# / <-alpha> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Rule.new(
name => "alpha", :negated
)
)
);
is-deeply $deparsed, '/ <-alpha> /', 'deparse';
match-ok "Fooa🦋:9cbar", '🦋';
}

subtest 'Multiple rule assertions work' => {
# / <+alpha -xdigit> /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Rule.new(
name => "alpha"
),
RakuAST::Regex::CharClassElement::Rule.new(
name => "xdigit", :negated
)
)
);
is-deeply $deparsed, '/ <+alpha -xdigit> /', 'deparse';
match-ok "Fooa🦋:9cbar", 'o';
}

# vim: expandtab shiftwidth=4

0 comments on commit 1f4eb03

Please sign in to comment.