Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (42 sloc) 1.805 kb
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
1 use v6;
2 use Test;
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
3 plan 16;
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
4
5 # L<S04/The Relationship of Blocks and Declarations/"A bare closure without
6 # placeholder arguments that uses $_">
7
8 {
9 # test with explicit $_
10 my $f1 = { 2*$_ };
11 is $f1(2), 4, 'Block with explit $_ has one formal paramter';
12 }
13
14 {
15 # test with implicit $_
16 my $f2 = { .sqrt };
17 is_approx $f2(4), 2, 'Block with implict $_ has one formal parameter';
18 }
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
19
20 {
21 # { } has implicit signature ($_ is rw = $OUTER::_)
22
23 $_ = 'Hello';
436c2ff [t/spec] re-fudged implicit-parameter.t for rakudo
moritz authored
24 #?pugs todo 'feature'
25 #?rakudo skip 'dispatch error (non-catchable)'
26 is(try { { $_ }.() }, 'Hello', '$_ in bare block defaults to outer');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
27 is({ $_ }.('Goodbye'), 'Goodbye', 'but it is only a default');
28 is({ 42 }.(), 42, 'no implicit $_ usage checking');
29 is({ 42 }.('Goodbye'), 42, '$_ gets assigned but isn\'t used');
30
436c2ff [t/spec] re-fudged implicit-parameter.t for rakudo
moritz authored
31 #?rakudo 2 todo 'arity of blocks with $_'
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
32 is(({ $_ }.arity), 1, '{$_} is arity 1, of course');
33 is(({ .say }.arity), 1, 'Blocks that uses $_ implicitly have arity 1');
34 }
35
36 #?rakudo skip 'pointy blocks'
37 {
38 dies_ok(sub () { -> { "Boo!" }.(42) }, '-> {} is arity 0', :todo<feature>);
39 dies_ok(sub () { -> { $_ }.(42) }, 'Even when we use $_', :todo<feature>);
40
41 is(try { $_ = "Ack"; -> { $_ }.() }, 'Ack!', '$_ is lexical here', :todo<feature>);
42 is(-> $a { $_ }.(42), 'Ack!', 'Even with parameters (?)', :todo<feature>);
43 is(-> $_ { $_ }.(42), 42, 'But not when the parameter is $_');
44
45 dies_ok( sub () { -> { $^a }.() }, 'Placeholders not allowed in ->');
46
47 is(-> { }.arity, 0, '->{} is arity 0, again');
48 }
49
50 {
436c2ff [t/spec] re-fudged implicit-parameter.t for rakudo
moritz authored
51 #?rakudo skip 'parse failure'
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
52 dies_ok(sub () { sub { $^foo }.(42) }, 'Placeholders not allowed in sub()');
53 }
Something went wrong with that request. Please try again.