]> git.vpit.fr Git - perl/modules/autovivification.git/blob - t/24-hash-numerous.t
This is 0.18
[perl/modules/autovivification.git] / t / 24-hash-numerous.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 2 * 2 * 4;
7
8 my $n = 100;
9
10 {
11  my $w;
12  {
13   my $r;
14   no autovivification;
15   $r = $w->{a}{b} for 1 .. $n;
16  }
17  is_deeply $w, undef, 'numerous fetches from an undef lexical';
18
19  $w = { a => undef };
20  {
21   my $r;
22   no autovivification;
23   $r = $w->{a}{b} for 1 .. $n;
24  }
25  is_deeply $w, { a => undef },'numerous fetches from a 1-level hashref lexical';
26 }
27
28 {
29  our $w;
30  {
31   my $r;
32   no autovivification;
33   $r = $w->{a}{b} for 1 .. $n;
34  }
35  is_deeply $w, undef, 'numerous fetches from an undef global';
36
37  $w = { a => undef };
38  {
39   my $r;
40   no autovivification;
41   $r = $w->{a}{b} for 1 .. $n;
42  }
43  is_deeply $w, { a => undef },'numerous fetches from a 1-level hashref global';
44 }
45
46 {
47  my $x;
48  {
49   my @r;
50   no autovivification;
51   @r = @{$x}{qw<a b>} for 1 .. $n;
52  }
53  is_deeply $x, undef, 'numerous slices from an undef lexical';
54
55  $x = { a => undef };
56  {
57   my @r;
58   no autovivification;
59   @r = @{$x->{a}}{qw<b c>} for 1 .. $n;
60  }
61  is_deeply $x, { a => undef }, 'numerous slices from a 1-level hashref lexical';
62 }
63
64 {
65  our $x;
66  {
67   my @r;
68   no autovivification;
69   @r = @{$x}{qw<a b>} for 1 .. $n;
70  }
71  is_deeply $x, undef, 'numerous slices from an undef global';
72
73  $x = { a => undef };
74  {
75   my @r;
76   no autovivification;
77   @r = @{$x->{a}}{qw<b c>} for 1 .. $n;
78  }
79  is_deeply $x, { a => undef }, 'numerous slices from a 1-level hashref global';
80 }
81
82 {
83  my $y;
84  {
85   my $r;
86   no autovivification;
87   $r = exists $y->{a}{b} for 1 .. $n;
88  }
89  is_deeply $y, undef, 'numerous exists from an undef lexical';
90
91  $y = { a => undef };
92  {
93   my $r;
94   no autovivification;
95   $r = exists $y->{a}{b} for 1 .. $n;
96  }
97  is_deeply $y, { a => undef },'numerous exists from a 1-level hashref lexical';
98 }
99
100 {
101  our $y;
102  {
103   my $r;
104   no autovivification;
105   $r = exists $y->{a}{b} for 1 .. $n;
106  }
107  is_deeply $y, undef, 'numerous exists from an undef global';
108
109  $y = { a => undef };
110  {
111   my $r;
112   no autovivification;
113   $r = exists $y->{a}{b} for 1 .. $n;
114  }
115  is_deeply $y, { a => undef },'numerous exists from a 1-level hashref global';
116 }
117
118 {
119  my $z;
120  {
121   my $r;
122   no autovivification;
123   $r = delete $z->{a}{b} for 1 .. $n;
124  }
125  is_deeply $z, undef, 'numerous deletes from an undef lexical';
126
127  $z = { a => undef };
128  {
129   my $r;
130   no autovivification;
131   $r = delete $z->{a}{b} for 1 .. $n;
132  }
133  is_deeply $z, { a => undef },'numerous deletes from a 1-level hashref lexical';
134 }
135
136 {
137  our $z;
138  {
139   my $r;
140   no autovivification;
141   $r = delete $z->{a}{b} for 1 .. $n;
142  }
143  is_deeply $z, undef, 'numerous deletes from an undef global';
144
145  $z = { a => undef };
146  {
147   my $r;
148   no autovivification;
149   $r = delete $z->{a}{b} for 1 .. $n;
150  }
151  is_deeply $z, { a => undef },'numerous deletes from a 1-level hashref global';
152 }