Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (39 sloc) 1.165 kb
65d39ea [t/spec] tests for code objects in signatures
moritz authored
1 use v6;
2 use Test;
ff7d3bf [t/spec] test for RT #67932
moritz authored
3 plan 8;
65d39ea [t/spec] tests for code objects in signatures
moritz authored
4
3caeec0 [t/spec] Added a smartlink and a future move order TODO ;-)
azawawi authored
5 # TODO: move this test to closure-parameters.t if it works in the future
6
7 # L<S06/Closure parameters>
65d39ea [t/spec] tests for code objects in signatures
moritz authored
8
9 our $collector = 2;
10 sub to_be_called($x) {
11 $collector += $x;
12 }
13
14 sub tester(&my_sub) {
15 my_sub(4);
16 }
17
18 tester(&to_be_called);
19 ok $collector == 6, 'Can call my_sub() if &my_sub was a parameter';
20
21 tester(sub ($x) { $collector = 3 * $x });
22 ok $collector == 12, 'same with anonymous sub';
23
02f7b85 [t/spec] Add a test to make sure if we declare something with the & sigi...
jnthn authored
24 sub tester2(&my_sub) { 1 }
067f36e [t/spec] correct a test in code.t, and add another one for RT #62432
moritz authored
25 dies_ok {tester2(42)}, "can't pass thing that doesn't do Callable";
26
27 sub not_returns_a_sub { 3 };
28 dies_ok {tester2(not_returns_a_sub)},
29 "can't pass thing that doesn't do Callable";
02f7b85 [t/spec] Add a test to make sure if we declare something with the & sigi...
jnthn authored
30
b7487a7 [t/spec] Test for RT #68578
kyle authored
31 is tester2({ 'block' }), 1, 'Can pass a block to a &parameter';
32
33 # RT #68578
34 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
35 sub rt68578( Callable &x ) {} #OK not used
28f9ab0 Fix test description (jnthn++)
kyle authored
36 dies_ok { rt68578({ 'block' }) },
37 "Can't pass something that isn't typed as returning Callable";
b7487a7 [t/spec] Test for RT #68578
kyle authored
38 }
39
ff7d3bf [t/spec] test for RT #67932
moritz authored
40 # RT #67932
41 {
42 my $tracker;
43 sub foo(&foo = &foo) {
44 $tracker = &foo
45 };
46 lives_ok { foo },
47 'can call a sub with a code object defaulting to something of its own name';
48 ok !$tracker.defined, 'the inner &foo is undefined (scoping)';
49 }
50
65d39ea [t/spec] tests for code objects in signatures
moritz authored
51 # vim: ft=perl6
Something went wrong with that request. Please try again.