]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/44-localize_delete-magic.t
Harden t/09-load-tests.t against stray exits
[perl/modules/Scope-Upper.git] / t / 44-localize_delete-magic.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Scope::Upper qw<localize_delete UP HERE>;
7
8 use Test::More tests => 9;
9
10 our $deleted;
11
12 {
13  package Scope::Upper::Test::TiedArray;
14
15  sub TIEARRAY { bless [], $_[0] }
16  sub STORE { $_[0]->[$_[1]] = $_[2] }
17  sub FETCH { $_[0]->[$_[1]] }
18  sub CLEAR { @{$_[0]} = (); }
19  sub FETCHSIZE { scalar @{$_[0]} }
20  sub DELETE { ++$main::deleted; delete $_[0]->[$_[1]] }
21  sub EXTEND {}
22
23  our $NEGATIVE_INDICES = 0;
24 }
25
26 our @a;
27
28 {
29  local @a;
30  tie @a, 'Scope::Upper::Test::TiedArray';
31  @a = (5 .. 7);
32  local $a[4] = 9;
33  is $deleted, undef, 'localize_delete @tied_array, $existent => HERE [not deleted]';
34  {
35   localize_delete '@a', 4 => HERE;
36   is $deleted, 1, 'localize_delete @tied_array, $existent => HERE [deleted]';
37   is_deeply \@a, [ 5 .. 7 ], 'localize_delete @tied_array, $existent => HERE [ok]';
38  }
39  is_deeply \@a, [ 5 .. 7, undef, 9 ], 'localize_elem @incomplete_tied_array, $nonexistent, 12 => HERE [end]';
40  is $deleted, 1, 'localize_delete @tied_array, $existent => HERE [not more deleted]';
41 }
42
43 {
44  local @a;
45  tie @a, 'Scope::Upper::Test::TiedArray';
46  @a = (4 .. 6);
47  local $a[4] = 7;
48  {
49   localize_delete '@main::a', -1 => HERE;
50   is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array, $existent_neg => HERE [ok]';
51  }
52  is_deeply \@a, [ 4 .. 6, undef, 7 ], 'localize_delete @tied_array, $existent_neg => HERE [end]';
53 }
54
55 SKIP:
56 {
57  skip '$NEGATIVE_INDICES has no special meaning on 5.8.0 and older' => 2
58                                                             if "$]" < 5.008_001;
59  local $Scope::Upper::Test::TiedArray::NEGATIVE_INDICES = 1;
60  local @a;
61  tie @a, 'Scope::Upper::Test::TiedArray';
62  @a = (4 .. 6);
63  local $a[4] = 7;
64  {
65   localize_delete '@main::a', -1 => HERE;
66   is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array_wo_neg, $existent_neg => HERE [ok]';
67  }
68  is_deeply \@a, [ 4, 5, 7 ], 'localize_delete @tied_array_wo_neg, $existent_neg => HERE [end]';
69 }