This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lvref.t: Tests for \my assignment and scope exit
authorFather Chrysostomos <sprout@cpan.org>
Fri, 3 Oct 2014 23:33:55 +0000 (16:33 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 11 Oct 2014 07:10:16 +0000 (00:10 -0700)
t/op/lvref.t

index 379ef26..c018448 100644 (file)
@@ -4,7 +4,7 @@ BEGIN {
     set_up_inc("../lib");
 }
 
-plan 130;
+plan 135;
 
 sub on { $::TODO = ' ' }
 sub off{ $::TODO = ''  }
@@ -73,6 +73,14 @@ is do { \(local $l) = \4; $l }, 4, '\(local $scalar) assignment';
 is $l, undef, 'localisation unwound';
 \$foo = \*bar;
 is *foo{SCALAR}, *bar{GLOB}, 'globref-to-scalarref assignment';
+for (1,2) {
+  \my $x = \3 if $_ == 1;
+  \my($y) = \3 if $_ == 1;
+  if ($_ == 2) {
+    is $x, undef, '\my $x = ... clears $x on scope exit';
+    is $y, undef, '\my($x) = ... clears $x on scope exit';
+  }
+}
 
 # Array Elements
 
@@ -195,6 +203,14 @@ package ArrayTest {
   } or do { SKIP: { ::skip 'unimplemented' } };
   is \@i, $old, '(\local @a) unwound';
 }
+for (1,2) {
+  \my @x = [1..3] if $_ == 1;
+  \my(@y) = \3 if $_ == 1;
+  if ($_ == 2) {
+    is @x, 0, '\my @x = ... clears @x on scope exit';
+    is @y, 0, '\my(@x) = ... clears @x on scope exit';
+  }
+}
 
 # Hashes
 
@@ -229,6 +245,12 @@ package HashTest {
   } or do { SKIP: { ::skip 'unimplemented' } };
   is \%i, $old, '(\local %a) unwound';
 }
+for (1,2) {
+  \my %x = {1,2} if $_ == 1;
+  if ($_ == 2) {
+    is %x, 0, '\my %x = ... clears %x on scope exit';
+  }
+}
 
 # Subroutines