Permalink
Browse files

[t] merge blocks/implicit_parameters.t into spec/

git-svn-id: http://svn.pugscode.org/pugs@22415 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 65df17e commit 4ced1fcfbf00ab9e30d86a0278ec67d7f4853b35 moritz committed Sep 26, 2008
Showing with 32 additions and 1 deletion.
  1. +32 −1 S04-declarations/implicit-parameter.t
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 2;
+plan 16;
# L<S04/The Relationship of Blocks and Declarations/"A bare closure without
# placeholder arguments that uses $_">
@@ -16,3 +16,34 @@ plan 2;
my $f2 = { .sqrt };
is_approx $f2(4), 2, 'Block with implict $_ has one formal parameter';
}
+
+{
+ # { } has implicit signature ($_ is rw = $OUTER::_)
+
+ $_ = 'Hello';
+ is(try { { $_ }.() }, 'Hello', '$_ in bare block defaults to outer', :todo<feature>);
+ is({ $_ }.('Goodbye'), 'Goodbye', 'but it is only a default');
+ is({ 42 }.(), 42, 'no implicit $_ usage checking');
+ is({ 42 }.('Goodbye'), 42, '$_ gets assigned but isn\'t used');
+
+ is(({ $_ }.arity), 1, '{$_} is arity 1, of course');
+ is(({ .say }.arity), 1, 'Blocks that uses $_ implicitly have arity 1');
+}
+
+#?rakudo skip 'pointy blocks'
+{
+ dies_ok(sub () { -> { "Boo!" }.(42) }, '-> {} is arity 0', :todo<feature>);
+ dies_ok(sub () { -> { $_ }.(42) }, 'Even when we use $_', :todo<feature>);
+
+ is(try { $_ = "Ack"; -> { $_ }.() }, 'Ack!', '$_ is lexical here', :todo<feature>);
+ is(-> $a { $_ }.(42), 'Ack!', 'Even with parameters (?)', :todo<feature>);
+ is(-> $_ { $_ }.(42), 42, 'But not when the parameter is $_');
+
+ dies_ok( sub () { -> { $^a }.() }, 'Placeholders not allowed in ->');
+
+ is(-> { }.arity, 0, '->{} is arity 0, again');
+}
+
+{
+ dies_ok(sub () { sub { $^foo }.(42) }, 'Placeholders not allowed in sub()');
+}

0 comments on commit 4ced1fc

Please sign in to comment.