This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #21845] "proto.h": 'id' is a reserved word in Objective-C.
[perl5.git] / t / op / undef.t
CommitLineData
a687059c
LW
1#!./perl
2
e03bd546
JH
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
e03bd546
JH
6}
7
659eaf73 8print "1..27\n";
a687059c
LW
9
10print defined($a) ? "not ok 1\n" : "ok 1\n";
11
12$a = 1+1;
13print defined($a) ? "ok 2\n" : "not ok 2\n";
14
15undef $a;
16print defined($a) ? "not ok 3\n" : "ok 3\n";
17
18$a = "hi";
19print defined($a) ? "ok 4\n" : "not ok 4\n";
20
21$a = $b;
22print defined($a) ? "not ok 5\n" : "ok 5\n";
23
24@ary = ("1arg");
25$a = pop(@ary);
26print defined($a) ? "ok 6\n" : "not ok 6\n";
27$a = pop(@ary);
28print defined($a) ? "not ok 7\n" : "ok 7\n";
29
30@ary = ("1arg");
31$a = shift(@ary);
32print defined($a) ? "ok 8\n" : "not ok 8\n";
33$a = shift(@ary);
34print defined($a) ? "not ok 9\n" : "ok 9\n";
35
36$ary{'foo'} = 'hi';
37print defined($ary{'foo'}) ? "ok 10\n" : "not ok 10\n";
38print defined($ary{'bar'}) ? "not ok 11\n" : "ok 11\n";
39undef $ary{'foo'};
40print defined($ary{'foo'}) ? "not ok 12\n" : "ok 12\n";
41
42print defined(@ary) ? "ok 13\n" : "not ok 13\n";
43print defined(%ary) ? "ok 14\n" : "not ok 14\n";
44undef @ary;
45print defined(@ary) ? "not ok 15\n" : "ok 15\n";
46undef %ary;
47print defined(%ary) ? "not ok 16\n" : "ok 16\n";
48@ary = (1);
fe14fcc3 49print defined @ary ? "ok 17\n" : "not ok 17\n";
a687059c
LW
50%ary = (1,1);
51print defined %ary ? "ok 18\n" : "not ok 18\n";
52
53sub foo { print "ok 19\n"; }
54
55&foo || print "not ok 19\n";
56
57print defined &foo ? "ok 20\n" : "not ok 20\n";
58undef &foo;
59print defined(&foo) ? "not ok 21\n" : "ok 21\n";
a3f914c5
GS
60
61eval { undef $1 };
62print $@ =~ /^Modification of a read/ ? "ok 22\n" : "not ok 22\n";
63
64eval { $1 = undef };
65print $@ =~ /^Modification of a read/ ? "ok 23\n" : "not ok 23\n";
66
659eaf73
GS
67{
68 require Tie::Hash;
69 tie my %foo, 'Tie::StdHash';
70 print defined %foo ? "ok 24\n" : "not ok 24\n";
71 %foo = ( a => 1 );
72 print defined %foo ? "ok 25\n" : "not ok 25\n";
73}
74
75{
76 require Tie::Array;
77 tie my @foo, 'Tie::StdArray';
78 print defined @foo ? "ok 26\n" : "not ok 26\n";
79 @foo = ( a => 1 );
80 print defined @foo ? "ok 27\n" : "not ok 27\n";
81}