use Test::More tests => 8 + 18 + 4 + 8 + 11 + 5 + 17;
-use Scope::Upper qw/reap/;
+use Scope::Upper qw/reap UP HERE/;
my $x;
-sub add { local $_; my $y = $_[1]; reap sub { $x += $y }, $_[0] + 1 }
+sub add { local $_; my $y = $_[0]; reap sub { $x += $y } => $_[1] }
$x = 0;
{
is($x, 0, 'start');
{
- add(0, 1);
+ add 1 => HERE;
is($x, 0, '1 didn\'t run');
{
- add(0, 2);
+ add 2 => HERE;
is($x, 0, '1 and 2 didn\'t run');
}
is($x, 2, '1 didn\'t run, 2 ran');
{
- add(0, 4);
+ add 4 => HERE;
is($x, 2, '1 and 3 didn\'t run, 2 ran');
}
is($x, 6, '1 didn\'t run, 2 and 3 ran');
local $_ = 3;
is($_, 3, '$_ has the right value');
{
- add(0, 1);
+ add 1 => HERE;
is($_, 3, '$_ has the right value');
local $_ = 5;
is($x, 0, '1 didn\'t run');
is($_, 5, '$_ has the right value');
{
- add(0, 2);
+ add 2 => HERE;
is($_, 5, '$_ has the right value');
local $_ = 7;
is($_, 7, '$_ has the right value');
{
local $_ = 9;
is($_, 9, '$_ has the right value');
- add(0, 4);
+ add 4 => HERE;
local $_ = 11;
is($_, 11, '$_ has the right value');
is($x, 2, '1 and 3 didn\'t run, 2 ran');
{
is($x, 0, 'start');
{
- add(0, 1);
- add(0, 2);
+ add 1 => HERE;
+ add 2 => HERE;
is($x, 0, '1 and 2 didn\'t run');
}
is($x, 3, '1 and 2 ran');
local $_ = 3;
{
local $_ = 5;
- add(0, 1);
+ add 1 => HERE;
is($_, 5, '$_ has the right value');
local $_ = 7;
- add(0, 2);
+ add 2 => HERE;
is($_, 7, '$_ has the right value');
is($x, 0, '1 and 2 didn\'t run');
local $_ = 9;
is($x, 0, 'start');
{
{
- add(1, 1);
+ add 1 => UP;
is($x, 0, '1 didn\'t run');
}
is($x, 0, '1 didn\'t run');
{
{
{
- add(2, 2);
+ add 2 => UP UP;
is($x, 1, '2 didn\'t run');
}
is($x, 1, '2 didn\'t run');
{
- add(1, 4);
+ add 4 => UP;
is($x, 1, '2 and 3 didn\'t run');
}
is($x, 1, '2 and 3 didn\'t run');
}
is($x, 7, 'end');
-sub bleh { add(1, 2); }
+sub bleh { add 2 => UP; }
$x = 0;
{
is($x, 0, 'start');
{
- add(0, 1);
+ add 1 => HERE;
is($x, 0, '1 didn\'t run');
bleh();
is($x, 0, '1 didn\'t run');
sub bar {
is($_, 7, '$_ has the right value');
local $_ = 9;
- add(2, 4);
+ add 4 => UP UP;
is($_, 9, '$_ has the right value');
- add(3, 8);
+ add 8 => UP UP UP;
is($_, 9, '$_ has the right value');
}
sub foo {
local $_ = 7;
- add(0, 2);
+ add 2 => HERE;
is($_, 7, '$_ has the right value');
is($x, 0, '1, 2 didn\'t run');
bar();
is($x, 0, '1, 2, 3, 4 didn\'t run');
is($_, 7, '$_ has the right value');
- add(1, 16);
+ add 16 => UP;
is($_, 7, '$_ has the right value');
}
{
is($x, 0, 'start');
local $_ = 3;
- add(0, 1);
+ add 1 => HERE;
is($_, 3, '$_ has the right value');
{
local $_ = 5;