Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 111 lines (82 sloc) 2.913 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 };
47 try { $s.() };
91adc3f [t/spec] more test fixes wrt undef
moritz authored
48 #?pugs todo 'feature'
297e783 [t] and [t/spec]
moritz authored
49 ok(!defined($!), 'pointy with block control exceptions');
af7627e @jnthn Another unfudge.
jnthn authored
50 #?rakudo todo 'pointy blocks and last/redo'
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'
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
59 is(&?ROUTINE.name, '&Main::outer', 'pointy still sees outer\'s &?ROUTINE');
60
61 $str ~= 'inner';
62 return 'inner ret';
63 };
64 $s.();
65 $str ~= 'outer';
66 return 'outer ret';
67 }
68
69 is outer(), 'inner ret', 'return in pointy returns from enclosing sub';
70 is $str, 'inner', 'return in pointy returns from enclosing sub';
71
72 # What about nested pointies -> { ... -> {} }?
73
74
75 # L<S06/""Pointy blocks""/It is referenced>
76 # Coming soon...
77
78
79 # -> { $^a, $^b } is illegal; you can't mix real sigs with placeholders,
80 # and the -> introduces a sig of (). TimToady #perl6 2008-May-24
297e783 [t] and [t/spec]
moritz authored
81 eval_dies_ok(q{{ -> { $^a, $^b } }}, '-> { $^a, $^b } is illegal');
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
82
1a356d7 [t/spec] tests for RT #61034
moritz authored
83 # RT #61034
84
85 lives_ok {my $x = -> {}; my $y = $x(); },
86 'can define and execute empty pointy block';
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
87
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
88 # The default type of pointy blocks is Mu, not Any. See
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
89 # http://www.nntp.perl.org/group/perl.perl6.language/2009/03/msg31181.html
1ce71f2 [t/spec] more smartlink fixes
moritz authored
90 # L<S02/Undefined types/default block parameter type>
ffa7511 [t/spec/] "Junction" -> "junction", ".eigenstates" -> "!eigenstates" …
Kodi authored
91 # this means that junctions don't autothread over pointy blocks
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
92
929d8e4 [t/spec] fudge junction test Rakudo no longer runs
kyle authored
93 #?rakudo skip 'Could not find non-existent sub junction'
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
94 {
95 my @a = any(3, 4);
96 my $ok = 0;
97 my $iterations = 0;
98 for @a -> $x {
ffa7511 [t/spec/] "Junction" -> "junction", ".eigenstates" -> "!eigenstates" …
Kodi authored
99 $ok = 1 if $x ~~ junction;
7ba0e44 [t/spec] fix test added in previous commit; properly fudge for rakudo
moritz authored
100 $iterations++;
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
101 }
a266302 [t/spec] Unfudge block default parameter type tests for Rakudo.
jnthn authored
102 ok $ok, 'Blocks receive junctions without autothreading';
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
103 is $iterations, 1, 'no autothreading happened';
104 my $b = -> $x { ... };
a266302 [t/spec] Unfudge block default parameter type tests for Rakudo.
jnthn authored
105 ok $b.signature.perl !~~ /Any/,
2162eb8 [t/spec] test that pointy block params default to Object
moritz authored
106 'The .signature of a block does not contain Any';
107 }
108
2752f2f [t] moved blocks/pointy.t to spec/
moritz authored
109 # vim: ft=perl6
1a356d7 [t/spec] tests for RT #61034
moritz authored
110
Something went wrong with that request. Please try again.