/
test2.pl
100 lines (89 loc) · 2.43 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# vim: ft=perl6
use Test;
use MONKEY_TYPING;
augment class Cursor {
method suppose($rx) {
my $*IN_SUPPOSE = True;
my $*FATALS = 0;
my @*WORRIES;
my %*WORRIES;
my $*HIGHWATER = -1;
my $*HIGHEXPECT = {};
try {
my @ret := $rx(self);
if (@ret) { return @( self, ) }
};
return ();
}
}
{
my $m = "ab" ~~ / (.) <alpha> /;
is (@$m)[0], "a", "Match.list returns positional captures";
is (%$m)<alpha>, "b", "Match.hash returns named";
is ((-> $p, :$alpha { $p, $alpha })(|$m)).join("|"), "a|b", "Match.Capture returns both";
my @arr = "abc" ~~ / (.) (.) (.) /;
is @arr.join("|"), "a|b|c", "Regex.ACCEPTS in list context returns captures";
$m = "" ~~ / <O( foo => 2 )> /;
is $m<O><foo>, 2, "<O> is functional";
$m = (grammar {
proto token TOP {*}
token TOP:foo { <sym> }
}).parse("foo");
is $m<sym>, "foo", '$<sym> is functional';
ok !(try die "foo").defined, "try of an error is undef";
is $!, "foo", 'the error goes into $!';
{
my @*foo = 1, 2, 3;
{
temp @*foo;
push @*foo, 4;
is +@*foo, 4, '@*foo has 4 elements in temp scope';
}
is +@*foo, 3, '@*foo has 3 elements again after temp';
}
my @ar = [1, 2, 3];
is +@ar, 1, "array constructors are singular";
my $i = 0;
$i++ until $i == 10;
is $i, 10, "until loops functional";
ok "foo" !~~ / f <.suppose { die }> /, ".suppose works (F)";
ok "foo" ~~ / f <.suppose o> oo /, ".suppose works (T)";
}
# {
# our role Stop4717[$a] {
# token foo { $a }
# }
#
# grammar X {
# token TOP { [ <foo> | foo ]: x }
# }
#
# ok (X but OUR::Stop4717["foobar"]).parse("foobarx"),
# "LTM works through parameterized role variables";
# }
#is $?FILE, 'test.pl', '$?FILE works';
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
# {
# {
# our $x = 5; #OK
# }
# ok $::x == 5, '$::x finds our variable';
#
# package Fao { our $y = 6; } #OK
# ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
#
# { class Mao { } }
# ok ::Mao.new.defined, 'can use classes via ::Mao';
# }
#
# {
# my $x = 7; #OK
# ok $::x == 7, '$::x can find lexicals';
# class A3 {
# method moo { 42 }
# class B4 {
# ok ::A3.moo, '::A3 can find outer classes';
# }
# }
# }
done-testing;