Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 58 lines (45 sloc) 1.9 kb
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
1 use v6;
2 use Test;
734bc95 [t/spec]
moritz authored
3 plan 18;
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
4
7101b98 [t/spec] fix several smartlinks
moritz authored
5 # L<S04/The Relationship of Blocks and Declarations/A bare closure
6 # (except the block associated with a conditional statement)>
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
7
8 {
9 # test with explicit $_
10 my $f1 = { 2*$_ };
1e2c1f0 [t/spec] 11 typos in 6 files.
Util authored
11 is $f1(2), 4, 'Block with explicit $_ has one formal parameter';
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
12 }
13
14 {
15 # test with implicit $_
16 my $f2 = { .sqrt };
13cc9c4 [t/spec] 71 typos in 32 files.
Util authored
17 is_approx $f2(4), 2, 'Block with implicit $_ has one formal parameter';
de174b3 [spec] test for $_ being treated as formal parameter of a block
moritz authored
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');
1e2c1f0 [t/spec] 11 typos in 6 files.
Util authored
29 is({ 42 }.('Goodbye'), 42, '$_ gets assigned but is not used');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
30
734bc95 [t/spec]
moritz authored
31 is(({ $_ }.arity), 0, '{$_} is arity 0, of course');
32 is(({ .say }.arity), 0, 'Blocks that uses $_ implicitly have arity 0');
33 is(({ $_ }.count), 1, '{$_} is count 1');
34 is(({ .say }.count), 1, 'Blocks that uses $_ implicitly have count 1');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
35 }
36
37 {
734bc95 [t/spec]
moritz authored
38 #?pugs 4 todo 'pointy blocks'
39 $_ = 'Ack';
40 dies_ok({ (-> { "Boo!" }).(42) }, '-> {} is arity 0');
41 dies_ok({ (-> { $_ }).(42) }, 'Even when we use $_>');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
42
48fe727 [t/spec] more unfudges
moritz authored
43 #?rakudo 2 todo 'pointy blocks and $_'
734bc95 [t/spec]
moritz authored
44 is((-> { $_ }).(), 'Ack!', '$_ is lexical here');
45 is(-> $a { $_ }.(42), 'Ack!', 'Even with parameters (?)');
46 is(-> $_ { $_ }.(42), 42, 'But not when the parameter is $_');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
47
2136dcb [implicit-parameter.t] placeholder conflict requires eval_die_ok
lwall authored
48 eval_dies_ok( 'sub () { -> { $^a }.() }', 'Placeholders not allowed in ->');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
49
50 is(-> { }.arity, 0, '->{} is arity 0, again');
51 }
52
53 {
d269ab0 [t/spec] s/dies_ok/eval_dies_ok/ on a test that will fail at compile tim...
moritz authored
54 eval_dies_ok('sub { $^foo }.(42)', 'Placeholders not allowed in sub()');
4ced1fc [t] merge blocks/implicit_parameters.t into spec/
moritz authored
55 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
56
57 # vim: ft=perl6
Something went wrong with that request. Please try again.