/
test2.pl
48 lines (43 loc) · 1.12 KB
/
test2.pl
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
44
45
46
47
48
# vim: ft=perl6
use Test;
{
use MONKEY_TYPING;
my class Foo {
method foo { 1 }
}
is Foo.foo, 2, "augments run early";
is Any.g4077, 4077, "can augment core classes";
is Cool.g4077, 4077, "augments visible in subclasses";
augment class Foo {
method foo { 2 }
}
augment class Any {
method g4077 { 4077 }
}
}
use MONKEY_TYPING;
augment class Match {
method at-key($k) { Q:CgOp {
(rawcall (cast Cursor (@ {self})) GetKey (unbox String (@ {$k.Str})))
} }
method at-pos($i) { self.at-key($i) }
}
augment class Cursor {
method at-key($k) { Q:CgOp {
(rawcall (cast Cursor (@ {self})) GetKey (unbox String (@ {$k.Str})))
} }
method at-pos($i) { self.at-key($i) }
}
{
my $ma = (grammar {
regex TOP { <foo> <bar> }
regex foo { \d+ }
regex bar { \w+ }
}).parse("123abc");
ok $ma<foo> ~~ Match, "<foo> sub is a Match";
is $ma<foo>, "123", "<foo> sub got 123";
ok $ma<bar> ~~ Match, "<bar> sub is a Match";
is $ma<bar>, "abc", "<bar> sub got 123";
ok !$ma<quux>, "no <quux> sub";
}
done-testing;