Permalink
Browse files

[t/spec] more tests for passing optional arguments

git-svn-id: http://svn.pugscode.org/pugs@24500 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent cc196ec commit 6533150ef2a771b471c6b50de90f6a6e7992b4f6 moritz committed Dec 19, 2008
Showing with 22 additions and 1 deletion.
  1. +22 −1 S06-signature/optional.t
View
23 S06-signature/optional.t
@@ -1,13 +1,34 @@
use v6;
use Test;
-plan 4;
+plan 10;
sub opt1($p?) { defined($p) ?? $p !! 'undef'; }
is opt1('abc'), 'abc', 'Can pass optional param';
is opt1(), 'undef', 'Can leave out optional param';
+sub opt2($p?, $q?) {
+ (defined($p) ?? $p !! 'undef')
+ ~ '|'
+ ~ (defined($q) ?? $q !! 'undef');
+}
+
+is opt2('a', 'b'), 'a|b', 'Can pass all two optional params';
+is opt2('a'), 'a|undef', 'Can pass one of two optional params';
+is opt2(), 'undef|undef', 'Can leave out all two optional params';
+
+sub t_opt2(Str $p?, Str $q?) {
+ (defined($p) ?? $p !! 'undef')
+ ~ '|'
+ ~ (defined($q) ?? $q !! 'undef');
+}
+
+#?rakudo 3 skip 'optional typed params, RT #61528'
+is t_opt2('a', 'b'), 'a|b', 'Can pass all two optional params';
+is t_opt2('a'), 'a|undef', 'Can pass one of two optional params';
+is t_opt2(), 'undef|undef', 'Can leave out all two optional params';
+
sub opt_typed(Int $p?) { defined($p) ?? $p !! 'undef' };
is opt_typed(2), 2, 'can pass optional typed param';

0 comments on commit 6533150

Please sign in to comment.