use yyerror() instead of croak() so that compile-time failures in
[p5sagit/p5-mst-13.2.git] / t / base / lex.t
CommitLineData
8d063cd8 1#!./perl
2
79072805 3# $RCSfile: lex.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:04 $
8d063cd8 4
2b92dfce 5print "1..41\n";
8d063cd8 6
79072805 7$x = 'x';
8d063cd8 8
79072805 9print "#1 :$x: eq :x:\n";
10if ($x eq 'x') {print "ok 1\n";} else {print "not ok 1\n";}
8d063cd8 11
12$x = $#; # this is the register $#
13
14if ($x eq '') {print "ok 2\n";} else {print "not ok 2\n";}
15
16$x = $#x;
17
18if ($x eq '-1') {print "ok 3\n";} else {print "not ok 3\n";}
19
20$x = '\\'; # ';
21
22if (length($x) == 1) {print "ok 4\n";} else {print "not ok 4\n";}
a559c259 23
24eval 'while (0) {
25 print "foo\n";
26}
27/^/ && (print "ok 5\n");
28';
29
30eval '$foo{1} / 1;';
79072805 31if (!$@) {print "ok 6\n";} else {print "not ok 6 $@\n";}
378cc40b 32
33eval '$foo = 123+123.4+123e4+123.4E5+123.4e+5+.12;';
34
35$foo = int($foo * 100 + .5);
87250799 36if ($foo eq 2591024652) {print "ok 7\n";} else {print "not ok 7 :$foo:\n";}
a687059c 37
38print <<'EOF';
39ok 8
40EOF
41
42$foo = 'ok 9';
43print <<EOF;
44$foo
45EOF
46
47eval <<\EOE, print $@;
48print <<'EOF';
49ok 10
50EOF
51
52$foo = 'ok 11';
53print <<EOF;
54$foo
55EOF
56EOE
57
58print <<`EOS` . <<\EOF;
59echo ok 12
60EOS
61ok 13
62EOF
63
64print qq/ok 14\n/;
65print qq(ok 15\n);
66
67print qq
a0d0e21e 68[ok 16\n]
a687059c 69;
70
71print q<ok 17
72>;
73
74print <<; # Yow!
75ok 18
76
77# previous line intentionally left blank.
79072805 78
2ba53c57 79print <<E1 eq "foo\n\n" ? "ok 19\n" : "not ok 19\n";
80@{[ <<E2 ]}
81foo
82E2
83E1
84
85print <<E1 eq "foo\n\n" ? "ok 20\n" : "not ok 20\n";
86@{[
87 <<E2
88foo
89E2
90]}
91E1
92
79072805 93$foo = FOO;
94$bar = BAR;
95$foo{$bar} = BAZ;
96$ary[0] = ABC;
97
2ba53c57 98print "$foo{$bar}" eq "BAZ" ? "ok 21\n" : "not ok 21\n";
79072805 99
2ba53c57 100print "${foo}{$bar}" eq "FOO{BAR}" ? "ok 22\n" : "not ok 22\n";
101print "${foo{$bar}}" eq "BAZ" ? "ok 23\n" : "not ok 23\n";
79072805 102
2ba53c57 103print "FOO:" =~ /$foo[:]/ ? "ok 24\n" : "not ok 24\n";
104print "ABC" =~ /^$ary[$A]$/ ? "ok 25\n" : "not ok 25\n";
105print "FOOZ" =~ /^$foo[$A-Z]$/ ? "ok 26\n" : "not ok 26\n";
1bcde0ca 106
f27ffc4a 107# MJD 19980425
108($X, @X) = qw(a b c d);
109print "d" =~ /^$X[-1]$/ ? "ok 27\n" : "not ok 27\n";
110print "a1" !~ /^$X[-1]$/ ? "ok 28\n" : "not ok 28\n";
a2c06652 111
f27ffc4a 112print (((q{{\{\(}} . q{{\)\}}}) eq '{{\(}{\)}}') ? "ok 29\n" : "not ok 29\n");
113
114
115$foo = "not ok 30\n";
a2c06652 116$foo =~ s/^not /substr(<<EOF, 0, 0)/e;
117 Ignored
118EOF
119print $foo;
2b92dfce 120
121# Tests for new extended control-character variables
122# MJD 19990227
123
124{ my $CX = "\cX";
125 my $CXY ="\cXY";
126 $ {$CX} = 17;
127 $ {$CXY} = 23;
128 if ($ {^XY} != 23) { print "not " }
129 print "ok 31\n";
130
131# Does the syntax where we use the literal control character still work?
765cb2dc 132 if (eval "\$ {\cX}" != 17 or $@) { print "not " }
2b92dfce 133 print "ok 32\n";
134
765cb2dc 135 eval "\$\cN = 24"; # Literal control character
136 if ($@ or ${"\cN"} != 24) { print "not " }
2b92dfce 137 print "ok 33\n";
138 if ($^N != 24) { print "not " } # Control character escape sequence
139 print "ok 34\n";
140
141# Does the old UNBRACED syntax still do what it used to?
142 if ("$^XY" ne "17Y") { print "not " }
143 print "ok 35\n";
144
145 sub XX () { 6 }
146 $ {"\cN\cXX"} = 119;
147 $^N = 5; # This should be an unused ^Var.
148 $N = 5;
149 # The second caret here should be interpreted as an xor
150 if (($^N^XX) != 3) { print "not " }
151 print "ok 36\n";
152# if (($N ^ XX()) != 3) { print "not " }
153# print "ok 32\n";
154
155 # These next two tests are trying to make sure that
156 # $^FOO is always global; it doesn't make sense to `my' it.
157 #
158 eval 'my $^X;';
159 print "not " unless index ($@, 'Can\'t use global $^X in "my"') > -1;
160 print "ok 37\n";
161# print "($@)\n" if $@;
162
163 eval 'my $ {^XYZ};';
164 print "not " unless index ($@, 'Can\'t use global $^XYZ in "my"') > -1;
165 print "ok 38\n";
166# print "($@)\n" if $@;
167
168# Now let's make sure that caret variables are all forced into the main package.
169 package Someother;
170 $^N = 'Someother';
171 $ {^Nostril} = 'Someother 2';
172 $ {^M} = 'Someother 3';
173 package main;
174 print "not " unless $^N eq 'Someother';
175 print "ok 39\n";
176 print "not " unless $ {^Nostril} eq 'Someother 2';
177 print "ok 40\n";
178 print "not " unless $ {^M} eq 'Someother 3';
179 print "ok 41\n";
180
181
182}
183
184