Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 117 lines (94 sloc) 3.554 kb
4ef6e53f »
2008-12-19 [t/spec] tests for optional parameters, typed and untyped (RT #61528)
1 use v6;
2 use Test;
3
288e0461 »
2008-12-22 [t] and [t/spec]
4 # L<S06/Optional parameters/>
5
2f2567fa »
2012-04-22 RT #79642, optional-but-not-bound hash is just a normal, empty Hash
6 plan 25;
4ef6e53f »
2008-12-19 [t/spec] tests for optional parameters, typed and untyped (RT #61528)
7
8 sub opt1($p?) { defined($p) ?? $p !! 'undef'; }
9
10 is opt1('abc'), 'abc', 'Can pass optional param';
11 is opt1(), 'undef', 'Can leave out optional param';
12
6533150e »
2008-12-19 [t/spec] more tests for passing optional arguments
13 sub opt2($p?, $q?) {
14 (defined($p) ?? $p !! 'undef')
15 ~ '|'
16 ~ (defined($q) ?? $q !! 'undef');
17 }
18
19 is opt2('a', 'b'), 'a|b', 'Can pass all two optional params';
20 is opt2('a'), 'a|undef', 'Can pass one of two optional params';
21 is opt2(), 'undef|undef', 'Can leave out all two optional params';
22
23 sub t_opt2(Str $p?, Str $q?) {
24 (defined($p) ?? $p !! 'undef')
25 ~ '|'
26 ~ (defined($q) ?? $q !! 'undef');
27 }
28
29 is t_opt2('a', 'b'), 'a|b', 'Can pass all two optional params';
30 is t_opt2('a'), 'a|undef', 'Can pass one of two optional params';
31 is t_opt2(), 'undef|undef', 'Can leave out all two optional params';
32
4ef6e53f »
2008-12-19 [t/spec] tests for optional parameters, typed and untyped (RT #61528)
33 sub opt_typed(Int $p?) { defined($p) ?? $p !! 'undef' };
34
35 is opt_typed(2), 2, 'can pass optional typed param';
36 is opt_typed() , 'undef', 'can leave out optional typed param';
37
288e0461 »
2008-12-22 [t] and [t/spec]
38 # L<S06/Parameters and arguments/"required positional parameters must come
39 # before those bound to optional positional">
fa12fffe »
2012-04-15 pugs fudge
40 #?pugs todo
b896f124 »
2011-01-23 [S06-signature/optional.t] Added tests for RT #76022.
41 eval_dies_ok 'sub wrong1 ($a?, $b) {...}', 'optional params before required ones are forbidden';
42 # RT #76022
fa12fffe »
2012-04-15 pugs fudge
43 #?pugs todo
b896f124 »
2011-01-23 [S06-signature/optional.t] Added tests for RT #76022.
44 {
45 eval_dies_ok 'sub wrong2 ($a = 1, $b) {...}', "...even if they're only optional by virtue of a default";
46 eval_dies_ok 'sub wrong3 ($a = 0, $b) {...}', '...and the default is 0';
47 }
288e0461 »
2008-12-22 [t] and [t/spec]
48
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
49 sub foo_53814($w, $x?, :$y = 2) { $w~"|"~$x~"|"~$y };
50 dies_ok {foo_53814(1,Mu,'something_extra',:y(3))},
c013159f »
2009-10-18 [t/spec]: Test descriptions must not contain '#'.
51 'die on too many parameters (was once bug RT 53814)';
9de901a3 »
2009-06-26 [t/spec] Test for RT 54804
52
7256424b »
2010-03-07 Mark failing test as todo
53
9de901a3 »
2009-06-26 [t/spec] Test for RT 54804
54 {
a297d279 »
2010-03-07 Put the sub definition inside the eval to make it callable
55
56 # old test is bogus, nullterm only allowed at the end of a list
57 # is rt54804( 1, , 3, ), '1|undef|3|undef',
58 # 'two commas parse as if undef is between them';
59 eval_dies_ok q/sub rt54804( $v, $w?, $x?, $y? ) {
9de901a3 »
2009-06-26 [t/spec] Test for RT 54804
60 (defined( $v ) ?? $v !! 'undef')
61 ~ '|' ~
62 (defined( $w ) ?? $w !! 'undef')
63 ~ '|' ~
64 (defined( $x ) ?? $x !! 'undef')
65 ~ '|' ~
66 (defined( $y ) ?? $y !! 'undef')
67 }
a297d279 »
2010-03-07 Put the sub definition inside the eval to make it callable
68 rt54804( 1, , 3, )/, "two commas in a row doesn't parse";
9de901a3 »
2009-06-26 [t/spec] Test for RT 54804
69 }
9ff2f3a0 »
2009-11-20 [t/spec] Test for RT 66822: required param after optional param
70
fa12fffe »
2012-04-15 pugs fudge
71 #?pugs todo
9ff2f3a0 »
2009-11-20 [t/spec] Test for RT 66822: required param after optional param
72 eval_dies_ok( 'sub rt66822($opt?, $req) { "$opt, $req" }',
73 "Can't put required parameter after optional parameters" );
74
d09d566c »
2011-09-14 Add tests for Niecza #49
75 # Niecza bug#49
76 sub opt_array1(@x?) { @x.elems }
77 sub opt_array2(@x? is copy) { @x.elems }
78 sub opt_hash1(%x?) { %x.keys.elems }
79 sub opt_hash2(%x? is copy) { %x.keys.elems }
80 is opt_array1(), 0, "optional array not passed is empty";
81 is opt_array2(), 0, "optional array not passed is empty (copy)";
82 is opt_hash1(), 0, "optional hash not passed is empty";
83 is opt_hash2(), 0, "optional hash not passed is empty (copy)";
84
398be5af »
2011-09-30 required params need to come before optional ones (RT #71110)
85 # RT #71110
fa12fffe »
2012-04-15 pugs fudge
86 #?pugs todo
398be5af »
2011-09-30 required params need to come before optional ones (RT #71110)
87 eval_dies_ok 'sub opt($a = 1, $b) { }',
88 'Cannot put required parameter after optional parameters';
d09d566c »
2011-09-14 Add tests for Niecza #49
89
9e7fb12f »
2011-10-01 test type checking of default values, RT #74758
90 # RT #74758
fa12fffe »
2012-04-15 pugs fudge
91 #?pugs todo
9e7fb12f »
2011-10-01 test type checking of default values, RT #74758
92 {
93 sub opt-type1(Int $x?) { $x };
94 ok opt-type1() === Int,
95 'optional param with type constraints gets the right value';
89f0409e »
2012-09-03 warning suppression, mostly "not used"
96 sub opt-type2(Int $x = 'str') { }; #OK not used
04daf2d6 »
2014-01-01 eval => EVAL in S05, S06 and S09
97 dies_ok { EVAL('opt-type2()') }, 'default values are type-checked';
9e7fb12f »
2011-10-01 test type checking of default values, RT #74758
98 }
99
b6538850 »
2011-10-20 test for RT #76728, assigning to optional hash param
100 # RT # 76728
fa12fffe »
2012-04-15 pugs fudge
101 #?pugs skip "Can't modify constant item: VUndef"
b6538850 »
2011-10-20 test for RT #76728, assigning to optional hash param
102 {
103 sub opt-hash(%h?) {
104 %h<a> = 'b';
105 %h
106 }
107 is opt-hash().keys, 'a', 'can assign to optional parameter';
2f2567fa »
2012-04-22 RT #79642, optional-but-not-bound hash is just a normal, empty Hash
108
109 # RT #79642
110 sub opt-hash2(%h?) {
111 %h;
112 }
113 ok opt-hash2() eqv ().hash, 'an optional-but-not-filled hash is just an empty Hash';
b6538850 »
2011-10-20 test for RT #76728, assigning to optional hash param
114 }
115
4ef6e53f »
2008-12-19 [t/spec] tests for optional parameters, typed and untyped (RT #61528)
116 # vim: ft=perl6
Something went wrong with that request. Please try again.