File: 44-localize_delete-magic.t

package info (click to toggle)
libscope-upper-perl 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 312 kB
  • ctags: 16
  • sloc: perl: 2,831; makefile: 7
file content (68 lines) | stat: -rw-r--r-- 1,838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!perl

use strict;
use warnings;

use Scope::Upper qw/localize_delete UP HERE/;

use Test::More tests => 9;

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 $NEGATIVE_INDICES = 0;
}

our @a;

{
 local @a;
 tie @a, 'Scope::Upper::Test::TiedArray';
 @a = (5 .. 7);
 local $a[4] = 9;
 is $deleted, undef, 'localize_delete @tied_array, $existent => HERE [not deleted]';
 {
  localize_delete '@a', 4 => HERE;
  is $deleted, 1, 'localize_delete @tied_array, $existent => HERE [deleted]';
  is_deeply \@a, [ 5 .. 7 ], 'localize_delete @tied_array, $existent => HERE [ok]';
 }
 is_deeply \@a, [ 5 .. 7, undef, 9 ], 'localize_elem @incomplete_tied_array, $nonexistent, 12 => HERE [end]';
 is $deleted, 1, 'localize_delete @tied_array, $existent => HERE [not more deleted]';
}

{
 local @a;
 tie @a, 'Scope::Upper::Test::TiedArray';
 @a = (4 .. 6);
 local $a[4] = 7;
 {
  localize_delete '@main::a', -1 => HERE;
  is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array, $existent_neg => HERE [ok]';
 }
 is_deeply \@a, [ 4 .. 6, undef, 7 ], 'localize_delete @tied_array, $existent_neg => HERE [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;
 tie @a, 'Scope::Upper::Test::TiedArray';
 @a = (4 .. 6);
 local $a[4] = 7;
 {
  localize_delete '@main::a', -1 => HERE;
  is_deeply \@a, [ 4 .. 6 ], 'localize_delete @tied_array_wo_neg, $existent_neg => HERE [ok]';
 }
 is_deeply \@a, [ 4, 5, 7 ], 'localize_delete @tied_array_wo_neg, $existent_neg => HERE [end]';
}