1N/A#!./perl
1N/A
1N/Aprint "1..55\n";
1N/A
1N/A$x = 'x';
1N/A
1N/Aprint "#1 :$x: eq :x:\n";
1N/Aif ($x eq 'x') {print "ok 1\n";} else {print "not ok 1\n";}
1N/A
1N/A$x = $#; # this is the register $#
1N/A
1N/Aif ($x eq '') {print "ok 2\n";} else {print "not ok 2\n";}
1N/A
1N/A$x = $#x;
1N/A
1N/Aif ($x eq '-1') {print "ok 3\n";} else {print "not ok 3\n";}
1N/A
1N/A$x = '\\'; # ';
1N/A
1N/Aif (length($x) == 1) {print "ok 4\n";} else {print "not ok 4\n";}
1N/A
1N/Aeval 'while (0) {
1N/A print "foo\n";
1N/A}
1N/A/^/ && (print "ok 5\n");
1N/A';
1N/A
1N/Aeval '$foo{1} / 1;';
1N/Aif (!$@) {print "ok 6\n";} else {print "not ok 6 $@\n";}
1N/A
1N/Aeval '$foo = 123+123.4+123e4+123.4E5+123.4e+5+.12;';
1N/A
1N/A$foo = int($foo * 100 + .5);
1N/Aif ($foo eq 2591024652) {print "ok 7\n";} else {print "not ok 7 :$foo:\n";}
1N/A
1N/Aprint <<'EOF';
1N/Aok 8
1N/AEOF
1N/A
1N/A$foo = 'ok 9';
1N/Aprint <<EOF;
1N/A$foo
1N/AEOF
1N/A
1N/Aeval <<\EOE, print $@;
1N/Aprint <<'EOF';
1N/Aok 10
1N/AEOF
1N/A
1N/A$foo = 'ok 11';
1N/Aprint <<EOF;
1N/A$foo
1N/AEOF
1N/AEOE
1N/A
1N/Aprint <<'EOS' . <<\EOF;
1N/Aok 12 - make sure single quotes are honored \nnot ok
1N/AEOS
1N/Aok 13
1N/AEOF
1N/A
1N/Aprint qq/ok 14\n/;
1N/Aprint qq(ok 15\n);
1N/A
1N/Aprint qq
1N/A[ok 16\n]
1N/A;
1N/A
1N/Aprint q<ok 17
1N/A>;
1N/A
1N/Aprint <<; # Yow!
1N/Aok 18
1N/A
1N/A# previous line intentionally left blank.
1N/A
1N/Aprint <<E1 eq "foo\n\n" ? "ok 19\n" : "not ok 19\n";
1N/A@{[ <<E2 ]}
1N/Afoo
1N/AE2
1N/AE1
1N/A
1N/Aprint <<E1 eq "foo\n\n" ? "ok 20\n" : "not ok 20\n";
1N/A@{[
1N/A <<E2
1N/Afoo
1N/AE2
1N/A]}
1N/AE1
1N/A
1N/A$foo = FOO;
1N/A$bar = BAR;
1N/A$foo{$bar} = BAZ;
1N/A$ary[0] = ABC;
1N/A
1N/Aprint "$foo{$bar}" eq "BAZ" ? "ok 21\n" : "not ok 21\n";
1N/A
1N/Aprint "${foo}{$bar}" eq "FOO{BAR}" ? "ok 22\n" : "not ok 22\n";
1N/Aprint "${foo{$bar}}" eq "BAZ" ? "ok 23\n" : "not ok 23\n";
1N/A
1N/Aprint "FOO:" =~ /$foo[:]/ ? "ok 24\n" : "not ok 24\n";
1N/Aprint "ABC" =~ /^$ary[$A]$/ ? "ok 25\n" : "not ok 25\n";
1N/Aprint "FOOZ" =~ /^$foo[$A-Z]$/ ? "ok 26\n" : "not ok 26\n";
1N/A
1N/A# MJD 19980425
1N/A($X, @X) = qw(a b c d);
1N/Aprint "d" =~ /^$X[-1]$/ ? "ok 27\n" : "not ok 27\n";
1N/Aprint "a1" !~ /^$X[-1]$/ ? "ok 28\n" : "not ok 28\n";
1N/A
1N/Aprint (((q{{\{\(}} . q{{\)\}}}) eq '{{\(}{\)}}') ? "ok 29\n" : "not ok 29\n");
1N/A
1N/A
1N/A$foo = "not ok 30\n";
1N/A$foo =~ s/^not /substr(<<EOF, 0, 0)/e;
1N/A Ignored
1N/AEOF
1N/Aprint $foo;
1N/A
1N/A# Tests for new extended control-character variables
1N/A# MJD 19990227
1N/A
1N/A{ my $CX = "\cX";
1N/A my $CXY ="\cXY";
1N/A $ {$CX} = 17;
1N/A $ {$CXY} = 23;
1N/A if ($ {^XY} != 23) { print "not " }
1N/A print "ok 31\n";
1N/A
1N/A# Does the syntax where we use the literal control character still work?
1N/A if (eval "\$ {\cX}" != 17 or $@) { print "not " }
1N/A print "ok 32\n";
1N/A
1N/A eval "\$\cQ = 24"; # Literal control character
1N/A if ($@ or ${"\cQ"} != 24) { print "not " }
1N/A print "ok 33\n";
1N/A if ($^Q != 24) { print "not " } # Control character escape sequence
1N/A print "ok 34\n";
1N/A
1N/A# Does the old UNBRACED syntax still do what it used to?
1N/A if ("$^XY" ne "17Y") { print "not " }
1N/A print "ok 35\n";
1N/A
1N/A sub XX () { 6 }
1N/A $ {"\cQ\cXX"} = 119;
1N/A $^Q = 5; # This should be an unused ^Var.
1N/A $N = 5;
1N/A # The second caret here should be interpreted as an xor
1N/A if (($^Q^XX) != 3) { print "not " }
1N/A print "ok 36\n";
1N/A# if (($N ^ XX()) != 3) { print "not " }
1N/A# print "ok 32\n";
1N/A
1N/A # These next two tests are trying to make sure that
1N/A # $^FOO is always global; it doesn't make sense to `my' it.
1N/A #
1N/A
1N/A eval 'my $^X;';
1N/A print "not " unless index ($@, 'Can\'t use global $^X in "my"') > -1;
1N/A print "ok 37\n";
1N/A# print "($@)\n" if $@;
1N/A
1N/A eval 'my $ {^XYZ};';
1N/A print "not " unless index ($@, 'Can\'t use global $^XYZ in "my"') > -1;
1N/A print "ok 38\n";
1N/A# print "($@)\n" if $@;
1N/A
1N/A# Now let's make sure that caret variables are all forced into the main package.
1N/A package Someother;
1N/A $^Q = 'Someother';
1N/A $ {^Quixote} = 'Someother 2';
1N/A $ {^M} = 'Someother 3';
1N/A package main;
1N/A print "not " unless $^Q eq 'Someother';
1N/A print "ok 39\n";
1N/A print "not " unless $ {^Quixote} eq 'Someother 2';
1N/A print "ok 40\n";
1N/A print "not " unless $ {^M} eq 'Someother 3';
1N/A print "ok 41\n";
1N/A
1N/A
1N/A}
1N/A
1N/A# see if eval '', s///e, and heredocs mix
1N/A
1N/Asub T {
1N/A my ($where, $num) = @_;
1N/A my ($p,$f,$l) = caller;
1N/A print "# $p:$f:$l vs /$where/\nnot " unless "$p:$f:$l" =~ /$where/;
1N/A print "ok $num\n";
1N/A}
1N/A
1N/Amy $test = 42;
1N/A
1N/A{
1N/A# line 42 "plink"
1N/A local $_ = "not ok ";
1N/A eval q{
1N/A s/^not /<<EOT/e and T '^main:\(eval \d+\):2$', $test++;
1N/A# fuggedaboudit
1N/AEOT
1N/A print $_, $test++, "\n";
1N/A T('^main:\(eval \d+\):6$', $test++);
1N/A# line 1 "plunk"
1N/A T('^main:plunk:1$', $test++);
1N/A };
1N/A print "# $@\nnot ok $test\n" if $@;
1N/A T '^main:plink:53$', $test++;
1N/A}
1N/A
1N/A# tests 47--51 start here
1N/A# tests for new array interpolation semantics:
1N/A# arrays now *always* interpolate into "..." strings.
1N/A# 20000522 MJD (mjd@plover.com)
1N/A{
1N/A my $test = 47;
1N/A eval(q(">@nosuch<" eq "><")) || print "# $@", "not ";
1N/A print "ok $test\n";
1N/A ++$test;
1N/A
1N/A # Look at this! This is going to be a common error in the future:
1N/A eval(q("fred@example.com" eq "fred.com")) || print "# $@", "not ";
1N/A print "ok $test\n";
1N/A ++$test;
1N/A
1N/A # Let's make sure that normal array interpolation still works right
1N/A # For some reason, this appears not to be tested anywhere else.
1N/A my @a = (1,2,3);
1N/A print +((">@a<" eq ">1 2 3<") ? '' : 'not '), "ok $test\n";
1N/A ++$test;
1N/A
1N/A # Ditto.
1N/A eval(q{@nosuch = ('a', 'b', 'c'); ">@nosuch<" eq ">a b c<"})
1N/A || print "# $@", "not ";
1N/A print "ok $test\n";
1N/A ++$test;
1N/A
1N/A # This isn't actually a lex test, but it's testing the same feature
1N/A sub makearray {
1N/A my @array = ('fish', 'dog', 'carrot');
1N/A *R::crackers = \@array;
1N/A }
1N/A
1N/A eval(q{makearray(); ">@R::crackers<" eq ">fish dog carrot<"})
1N/A || print "# $@", "not ";
1N/A print "ok $test\n";
1N/A ++$test;
1N/A}
1N/A
1N/A# Tests 52-54
1N/A# => should only quote foo::bar if it isn't a real sub. AMS, 20010621
1N/A
1N/Asub xyz::foo { "bar" }
1N/Amy %str = (
1N/A foo => 1,
1N/A xyz::foo => 1,
1N/A xyz::bar => 1,
1N/A);
1N/A
1N/Amy $test = 52;
1N/Aprint ((exists $str{foo} ? "" : "not ")."ok $test\n"); ++$test;
1N/Aprint ((exists $str{bar} ? "" : "not ")."ok $test\n"); ++$test;
1N/Aprint ((exists $str{xyz::bar} ? "" : "not ")."ok $test\n"); ++$test;
1N/A
1N/Asub foo::::::bar { print "ok $test\n"; $test++ }
1N/Afoo::::::bar;