From 362e758e511f89d460f083210680cff7744c09e8 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 3 Oct 2014 12:40:23 -0700 Subject: [PATCH] Rework lvref.t foreach tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Remove the to-do marker. Add tests for package vars, too. Redo the \my &a test. I’ve decided not to bother with the ‘my &a’ syntax for now (if at all). It is problematic and needs discussion. (If ‘my &a’ is allowed in foreach, then it should be allowed else- where, but ‘my &a;’ would call a stub.) --- t/op/lvref.t | 59 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/t/op/lvref.t b/t/op/lvref.t index bdaa23e..379ef26 100644 --- a/t/op/lvref.t +++ b/t/op/lvref.t @@ -4,7 +4,7 @@ BEGIN { set_up_inc("../lib"); } -plan 125; +plan 130; sub on { $::TODO = ' ' } sub off{ $::TODO = '' } @@ -284,42 +284,61 @@ is $whitu, 5, '\( ?: ) assignment'; # Foreach -on; -eval ' - for \my $a(\$for1, \$for2) { - push @for, \$a; - } -'; +for \my $topic (\$for1, \$for2) { + push @for, \$topic; +} is "@for", \$for1 . ' ' . \$for2, 'foreach \my $a'; +is \$topic, \$::topic, 'for \my scoping'; + +@for = (); +for \$::a(\$for1, \$for2) { + push @for, \$::a; +} +is "@for", \$for1 . ' ' . \$for2, 'foreach \$::a'; @for = (); -eval ' - for \my @a([1,2], [3,4]) { +for \my @a([1,2], [3,4]) { push @for, @a; - } -'; +} is "@for", "1 2 3 4", 'foreach \my @a [perl #22335]'; @for = (); -eval ' - for \my %a({5,6}, {7,8}) { +for \@::a([1,2], [3,4]) { + push @for, @::a; +} +is "@for", "1 2 3 4", 'foreach \@::a [perl #22335]'; + +@for = (); +for \my %a({5,6}, {7,8}) { push @for, %a; - } -'; +} is "@for", "5 6 7 8", 'foreach \my %a [perl #22335]'; @for = (); -eval ' - for \my &a(sub {9}, sub {10}) { +for \%::a({5,6}, {7,8}) { + push @for, %::a; +} +is "@for", "5 6 7 8", 'foreach \%::a [perl #22335]'; + +@for = (); +{ + use feature 'lexical_subs'; + no warnings 'experimental::lexical_subs'; + my sub a; + for \&a(sub {9}, sub {10}) { push @for, &a; } -'; -is "@for", "9 10", 'foreach \my &a'; +} +is "@for", "9 10", 'foreach \&padcv'; +@for = (); +for \&::a(sub {9}, sub {10}) { + push @for, &::a; +} +is "@for", "9 10", 'foreach \&rv2cv'; # Errors -off; eval { my $x; \$x = 3 }; like $@, qr/^Assigned value is not a reference at/, 'assigning non-ref'; eval { my $x; \$x = [] }; -- 1.8.3.1