Skip to content

Commit

Permalink
Add tests for RakuAST::Regex::InternalModifier::(Ratchet|Sigspace)
Browse files Browse the repository at this point in the history
And additionally RakuAST::Regex::WithSigspace
  • Loading branch information
lizmat committed Jan 17, 2023
1 parent 78526bc commit 7551c67
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
3 changes: 0 additions & 3 deletions t/12-rakuast/TODO
Expand Up @@ -33,12 +33,9 @@ RakuAST::Regex::Assertion::Callable
RakuAST::Regex::Assertion::Named::Args
RakuAST::Regex::Backtrack::Greedy
RakuAST::Regex::BacktrackModifiedAtom
RakuAST::Regex::InternalModifier::Ratchet
RakuAST::Regex::InternalModifier::Sigspace
RakuAST::Regex::Quantifier::BlockRange
RakuAST::Regex::SequentialConjunction
RakuAST::Regex::Term
RakuAST::Regex::WithSigspace
RakuAST::RegexDeclaration
RakuAST::RegexThunk
RakuAST::Statement::Control
Expand Down
78 changes: 65 additions & 13 deletions t/12-rakuast/regex.rakutest
Expand Up @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL;
use experimental :rakuast;
use Test;

plan 51;
plan 55;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -609,6 +609,25 @@ subtest 'Match with block' => {
match-ok "foo", 'oo', 2;
}

subtest 'Match with variable definition' => {
# / o :my $foo; o /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::Statement.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::VarDeclaration::Simple.new(
scope => 'my',
name => '$foo'
)
)
),
RakuAST::Regex::Literal.new("o")
);
is-deeply $deparsed, '/ o :my $foo; o /', 'deparse';

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

subtest 'Match with ignoring case' => {
# / :i oo /
ast RakuAST::Regex::Sequence.new(
Expand Down Expand Up @@ -668,28 +687,61 @@ subtest 'No match with *not* ignoring mark' => {
# / :!m oo /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::InternalModifier::IgnoreMark.new(:negated),
RakuAST::Regex::Literal.new("oo"),
RakuAST::Regex::Literal.new("oo")
);
is-deeply $deparsed, '/ :!m oo /', 'deparse';

match-nok "Föö";
}

subtest 'Match with variable definition' => {
# / o :my $foo; o /
subtest 'Match with ratchet' => {
# / o :r o /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::Statement.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::VarDeclaration::Simple.new(
scope => 'my',
name => '$foo'
)
)
),
RakuAST::Regex::InternalModifier::Ratchet.new,
RakuAST::Regex::Literal.new("o")
);
is-deeply $deparsed, '/ o :my $foo; o /', 'deparse';
is-deeply $deparsed, '/ o :r o /', 'deparse';

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

subtest 'Match without ratchet' => {
# / o :!r o /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::InternalModifier::Ratchet.new(:negated),
RakuAST::Regex::Literal.new("o")
);
is-deeply $deparsed, '/ o :!r o /', 'deparse';

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

subtest 'Match with sigspace' => {
# / o :s o /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::InternalModifier::Sigspace.new,
RakuAST::Regex::WithSigspace.new(
RakuAST::Regex::Literal.new("o")
)
);
is-deeply $deparsed, '/ o :s o /', 'deparse';

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

subtest 'Match without sigspace' => {
# / o :!s o /
ast RakuAST::Regex::Sequence.new(
RakuAST::Regex::Literal.new("o"),
RakuAST::Regex::InternalModifier::Sigspace.new(:negated),
RakuAST::Regex::WithSigspace.new(
RakuAST::Regex::Literal.new("o")
)
);
is-deeply $deparsed, '/ o :!s o /', 'deparse';

match-ok "Foo", 'oo';
}
Expand Down

0 comments on commit 7551c67

Please sign in to comment.