/
autovivification
50 lines (49 loc) 路 1.26 KB
/
autovivification
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
Test the autovivification feature
__END__
# NAME hash autovivification
use feature 'say'; # ensure the autoviv test depends on cop_warnings, not cop_hints
my $x;
$x->{foo} = 1;
no feature 'autovivification';
undef $x;
$x->{foo} = 1;
EXPECT
Attempt to autovivify a hash reference with autovivification disabled at - line 6.
########
# NAME hash autovivification (subhash)
use feature 'say'; # ensure the autoviv test depends on cop_warnings, not cop_hints
my $x = {};
$x->{foo} = 1;
$x->{foo}{bar} = 1;
no feature 'autovivification';
$x = {};
$x->{foo}{bar} = 1;
EXPECT
Attempt to autovivify a hash reference with autovivification disabled at - line 7.
########
# NAME array autovivification
my $x;
$x->[0] = 1;
undef $x;
no feature 'autovivification';
$x->[0] = 2;
EXPECT
Attempt to autovivify an array reference with autovivification disabled at - line 5.
########
# NAME array autovivification (sub array)
my $x = {};
$x->{foo}[0] = 1;
$x = {};
no feature 'autovivification';
$x->{foo}[0] = 2;
EXPECT
Attempt to autovivify an array reference with autovivification disabled at - line 5.
########
# NAME scalar autovivification
my $x;
$$x = 1;
undef $x;
no feature 'autovivification';
$$x = 2;
EXPECT
Attempt to autovivify a scalar reference with autovivification disabled at - line 5.