-
Notifications
You must be signed in to change notification settings - Fork 15
/
test2.pl
109 lines (95 loc) · 2.39 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
101
102
103
104
105
106
107
108
109
# vim: ft=perl6
use Test;
use MONKEY_TYPING;
{
my $str;
INIT $str = '';
$str ~= 1;
INIT $str ~= 2;
$str ~= 3;
INIT $str ~= 4;
is $str, '2413', 'INIT blocks run in correct order';
}
{
my class X3 {
has $.a;
}
my $x = X3.new(a => 5);
is $x.a, 5, 'Attribute values can be passed in constructors';
sub foo($/) { $<a> }
is foo({ a => 5 }), 5, 'Can bind $/ in signature';
my class X4 {
method foo { 13 }
method !bar { 17 }
method sam($x) { self!"$x"() }
}
is X4."foo"(), 13, 'indirect method calls work'; #OK
is X4."{ "fo" ~ "o" }"(), 13, 'indirect calls work with interpolation';
is X4.sam("bar"), 17, "indirect private method calls work";
}
{
"foo" ~~ /oo/;
is $/.ast, 'oo', '.ast defaults to .Str';
"foo" ~~ /oo { make 15 }/;
is $/.ast, 15, 'make can change .ast';
"foo" ~~ /{make 30} oo/;
is $/.ast, 30, 'make works in the middle';
my grammar X5 {
proto token TOP {*}
token TOP:x { foo { make 45 } }
}
is X5.parse("foo").ast, 45, 'make works in multiregexes';
}
{
my grammar X6 {
token a { <?> }
proto token b {*}
token b:x { <?> }
proto token c {*}
token c:x { <?> }
}
my class A6 {
method a($/) { make 1 }
method b($/) { make 2 }
method c:x ($/) { make 3 }
}
is X6.parse("", :actions(A6), :rule<a>).ast, 1,
'action methods work (simple rule)';
#is X6.parse("", :actions(A6), :rule<b>).ast, 2,
# 'action methods work (proto rule)';
is X6.parse("", :actions(A6), :rule<c>).ast, 3,
'action methods work (candidate rule)';
}
{
my @foo = 1; #OK
my $tgt; #OK
my %into;
$tgt = %into<foo> = True;
ok %into<foo>, "2011-01-13 list assignment parsefail";
}
#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;