t/32-localize_elem-block.t
t/38-localize_elem-magic.t
t/39-localize_elem-target.t
-t/40-localize_delete.t
+t/41-localize_delete-level.t
+t/48-localize_delete-magic.t
+t/49-localize_delete-target.t
t/90-boilerplate.t
t/91-pod.t
t/92-pod-coverage.t
--- /dev/null
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+
+use Scope::Upper qw/localize_delete/;
+
+use lib 't/lib';
+use Scope::Upper::TestGenerator;
+
+our ($x, $testcase);
+
+local $Scope::Upper::TestGenerator::call = sub {
+ my ($height, $level, $i) = @_;
+ return [ "localize_delete '\@main::a', 2 => $level;\n" ];
+};
+
+local $Scope::Upper::TestGenerator::test = sub {
+ my ($height, $level, $i) = @_;
+ my $j = ($i == $height - $level) ? '1' : '1, undef, 2';
+ return "is_deeply(\\\@main::a, [ $j ], 'a h=$height, l=$level, i=$i');\n";
+};
+
+our @a;
+
+for my $level (0 .. 4) {
+ for my $height ($level + 1 .. $level + 2) {
+ my $tests = Scope::Upper::TestGenerator::gen($height, $level);
+ for (@$tests) {
+ $testcase = $_;
+ $x = undef;
+ @a = (1);
+ $a[2] = 2;
+ eval;
+ diag $@ if $@;
+ }
+ }
+}
+
+local $Scope::Upper::TestGenerator::call = sub {
+ my ($height, $level, $i) = @_;
+ return [ "localize_delete '%main::h', 'a' => $level;\n" ];
+};
+
+local $Scope::Upper::TestGenerator::test = sub {
+ my ($height, $level, $i) = @_;
+ my $j = ($i == $height - $level) ? 'b => 2' : 'a => 1, b => 2';
+ return "is_deeply(\\%main::h, { $j }, 'h h=$height, l=$level, i=$i');\n";
+};
+
+our %h;
+
+for my $level (0 .. 4) {
+ for my $height ($level + 1 .. $level + 2) {
+ my $tests = Scope::Upper::TestGenerator::gen($height, $level);
+ for (@$tests) {
+ $testcase = $_;
+ $x = undef;
+ %h = (a => 1, b => 2);
+ eval;
+ diag $@ if $@;
+ }
+ }
+}
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Scope::Upper qw/localize_delete/;
+
+use Test::More tests => 5;
+
+our $deleted;
+
+{
+ package Scope::Upper::Test::TiedArray;
+
+ sub TIEARRAY { bless [], $_[0] }
+ sub STORE { $_[0]->[$_[1]] = $_[2] }
+ sub FETCH { $_[0]->[$_[1]] }
+ sub CLEAR { @{$_[0]} = (); }
+ sub FETCHSIZE { scalar @{$_[0]} }
+ sub DELETE { ++$main::deleted; delete $_[0]->[$_[1]] }
+ sub EXTEND {}
+}
+
+our @a;
+
+tie @a, 'Scope::Upper::Test::TiedArray';
+{
+ local @a = (5 .. 7);
+ local $a[4] = 9;
+ is $deleted, undef, 'localize_delete @tied_array, $existent => 0 [not deleted]';
+ {
+ localize_delete '@a', 4 => 0;
+ is $deleted, 1, 'localize_delete @tied_array, $existent => 0 [deleted]';
+ is_deeply \@a, [ 5 .. 7 ], 'localize_delete @tied_array, $existent => 0 [ok]';
+ }
+ 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]';
+}