Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (57 sloc) 2.297 kb
86188d07 »
2008-08-17 [gsoc_spectest] new test for closure parameters. (added 9 tests)
1 use v6;
2 use Test;
3
6483dc63 »
2010-03-11 [t/spec] test for RT #69240, &a as a named parameter
4 plan 15;
86188d07 »
2008-08-17 [gsoc_spectest] new test for closure parameters. (added 9 tests)
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
b1595479 »
2009-01-25 [t] and [t/spec]
21 #?rakudo skip 'type syntax parse failure'
86188d07 »
2008-08-17 [gsoc_spectest] new test for closure parameters. (added 9 tests)
22 {
23 my sub testit (&testcode:(Int)) {testcode(12)}
24 my sub testint(Int $foo) {return 1}
25 my sub teststr(Str $foo) {return 'foo'}
26
27 ok(testit(&testint), 'code runs with proper signature (1)');
28 eval_dies_ok('testit(&teststr)', 'code dies with invalid signature (1)');
29 }
30
b1595479 »
2009-01-25 [t] and [t/spec]
31 #?rakudo skip 'type syntax parse failure'
86188d07 »
2008-08-17 [gsoc_spectest] new test for closure parameters. (added 9 tests)
32 {
c21309df »
2009-08-02 [t/spec] when our closure parameter requires and Int, we should give …
33 my sub testit (&testcode:(Int --> Bool)) {testcode(3)}
86188d07 »
2008-08-17 [gsoc_spectest] new test for closure parameters. (added 9 tests)
34 my Bool sub testintbool(Int $foo) {return Bool::True}
35 my Bool sub teststrbool(Str $foo) {return Bool::False}
36 my Int sub testintint (Int $foo) {return 1}
37 my Int sub teststrint (Str $foo) {return 0}
38
39 ok(testit(&testintbool), 'code runs with proper signature (2)');
40 eval_dies_ok('testit(&testintint)', 'code dies with invalid signature (2)');
41 eval_dies_ok('testit(&teststrbool)', 'code dies with invalid signature (3)');
42 eval_dies_ok('testit(&teststrint)', 'code dies with invalid signature (4)');
43 }
c21309df »
2009-08-02 [t/spec] when our closure parameter requires and Int, we should give …
44
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
45 #?rakudo skip 'type syntax parse failure'
46 {
47 multi sub t1 (&code:(Int)) { 'Int' };
48 multi sub t1 (&code:(Str)) { 'Str' };
49 multi sub t1 (&code:(Str --> Bool)) { 'Str --> Bool' };
50 multi sub t1 (&code:(Any, Any)) { 'Two' };
51
52 is t1(-> $a, $b { }), 'Two',
e2cac8bc »
2009-08-05 [closure-parameters.t] missing semicolons
53 'Multi dispatch based on closure parameter syntax (1)';
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
54 is t1(-> Int $a { }), 'Int',
e2cac8bc »
2009-08-05 [closure-parameters.t] missing semicolons
55 'Multi dispatch based on closure parameter syntax (2)';
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
56 is t1(-> Str $a { }), 'Str',
e2cac8bc »
2009-08-05 [closure-parameters.t] missing semicolons
57 'Multi dispatch based on closure parameter syntax (3)';
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
58
59 sub takes-str-returns-bool(Str $x --> Bool) { True }
60 is t1(&takes-str-returns-bool), 'Str --> Bool',
e2cac8bc »
2009-08-05 [closure-parameters.t] missing semicolons
61 'Multi dispatch based on closure parameter syntax (4)';
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
62
63 dies_ok { t1( -> { 3 }) },
e2cac8bc »
2009-08-05 [closure-parameters.t] missing semicolons
64 'Multi dispatch based on closure parameter syntax (5)';
5ab90cfb »
2009-08-02 [t/spec] test multi dispatch over the signature of closure parameters
65 }
66
6483dc63 »
2010-03-11 [t/spec] test for RT #69240, &a as a named parameter
67 {
68 sub foo(:&a) { bar(:&a) }
69 sub bar(*%_) { "OH HAI" }
70 is foo(), 'OH HAI', 'can use &a as a named parameter';
71 }
72
c21309df »
2009-08-02 [t/spec] when our closure parameter requires and Int, we should give …
73 # vim: ft=perl6
Something went wrong with that request. Please try again.