From: Vincent Pit Date: Sat, 3 Jan 2009 16:07:18 +0000 (+0100) Subject: More localize_delete() tests X-Git-Tag: v0.03~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=e2ff531cb21aae759ad18f1e996e6f014ff5f3d0;p=perl%2Fmodules%2FScope-Upper.git More localize_delete() tests --- diff --git a/MANIFEST b/MANIFEST index a6934e6..5452cf7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -21,7 +21,9 @@ t/31-localize_elem-level.t 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 diff --git a/t/41-localize_delete-level.t b/t/41-localize_delete-level.t new file mode 100644 index 0000000..b759523 --- /dev/null +++ b/t/41-localize_delete-level.t @@ -0,0 +1,66 @@ +#!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 $@; + } + } +} diff --git a/t/48-localize_delete-magic.t b/t/48-localize_delete-magic.t new file mode 100644 index 0000000..f037b3b --- /dev/null +++ b/t/48-localize_delete-magic.t @@ -0,0 +1,38 @@ +#!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]'; +} diff --git a/t/40-localize_delete.t b/t/49-localize_delete-target.t similarity index 100% rename from t/40-localize_delete.t rename to t/49-localize_delete-target.t