Skip to content

Commit

Permalink
RakuAST: add tests for where literal / regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Feb 15, 2023
1 parent f89db51 commit 7ad82e9
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion t/12-rakuast/subset.rakutest
Expand Up @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL;
use experimental :rakuast;
use Test;

plan 5;
plan 7;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -177,4 +177,48 @@ subtest 'Subset with a where whatevercode' => {
}
}

subtest 'Subset with a where literal' => {
# my subset Foo where 42
ast RakuAST::Type::Subset.new(
scope => 'my',
name => RakuAST::Name.from-identifier("Foo"),
where => RakuAST::IntLiteral.new(42)
);

is-deeply $deparsed, 'my subset Foo where 42', 'deparse';

for 'AST', EVAL($ast), 'Str', EVAL($deparsed) -> $type, $subset {
is-deeply $subset.^name, "Foo", "$type: is name ok";
is-deeply $subset.^refinee, Any, "$type: is refinee ok";
isa-ok $subset.^refinement, Block, "$type: is refinement ok";

ok 42 ~~ $subset, "$type: subset accepts 42";
nok 41 ~~ $subset, "$type: subset does not accept 41";
nok "foo" ~~ $subset, "$type: subset does not accept foo";
}
}

subtest 'Subset with a where regex' => {
# my subset Foo where / 42 /
ast RakuAST::Type::Subset.new(
scope => 'my',
name => RakuAST::Name.from-identifier("Foo"),
where => RakuAST::QuotedRegex.new(
body => RakuAST::Regex::Literal.new('42')
)
);

is-deeply $deparsed, 'my subset Foo where / 42 /', 'deparse';

for 'AST', EVAL($ast), 'Str', EVAL($deparsed) -> $type, $subset {
is-deeply $subset.^name, "Foo", "$type: is name ok";
is-deeply $subset.^refinee, Any, "$type: is refinee ok";
isa-ok $subset.^refinement, Block, "$type: is refinement ok";

ok 42 ~~ $subset, "$type: subset accepts 42";
nok 41 ~~ $subset, "$type: subset does not accept 41";
nok "foo" ~~ $subset, "$type: subset does not accept foo";
}
}

# vim: expandtab shiftwidth=4

0 comments on commit 7ad82e9

Please sign in to comment.