7 print "#1 :$x: eq :x:\n";
8 if ($x eq 'x') {print "ok 1\n";} else {print "not ok 1\n";}
12 if ($x eq '') {print "ok 2\n";} else {print "not ok 2\n";}
16 if ($x eq '-1') {print "ok 3\n";} else {print "not ok 3\n";}
20 if (length($x) == 1) {print "ok 4\n";} else {print "not ok 4\n";}
25 /^/ && (print "ok 5\n");
29 if (!$@) {print "ok 6\n";} else {print "not ok 6 $@\n";}
31 eval '$foo = 123+123.4+123e4+123.4E5+123.4e+5+.12;';
33 $foo = int($foo * 100 + .5);
34 if ($foo eq 2591024652) {print "ok 7\n";} else {print "not ok 7 :$foo:\n";}
45 eval <<\EOE, print $@;
56 print <<'EOS' . <<\EOF;
57 ok 12 - make sure single quotes are honored \nnot ok
72 print "ok 18 - was the test for the deprecated use of bare << to mean <<\"\"\n";
76 ## previous line intentionally left blank.
78 print <<E1 eq "foo\n\n" ? "ok 19\n" : "not ok 19\n";
84 print <<E1 eq "foo\n\n" ? "ok 20\n" : "not ok 20\n";
97 print "$foo{$bar}" eq "BAZ" ? "ok 21\n" : "not ok 21\n";
99 print "${foo}{$bar}" eq "FOO{BAR}" ? "ok 22\n" : "not ok 22\n";
100 print "${foo{$bar}}" eq "BAZ" ? "ok 23\n" : "not ok 23\n";
102 print "FOO:" =~ /$foo[:]/ ? "ok 24\n" : "not ok 24\n";
103 print "ABC" =~ /^$ary[$A]$/ ? "ok 25\n" : "not ok 25\n";
104 print "FOOZ" =~ /^$foo[$A-Z]$/ ? "ok 26\n" : "not ok 26\n";
107 ($X, @X) = qw(a b c d);
108 print "d" =~ /^$X[-1]$/ ? "ok 27\n" : "not ok 27\n";
109 print "a1" !~ /^$X[-1]$/ ? "ok 28\n" : "not ok 28\n";
111 print (((q{{\{\(}} . q{{\)\}}}) eq '{{\(}{\)}}') ? "ok 29\n" : "not ok 29\n");
114 $foo = "not ok 30\n";
115 $foo =~ s/^not /substr(<<EOF, 0, 0)/e;
120 # Tests for new extended control-character variables
129 if ($ {^XY} != 23) { print "not " }
130 print "ok $test\n"; $test++;
132 # Does the old UNBRACED syntax still do what it used to?
133 if ("$^XY" ne "17Y") { print "not " }
134 print "ok $test\n"; $test++;
138 $^Q = 5; # This should be an unused ^Var.
140 # The second caret here should be interpreted as an xor
141 if (($^Q^XX) != 3) { print "not " }
142 print "ok $test\n"; $test++;
144 # These next two tests are trying to make sure that
145 # $^FOO is always global; it doesn't make sense to 'my' it.
149 print "not " unless index ($@, 'Can\'t use global $^X in "my"') > -1;
150 print "ok $test\n"; $test++;
151 # print "($@)\n" if $@;
154 print "not " unless index ($@, 'Can\'t use global $^XYZ in "my"') > -1;
155 print "ok $test\n"; $test++;
156 # print "($@)\n" if $@;
159 @{^TEST}= ("foo", "bar");
160 %{^TEST}= ("foo" => "FOO", "bar" => "BAR" );
162 print "not " if "${^TEST}" ne "splat";
163 print "ok $test\n"; $test++;
165 print "not " if "${ ^TEST }" ne "splat";
166 print "ok $test\n"; $test++;
168 print "not " if "${^TEST}[0]" ne "splat[0]";
169 print "ok $test\n"; $test++;
171 print "not " if "${^TEST[0]}" ne "foo";
172 print "ok $test\n"; $test++;
174 print "not " if "${ ^TEST [1] }" ne "bar";
175 print "ok $test\n"; $test++;
177 print "not " if "${^TEST}{foo}" ne "splat{foo}";
178 print "ok $test\n"; $test++;
180 print "not " if "${^TEST{foo}}" ne "FOO";
181 print "ok $test\n"; $test++;
183 print "not " if "${ ^TEST {bar} }" ne "BAR";
184 print "ok $test\n"; $test++;
187 # Now let's make sure that caret variables are all forced into the main package.
190 $ {^Quixote} = 'Someother 2';
191 $ {^M} = 'Someother 3';
193 print "not " unless $^Q eq 'Someother';
194 print "ok $test\n"; $test++;
195 print "not " unless $ {^Quixote} eq 'Someother 2';
196 print "ok $test\n"; $test++;
197 print "not " unless $ {^M} eq 'Someother 3';
198 print "ok $test\n"; $test++;
203 # see if eval '', s///e, and heredocs mix
206 my ($where, $num) = @_;
207 my ($p,$f,$l) = caller;
208 print "# $p:$f:$l vs /$where/\nnot " unless "$p:$f:$l" =~ /$where/;
214 local $_ = "not ok ";
216 s/^not /<<EOT/e and T '^main:\(eval \d+\):2$', $test++;
219 print $_, $test++, "\n";
220 T('^main:\(eval \d+\):6$', $test++);
222 T('^main:plunk:1$', $test++);
224 print "# $@\nnot ok $test\n" if $@;
225 T '^main:plink:53$', $test++;
228 # tests 47--51 start here
229 # tests for new array interpolation semantics:
230 # arrays now *always* interpolate into "..." strings.
231 # 20000522 MJD (mjd@plover.com)
233 eval(q(">@nosuch<" eq "><")) || print "# $@", "not ";
237 # Look at this! This is going to be a common error in the future:
238 eval(q("fred@example.com" eq "fred.com")) || print "# $@", "not ";
242 # Let's make sure that normal array interpolation still works right
243 # For some reason, this appears not to be tested anywhere else.
245 print +((">@a<" eq ">1 2 3<") ? '' : 'not '), "ok $test\n";
249 eval(q{@nosuch = ('a', 'b', 'c'); ">@nosuch<" eq ">a b c<"})
250 || print "# $@", "not ";
254 # This isn't actually a lex test, but it's testing the same feature
256 my @array = ('fish', 'dog', 'carrot');
257 *R::crackers = \@array;
260 eval(q{makearray(); ">@R::crackers<" eq ">fish dog carrot<"})
261 || print "# $@", "not ";
267 # => should only quote foo::bar if it isn't a real sub. AMS, 20010621
269 sub xyz::foo { "bar" }
276 print ((exists $str{foo} ? "" : "not ")."ok $test\n"); ++$test;
277 print ((exists $str{bar} ? "" : "not ")."ok $test\n"); ++$test;
278 print ((exists $str{xyz::bar} ? "" : "not ")."ok $test\n"); ++$test;
280 sub foo::::::bar { print "ok $test\n"; $test++ }
283 # \xDF is a non-ASCII alpha on both ASCII and EBCDIC.
285 if ($@ =~ /Unrecognized character \\xDF; marked by <-- HERE after \$x =<-- HERE near column 5/) { print "ok $test\n"; } else { print "not ok $test\n"; }
288 # Is "[~" scanned correctly?
290 print "not " unless($a[~~2] == 3);
291 print "ok $test\n"; $test++;
294 eval 's/(?:)/"ok $test" . "${\q||}".<<\END/e;
295 - heredoc after "" in s/// in eval
298 print $_ || "not ok $test\n"; $test++;
301 eval 's|(?:)|"ok $test" . "${\<<\END}"
302 - heredoc in "" in multiline s///e in eval
306 print $_ || "not ok $test\n"; $test++;
309 eval "s/(?:)/<<foo/e #\0
310 ok $test - null on same line as heredoc in s/// in eval
313 print $_ || "not ok $test\n"; $test++;
316 eval ' s/(?:)/"${\<<END}"/e;
317 ok $test - heredoc in "" in single-line s///e in eval
320 print $_ || "not ok $test\n"; $test++;
324 ok $test - heredoc in "" in multiline s///e outside eval
327 print $_ || "not ok $test\n"; $test++;
329 $_ = "not ok $test - s/// in s/// pattern\n";
334 ok $test - here-doc in re-eval
338 eval '/(?{print <<END
339 ok $test - here-doc in re-eval in string eval
343 eval 'print qq ;ok $test - eval ending with semicolon\n;'
344 or print "not ok $test - eval ending with semicolon\n"; $test++;
346 print "not " unless qr/(?{<<END})/ eq '(?^:(?{<<END}))';
349 print "ok $test - here-doc in single-line re-eval\n"; $test++;
351 $_ = qr/(?{"${<<END}"
355 print "not " unless /foo/;
356 print "ok $test - here-doc in quotes in multiline re-eval\n"; $test++;
358 eval 's//<<END/e if 0; $_ = "a
361 print "not " if $_ =~ /\n\n/;
362 print "ok $test - eval 's//<<END/' does not leave extra newlines\n"; $test++;
366 print 'not ' unless $_ eq "b\0";
367 print "ok $test - # after null in s/// repl\n"; $test++;
372 print "ok $test - s//'#' . <<END/e\n"; $test++;
375 print "not " unless $@;
376 print "ok $test - s//3}->{3/e\n"; $test++;
380 eval 's/${\%x}{3}//e';
381 print "$_ - s//\${\\%x}{3}/e\n"; $test++;
384 print "not " unless $@;
385 print "ok $test - s/\${foo#}//e\n"; $test++;
387 eval 'warn ({$_ => 1} + 1) if 0';
389 print "ok $test - listop({$_ => 1} + 1)\n"; $test++;
392 for(qw< require goto last next redo CORE::dump >) {
393 eval "sub { $_ foo << 2 }";
395 print "ok ", $test++, " - [perl #105924] $_ WORD << ...\n";
399 # http://rt.perl.org/rt3/Ticket/Display.html?id=56880
401 eval 'v23: $counter++; goto v23 unless $counter == 2';
402 print "not " unless $counter == 2;
403 print "ok $test - Use v[0-9]+ as a label\n"; $test++;
405 eval 'v23 : $counter++; goto v23 unless $counter == 2';
406 print "not " unless $counter == 2;
407 print "ok $test - Use v[0-9]+ as a label with space before colon\n"; $test++;
410 eval "package v10::foo; sub test2 { return 'v10::foo' }
411 package v10; sub test { return v10::foo::test2(); }
412 package main; \$output = v10::test(); ";
413 print "not " unless $output eq 'v10::foo';
414 print "ok $test - call a function in package v10::foo\n"; $test++;
416 print "not " unless (1?v65:"bar") eq chr(65);
417 print "ok $test - colon detection after vstring does not break ? vstring :\n"; $test++;
419 print ((ord("A") == 65) ? v35 : v123); # NUMBER SIGN is the same for all
420 # supported EBCDIC platforms
422 print ((ord("A") == 65) ? v10 : "\n"); # LF varies on EBCDIC, if the v123 for
423 # '#' works above, consider it good
425 print "ok $test - print vstring prints the vstring\n";
428 # Test pyoq ops with comments before the first delim
431 eq 'b' or print "not ";
432 print "ok $test - q <comment> <newline> ...\n"; $test++;
435 eq 'b' or print "not ";
436 print "ok $test - qq <comment> <newline> ...\n"; $test++;
439 [0] eq 'b' or print "not ";
440 print "ok $test - qw <comment> <newline> ...\n"; $test++;
444 print "ok $test - m <comment> <newline> ...\n"; $test++;
447 eq qr/b/ or print "not ";
448 print "ok $test - qr <comment> <newline> ...\n"; $test++;
454 print "not " unless $_ eq 'b';
455 print "ok $test - s <comment> <newline> ...\n"; $test++;
461 print "not " unless $_ eq 'b';
462 print "ok $test - tr <comment> <newline> ...\n"; $test++;
468 print "not " unless $_ eq 'b';
469 print "ok $test - y <comment> <newline> ...\n"; $test++;
471 print "not " unless (time
473 print "ok $test - => quotes keywords across lines\n"; $test++;
476 print "not " unless eval '"a\U="' eq "a=";
477 print "ok $test - [perl #80368] qq <a\\U=>\n"; $test++;
479 sub Function_with_side_effects { $_ = "sidekick function called" }
481 (eval '${Function_with_side_effects,\$_}' || $@)
482 eq "sidekick function called";
483 print "ok $test - \${...} where {...} looks like hash\n"; $test++;
485 @_ = map{BEGIN {$_122782 = 'tst2'}; "rhu$_"} 'barb2';
486 print "not " unless "@_" eq 'rhubarb2';
487 print "ok $test - map{BEGIN...\n"; $test++;
488 print "not " unless $_122782 eq 'tst2';
489 print "ok $test - map{BEGIN...\n"; $test++;
495 print "not "unless $_ == 42;
496 print "ok $test - \${ <newline> =pod\n"; $test++;
502 print "not "unless "@_" eq 2;
503 print "ok $test - map{ <newline> =pod\n"; $test++;
505 print "not " unless $@ =~ /^Unimplemented at /;
506 print "ok $test - \${...} (literal triple-dot)\n"; $test++;
507 eval { () = map{...} @_ };
508 print "not " unless $@ =~ /^Unimplemented at /;
509 print "ok $test - map{...} (literal triple-dot)\n"; $test++;
510 print "not " unless &{sub :lvalue { "a" }} eq "a";
511 print "ok $test - &{sub :lvalue...}\n"; $test++;
512 print "not " unless ref +(map{sub :lvalue { "a" }} 1)[0] eq "CODE";
513 print "ok $test - map{sub :lvalue...}\n"; $test++;
515 # Used to crash [perl #123711]
518 # Used to fail an assertion [perl #123617] [perl #123955]
519 eval '"$a{ 1 m// }"; //';
520 eval '"@0{0s 000";eval"$"';
522 # Pending token stack overflow [perl #123677]
524 local $SIG{__WARN__}=sub{};
525 eval q|s)$0{0h());qx(@0);qx(@0);qx(@0)|;
528 # Used to crash [perl #123801]
531 # Used to fail an assertion [perl #123763]
533 local $SIG{__WARN__}=sub{};
534 eval q|my($_);0=split|;
535 eval q|my $_; @x = split|;
539 # Used to crash [perl #124187]
540 eval q|qq{@{[{}}*sub{]]}}}=u|;
544 # Used to crash [perl #124385]
545 eval '0; qq{@{sub{]]}}}}}';
546 print "ok $test - 124385\n"; $test++;
550 # Used to crash [perl #125350]
551 eval ('qq{@{[0}*sub{]]}}}=sub{0' . "\c[");
552 print "ok $test - 125350\n"; $test++;
556 # Used to crash [perl #128171]
557 eval ('/@0{0*->@*/*]');
558 print "ok $test - 128171\n"; $test++;
561 $foo = "WRONG"; $foo:: = "bar"; $bar = "baz";
562 print "not " unless "$foo::$bar" eq "barbaz";
563 print qq|ok $test - [perl #128478] "\$foo::\$bar"\n|; $test++;
564 @bar = ("baz","bonk");
565 print "not " unless "$foo::@bar" eq "barbaz bonk";
566 print qq|ok $test - [perl #128478] "\$foo::\@bar"\n|; $test ++;
568 # Test that compilation of tentative indirect method call syntax which
569 # turns out not to be such does not upgrade constants to full globs in the
573 { local $SIG{__WARN__}=sub{}; eval 'fop bas'; }
574 print "not " unless ref $::{fop} eq 'SCALAR';
575 print "ok $test - first constant in 'const1 const2' is not upgraded\n";
577 print "not " unless ref $::{bas} eq 'SCALAR';
578 print "ok $test - second constant in 'const1 const2' is not upgraded\n";