Browse files

[t/spec] exercise bare "oh I feel so Haskell" sigils in signatures

git-svn-id: http://svn.pugscode.org/pugs@25696 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent b71bf8f commit 502162b2fbf59385628ca2792198e1016e442acb moritz committed Mar 4, 2009
Showing with 47 additions and 2 deletions.
  1. +19 −1 S06-multi/type-based.t
  2. +15 −1 S06-signature/arity.t
  3. +13 −0 S06-signature/positional.t
View
20 S06-multi/type-based.t
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 26;
+plan 32;
# type based dispatching
#
@@ -98,5 +98,23 @@ is(mmd(1..3), 2, 'Slurpy MMD to listop via list');
is m(1, 1), 0, 'subset types involving mulitple parameters (success)';
}
+{
+ multi f2 ($) { 1 };
+ multi f2 ($, $) { 2 };
+ multi f2 ($, $, $) { 3 };
+ multi f2 ($, $, @) { '3+' };
+ is f2(3), 1, 'arity-based dispatch to ($)';
+ is f2('foo', f2(3)), 2, 'arity-based dispatch to ($, $)';
+ #?rakudo 2 skip 'multi dispatch based on sigils'
+ is f2('foo', 4, 8), 3, 'arity-based dispatch to ($, $, $)';
+ is f2('foo', 4, <a b>), '3+', 'arity-based dispatch to ($, $, @)';
+}
+
+{
+ multi f3 ($ where 0 ) { 1 };
+ multi f3 ($x) { $x + 1 };
+ is f3(0), 1, 'can dispatch to "$ where 0"';
+ is f3(3), 4, '... and the ordinary dispatch still works';
+}
# vim: ft=perl6
View
16 S06-signature/arity.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 20;
+plan 25;
# L<S06/Required parameters/method:>
sub a_zero () { };
@@ -25,6 +25,20 @@ is &o_zero.arity, 0, 'arity 0 sub with optional params';
is &o_one.arity, 1, 'arity 1 sub with optional params';
is &o_two.arity, 2, 'arity with optional and required named params';
+{
+ sub b_zero () { };
+ sub b_one ($a) { };
+ sub b_two ($a, $b) { };
+ sub b_three ($a, $b, @c) { };
+ sub b_four ($a, $b, @c, %d) { };
+ is &b_zero.arity, 0, '0 arity &sub';
+ is &b_one.arity, 1, '1 arity &sub';
+ is &b_two.arity, 2, '2 arity &sub';
+ is &b_three.arity, 3, '3 arity &sub';
+ is &b_four.arity, 4, '4 arity &foo';
+
+}
+
# It's not really specced in what way (*@slurpy_params) should influence
# .arity. Also it's unclear what the result of &multisub.arity is.
# See the thread "&multisub.arity?" on p6l started by Ingo Blechschmidt for
View
13 S06-signature/positional.t
@@ -0,0 +1,13 @@
+use v6;
+use Test;
+plan 3;
+
+sub my_first ($x, $, $ ) { $x };
+sub my_second ($, $x, $ ) { $x };
+sub my_third ($, $, $x) { $x };
+
+is my_first( 4, 5, 6), 4, '($x, $, $) works as a signature';
+is my_second(4, 5, 6), 5, '($, $x, $) works as a signature';
+is my_third( 4, 5, 6), 6, '($, $, $x) works as a signature';
+
+# vim: ft=perl6

0 comments on commit 502162b

Please sign in to comment.