Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (86 sloc) 3.077 kB
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
5 plan 17;
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
6
7 =begin description
8
9 Test pointy sub behaviour described in S06
10
11 =end description
12
f97d4fb [t/spec] fix two smartlinks
moritz authored
13 # L<S06/""Pointy blocks""/"parameter list of a pointy block does not require
14 # parentheses">
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
15 my ($sub, $got);
16
17 $got = '';
18 $sub = -> $x { $got = "x $x" };
19 $sub.(123);
20 is $got, 'x 123', 'pointy sub without param parens';
21
22 $got = '';
23 -> $x { $got = "x $x" }.(123);
24 is $got, 'x 123', 'called pointy immediately: -> $x { ... }.(...)';
25
26 $got = '';
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
27 -> $x { $got = "x $x" }(123);
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
28 is $got, 'x 123', 'called pointy immediately: -> $x { ... }(...)';
29
30
31 # L<S04/Statement-ending blocks/End-of-statement cannot occur within a bracketed expression>
32 my @a;
297e783 [t] and [t/spec]
moritz authored
33 lives_ok { @a = ("one", -> $x { $x**2 }, "three")} ,
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
34 'pointy sub without preceding comma';
35 is @a[0], 'one', 'pointy sub in list previous argument';
207f13f [t] and [t/spec]
moritz authored
36 isa_ok @a[1], Code, 'pointy sub in list';
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
37 is @a[2], 'three', 'pointy sub in list following argument';
38
39
40 # L<S06/""Pointy blocks""/behaves like a block with respect to control exceptions>
41 my $n = 1;
42 my $s = -> {
43 last if $n == 10;
44 $n++;
45 redo if $n < 10;
46 };
aed8452 @moritz fix a test, rakudo unfudges
moritz authored
47 dies_ok $s, 'pointy with block control exceptions';
af7627e @jnthn Another unfudge.
jnthn authored
48 #?rakudo todo 'pointy blocks and last/redo'
8032449 @colomon Fudge for niecza.
colomon authored
49 #?niecza todo
e4b089d @coke pugs fudges
coke authored
50 #?pugs todo
8c80d2b [pointy.t] unmatched right paren found by STD
lwall authored
51 is $n, 10, "pointy control exceptions ran";
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
52
53 # L<S06/""Pointy blocks""/will return from the innermost enclosing sub or method>
54 my $str = '';
55
56 sub outer {
57 my $s = -> {
297e783 [t] and [t/spec]
moritz authored
58 #?rakudo skip '&?ROUTINE'
cf47754 @coke niecza autounfudge
coke authored
59 #?niecza todo 'Unable to resolve method name in class Sub'
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
60 is(&?ROUTINE.name, '&Main::outer', 'pointy still sees outer\'s &?ROUTINE');
61
62 $str ~= 'inner';
63 return 'inner ret';
64 };
65 $s.();
66 $str ~= 'outer';
67 return 'outer ret';
68 }
69
70 is outer(), 'inner ret', 'return in pointy returns from enclosing sub';
71 is $str, 'inner', 'return in pointy returns from enclosing sub';
72
73 # What about nested pointies -> { ... -> {} }?
74
75
76 # L<S06/""Pointy blocks""/It is referenced>
77 # Coming soon...
78
79
80 # -> { $^a, $^b } is illegal; you can't mix real sigs with placeholders,
81 # and the -> introduces a sig of (). TimToady #perl6 2008-May-24
e4b089d @coke pugs fudges
coke authored
82 #?pugs todo
297e783 [t] and [t/spec]
moritz authored
83 eval_dies_ok(q{{ -> { $^a, $^b } }}, '-> { $^a, $^b } is illegal');
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
84
1a356d7 [t/spec] tests for RT #61034
moritz authored
85 # RT #61034
86
87 lives_ok {my $x = -> {}; my $y = $x(); },
88 'can define and execute empty pointy block';
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
89
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
90 # The default type of pointy blocks is Mu, not Any. See
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
91 # http://www.nntp.perl.org/group/perl.perl6.language/2009/03/msg31181.html
1ce71f2 [t/spec] more smartlink fixes
moritz authored
92 # L<S02/Undefined types/default block parameter type>
ffa7511 [t/spec/] "Junction" -> "junction", ".eigenstates" -> "!eigenstates" …
Kodi authored
93 # this means that junctions don't autothread over pointy blocks
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
94
929d8e4 [t/spec] fudge junction test Rakudo no longer runs
kyle authored
95 #?rakudo skip 'Could not find non-existent sub junction'
8032449 @colomon Fudge for niecza.
colomon authored
96 #?niecza skip 'Could not find non-existent sub junction'
e4b089d @coke pugs fudges
coke authored
97 #?pugs skip 'No such subroutine: "&junction'
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
98 {
99 my @a = any(3, 4);
100 my $ok = 0;
101 my $iterations = 0;
102 for @a -> $x {
ffa7511 [t/spec/] "Junction" -> "junction", ".eigenstates" -> "!eigenstates" …
Kodi authored
103 $ok = 1 if $x ~~ junction;
7ba0e44 [t/spec] fix test added in previous commit; properly fudge for rakudo
moritz authored
104 $iterations++;
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
105 }
a266302 [t/spec] Unfudge block default parameter type tests for Rakudo.
jnthn authored
106 ok $ok, 'Blocks receive junctions without autothreading';
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
107 is $iterations, 1, 'no autothreading happened';
108 my $b = -> $x { ... };
a266302 [t/spec] Unfudge block default parameter type tests for Rakudo.
jnthn authored
109 ok $b.signature.perl !~~ /Any/,
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
110 'The .signature of a block does not contain Any';
111 }
112
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
113 # vim: ft=perl6
1a356d7 [t/spec] tests for RT #61034
moritz authored
114
Something went wrong with that request. Please try again.