Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (58 sloc) 2.685 kB
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
1 use v6;
2 use Test;
3
37a17ea @hoelzro Test closure parameters without calling the parameter
hoelzro authored
4 plan 17;
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
5
6 # L<S06/Closure parameters>
7
8 {
9 my sub testit (&testcode) {testcode()}
10
11 ok(testit({return 1}), 'code executes as testsub({...})');
12
13 my $code = {return 1};
14 ok(testit($code), 'code executes as testsub($closure)');
15
16 my sub returntrue {return 1}
17 ok(testit(&returntrue), 'code executes as testsub(&subroutine)');
18 }
19
20 # with a signature for the closure
21 {
22 my sub testit (&testcode:(Int)) {testcode(12)}
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
23 my sub testint(Int $foo) {return 1} #OK not used
24 my sub teststr(Str $foo) {return 'foo'} #OK not used
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
25
37a17ea @hoelzro Test closure parameters without calling the parameter
hoelzro authored
26 my sub test-but-dont-call(&testcode:(Int)) { True }
27
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
28 ok(testit(&testint), 'code runs with proper signature (1)');
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
29 eval-dies-ok('testit(&teststr)', 'code dies with invalid signature (1)');
37a17ea @hoelzro Test closure parameters without calling the parameter
hoelzro authored
30
31 ok(test-but-dont-call(&testint), 'code runs with proper signature (1)');
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
32 eval-dies-ok('test-but-dont-call(&teststr)', 'code dies with invalid signature (1)');
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
33 }
34
35 {
c21309d [t/spec] when our closure parameter requires and Int, we should give …
moritz authored
36 my sub testit (&testcode:(Int --> Bool)) {testcode(3)}
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
37 my Bool sub testintbool(Int $foo) {return Bool::True} #OK not used
38 my Bool sub teststrbool(Str $foo) {return Bool::False} #OK not used
39 my Int sub testintint (Int $foo) {return 1} #OK not used
40 my Int sub teststrint (Str $foo) {return 0} #OK not used
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
41
42 ok(testit(&testintbool), 'code runs with proper signature (2)');
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
43 eval-dies-ok('testit(&testintint)', 'code dies with invalid signature (2)');
44 eval-dies-ok('testit(&teststrbool)', 'code dies with invalid signature (3)');
45 eval-dies-ok('testit(&teststrint)', 'code dies with invalid signature (4)');
86188d0 [gsoc_spectest] new test for closure parameters. (added 9 tests)
Auzon authored
46 }
c21309d [t/spec] when our closure parameter requires and Int, we should give …
moritz authored
47
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
48 #?rakudo skip 'subsignatures dont factor into multi candidates yet RT #124935'
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
49 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
50 multi sub t1 (&code:(Int)) { 'Int' }; #OK not used
51 multi sub t1 (&code:(Str)) { 'Str' }; #OK not used
52 multi sub t1 (&code:(Str --> Bool)) { 'Str --> Bool' }; #OK not used
53 multi sub t1 (&code:(Any, Any)) { 'Two' }; #OK not used
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
54
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
55 is t1(-> $a, $b { }), 'Two', #OK not used
e2cac8b [closure-parameters.t] missing semicolons
lwall authored
56 'Multi dispatch based on closure parameter syntax (1)';
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
57 is t1(-> Int $a { }), 'Int', #OK not used
e2cac8b [closure-parameters.t] missing semicolons
lwall authored
58 'Multi dispatch based on closure parameter syntax (2)';
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
59 is t1(-> Str $a { }), 'Str', #OK not used
e2cac8b [closure-parameters.t] missing semicolons
lwall authored
60 'Multi dispatch based on closure parameter syntax (3)';
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
61
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
62 sub takes-str-returns-bool(Str $x --> Bool) { True } #OK not used
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
63 is t1(&takes-str-returns-bool), 'Str --> Bool',
e2cac8b [closure-parameters.t] missing semicolons
lwall authored
64 'Multi dispatch based on closure parameter syntax (4)';
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
65
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
66 dies-ok { t1( -> { 3 }) },
e2cac8b [closure-parameters.t] missing semicolons
lwall authored
67 'Multi dispatch based on closure parameter syntax (5)';
5ab90cf [t/spec] test multi dispatch over the signature of closure parameters
moritz authored
68 }
69
6483dc6 [t/spec] test for RT #69240, &a as a named parameter
moritz authored
70 {
71 sub foo(:&a) { bar(:&a) }
72 sub bar(*%_) { "OH HAI" }
73 is foo(), 'OH HAI', 'can use &a as a named parameter';
74 }
75
c21309d [t/spec] when our closure parameter requires and Int, we should give …
moritz authored
76 # vim: ft=perl6
Something went wrong with that request. Please try again.