-
Notifications
You must be signed in to change notification settings - Fork 135
/
methods.t
43 lines (35 loc) · 1.04 KB
/
methods.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use v6;
use Test;
plan 8;
grammar WithMethod {
rule TOP { 'lorem' | <.panic> }
method panic { die "The sky is falling!"; }
};
dies-ok { WithMethod.parse('unrelated') },
'Can call die() from a method within a grammar';
try { WithMethod.parse('unrelated') };
ok "$!" ~~ /'The sky is falling!'/, 'and got the exception message';
my $x = 0;
grammar WithOuterLex {
regex TOP { x { $x = 42 } }
}
WithOuterLex.parse('xxx');
is $x, 42, 'regex in a grammar can see outer lexicals';
grammar WithAttrib {
has Str $.sep;
}
# RT #73680
is WithAttrib.new(sep => ',').sep, ',', 'attributes work in grammars too';
isa-ok WithAttrib.new.sep, Str, 'empty attribute intilized to Str';
# RT #113552
{
try { EVAL 'grammar A { token a { ... }; token a { ... } }' };
my $error = ~$!;
ok $error ~~ /:i 'already has a Regex \'a\'' /, "duplicate methods err sanely";
}
# RT #125169
{
grammar D { our token doo { doo }; };
ok 'doo' ~~ &D::doo, 'our token as rhs of smartmatch';
ok 'doo' ~~ / <&D::doo> /, 'our token in regey assertion';
}