Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

84 lines (61 sloc) 2.279 kb
use v6;
# Test control blocks (BEGIN/CHECK/INIT/END) used as rvalues
# [TODO] add tests for other control blocks
use Test;
plan 16;
# L<S04/Phasers/"marked with a *" "used within" expression>
{
my $x = BEGIN { 8 };
is $x, 8, 'BEGIN block as expression';
# test that built-ins are available within a BEGIN block:
my $y = BEGIN { uc 'moin' };
is $y, 'MOIN', 'can access built-in functions in BEGIN blocks';
my $z = BEGIN { 'moin'.uc };
is $z, 'MOIN', 'can access built-in methods in BEGIN blocks';
}
{
my $x = BEGIN 8;
is $x, 8, 'BEGIN statement prefix as expression';
# test that built-ins are available within a BEGIN block:
my $y = BEGIN uc 'moin';
is $y, 'MOIN', 'can access built-in functions in BEGIN statement prefix';
my $z = BEGIN 'moin'.uc;
is $z, 'MOIN', 'can access built-in methods in BEGIN statement prefix';
}
{
my $hist; # DO NOT INITIALIZE HERE! (my runs after these blocks)
# Test INIT {} as rval:
my $init_val;
my $init = {
$init_val = INIT { '' ~ ($hist ~= 'I') };
}
#?niecza todo 'block returns no value'
is $init(), 'BCI', 'INIT {} runs only once';
#?niecza todo 'block returns no value'
is $init_val, 'BCI', 'INIT {} as rval is its ret val';
#?niecza todo 'block returns no value'
is $init(), 'BCI', 'INIT {} runs only once';
# Test CHECK {} as rval:
my $check_val;
my $check = {
$check_val = CHECK { '' ~ ($hist ~= 'C') };
}
#?niecza todo 'block returns no value'
is $check(), 'BC', 'CHECK {} runs only once';
#?niecza todo 'block returns no value'
is $check_val, 'BC', 'CHECK {} as rval is its ret val';
#?niecza todo 'block returns no value'
is $check(), 'BC', 'CHECK {} runs only once';
# Test BEGIN {} as rval:
my $begin_val;
my $begin = {
$begin_val = BEGIN { '' ~ ($hist ~= 'B') };
}
is $begin(), 'B', 'BEGIN {} runs only once';
is $begin_val, 'B', 'BEGIN {} as rval is its ret val';
is $begin(), 'B', 'BEGIN {} runs only once';
# Test END {} as rval:
#?niecza skip 'Excess arguments to EVAL, used 1 of 2 positionals'
ok !EVAL('my $end_val = END { 3 }'), "END {} can't be used as a rvalue";
}
# vim: ft=perl6 expandtab sw=4
Jump to Line
Something went wrong with that request. Please try again.