]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/48-localize_delete-magic.t
Fix deletion of localized array elements with negative indices resulting in an incorr...
[perl/modules/Scope-Upper.git] / t / 48-localize_delete-magic.t
index f037b3bdd57c3a257e475a09405dee8952cb2b7e..0b930505f4a20896fd08684df21b4267de3c7285 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use Scope::Upper qw/localize_delete/;
 
-use Test::More tests => 5;
+use Test::More tests => 9;
 
 our $deleted;
 
@@ -19,6 +19,8 @@ our $deleted;
  sub FETCHSIZE { scalar @{$_[0]} }
  sub DELETE { ++$main::deleted; delete $_[0]->[$_[1]] }
  sub EXTEND {}
+
+ our $NEGATIVE_INDICES = 0;
 }
 
 our @a;
@@ -36,3 +38,26 @@ tie @a, 'Scope::Upper::Test::TiedArray';
  is_deeply \@a, [ 5 .. 7, undef, 9 ], 'localize_elem @incomplete_tied_array, $nonexistent, 12 => 0 [end]';
  is $deleted, 1, 'localize_delete @tied_array, $existent => 0 [not more deleted]';
 }
+
+{
+ local @a = (4 .. 6);
+ local $a[4] = 7;
+ {
+  localize_delete '@main::a', -1, 0;
+  is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array, $existent_neg => 0 [ok]';
+ }
+ is_deeply \@a, [ 4 .. 6, undef, 7 ], 'localize_delete @tied_array, $existent_neg => 0 [end]';
+}
+
+SKIP:
+{
+ skip '$NEGATIVE_INDICES has no special meaning on 5.8.0 and older' => 2 if $] < 5.008_001;
+ local $Scope::Upper::Test::TiedArray::NEGATIVE_INDICES = 1;
+ local @a = (4 .. 6);
+ local $a[4] = 7;
+ {
+  localize_delete '@main::a', -1, 0;
+  is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array_wo_neg, $existent_neg => 0 [ok]';
+ }
+ is_deeply \@a, [ 4, 5, 7 ], 'localize_delete @tied_array_wo_neg, $existent_neg => 0 [end]';
+}