Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 57 lines (44 sloc) 1.287 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
f341480 [t/spec] more warning suppressions; remaining STD warnings are mostly bu...
lwall authored
24 sub tester2(&my_sub) { 1 } #OK not used
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
25 #?niecza todo
ae9d8ff @moritz fudge and correct tests
moritz authored
26 dies_ok {eval 'tester2(42)' }, "can't pass thing that doesn't do Callable";
067f36e [t/spec] correct a test in code.t, and add another one for RT #62432
moritz authored
27
28 sub not_returns_a_sub { 3 };
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
29 #?niecza todo
ae9d8ff @moritz fudge and correct tests
moritz authored
30 dies_ok { eval 'tester2(not_returns_a_sub)' },
067f36e [t/spec] correct a test in code.t, and add another one for RT #62432
moritz authored
31 "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
32
b7487a7 [t/spec] Test for RT #68578
kyle authored
33 is tester2({ 'block' }), 1, 'Can pass a block to a &parameter';
34
35 # RT #68578
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
36 #?niecza todo
b7487a7 [t/spec] Test for RT #68578
kyle authored
37 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
38 sub rt68578( Callable &x ) {} #OK not used
28f9ab0 Fix test description (jnthn++)
kyle authored
39 dies_ok { rt68578({ 'block' }) },
40 "Can't pass something that isn't typed as returning Callable";
b7487a7 [t/spec] Test for RT #68578
kyle authored
41 }
42
ff7d3bf [t/spec] test for RT #67932
moritz authored
43 # RT #67932
44 {
45 my $tracker;
46 sub foo(&foo = &foo) {
47 $tracker = &foo
48 };
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
49 #?niecza todo
ae9d8ff @moritz fudge and correct tests
moritz authored
50 #?rakudo todo 'RT 67932'
ff7d3bf [t/spec] test for RT #67932
moritz authored
51 lives_ok { foo },
52 'can call a sub with a code object defaulting to something of its own name';
53 ok !$tracker.defined, 'the inner &foo is undefined (scoping)';
54 }
55
65d39ea [t/spec] tests for code objects in signatures
moritz authored
56 # vim: ft=perl6
Something went wrong with that request. Please try again.