use v6;
use Test;
plan 11;
{
my $a = 42;
{
is(eval('let $a = 23; $a'), 23, "let() changed the variable (1)");
1;
}
is $a, 23, "let() should not restore the variable, as our block exited succesfully (1)";
}
{
my $a = 42;
{
is(eval('let $a = 23; $a'), 23, "let() changed the variable (1)");
Mu;
}
is $a, 42, "let() should restore the variable, as our block failed";
}
{
my $a = 42;
my $get_a = { $a };
{
is(eval('let $a = 23; $a'), 23, "let() changed the variable (2-1)");
is $get_a(), 23, "let() changed the variable (2-2)";
1;
}
is $a, 23, "let() should not restore the variable, as our block exited succesfully (2)";
}
{
my $a = 42;
try {
is(eval('let $a = 23; $a'), 23, "let() changed the variable in a try block");
die 57;
};
is $a, 42, "let() restored the variable, the block was exited using an exception";
}
{
my @array = (0, 1, 2);
{
is(eval('let @array[1] = 42; @array[1]'), 42, "let() changed our array element");
Mu;
}
is @array[1], 1, "let() restored our array element";
}