1N/ABEGIN {
1N/A if ($ENV{PERL_CORE}) {
1N/A chdir('t') if -d 't';
1N/A @INC = qw(../lib);
1N/A }
1N/A}
1N/A
1N/A#! /usr/local/bin/perl -ws
1N/A# Before `make install' is performed this script should be runnable with
1N/A# `make test'. After `make install' it should work as `perl test.pl'
1N/A
1N/A######################### We start with some black magic to print on failure.
1N/A
1N/A# Change 1..1 below to 1..last_test_to_print .
1N/A# (It may become useful if the test is moved to ./t subdirectory.)
1N/A
1N/ABEGIN { $| = 1; print "1..89\n"; }
1N/AEND {print "not ok 1\n" unless $loaded;}
1N/Ause Text::Balanced qw ( extract_quotelike );
1N/A$loaded = 1;
1N/Aprint "ok 1\n";
1N/A$count=2;
1N/Ause vars qw( $DEBUG );
1N/A# $DEBUG=1;
1N/Asub debug { print "\t>>>",@_ if $DEBUG }
1N/A
1N/A######################### End of black magic.
1N/A
1N/A
1N/A$cmd = "print";
1N/A$neg = 0;
1N/Awhile (defined($str = <DATA>))
1N/A{
1N/A chomp $str;
1N/A if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
1N/A elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
1N/A elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
1N/A debug "\tUsing: $cmd\n";
1N/A debug "\t on: [$str]\n";
1N/A $str =~ s/\\n/\n/g;
1N/A my $orig = $str;
1N/A
1N/A my @res;
1N/A eval qq{\@res = $cmd; };
1N/A debug "\t got:\n" . join "", map { $res[$_]=~s/\n/\\n/g; "\t\t\t$_: [$res[$_]]\n"} (0..$#res);
1N/A debug "\t left: " . (map { s/\n/\\n/g; "[$_]\n" } my $cpy1 = $str)[0];
1N/A debug "\t pos: " . (map { s/\n/\\n/g; "[$_]\n" } my $cpy2 = substr($str,pos($str)))[0] . "...]\n";
1N/A print "not " if (substr($str,pos($str),1) eq ';')==$neg;
1N/A print "ok ", $count++;
1N/A print "\n";
1N/A
1N/A $str = $orig;
1N/A debug "\tUsing: scalar $cmd\n";
1N/A debug "\t on: [$str]\n";
1N/A $var = eval $cmd;
1N/A print " ($@)" if $@ && $DEBUG;
1N/A $var = "<undef>" unless defined $var;
1N/A debug "\t scalar got: " . (map { s/\n/\\n/g; "[$_]\n" } $var)[0];
1N/A debug "\t scalar left: " . (map { s/\n/\\n/g; "[$_]\n" } $str)[0];
1N/A print "not " if ($str =~ '\A;')==$neg;
1N/A print "ok ", $count++;
1N/A print "\n";
1N/A}
1N/A
1N/A__DATA__
1N/A
1N/A# USING: extract_quotelike($str);
1N/A'';
1N/A"";
1N/A"a";
1N/A'b';
1N/A`cc`;
1N/A
1N/A
1N/A<<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
1N/A <<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
1N/A<<"EOHERE"; done()\nline1\nline2\nEOHERE\n and next
1N/A<<`EOHERE`; done()\nline1\nline2\nEOHERE\n and next
1N/A<<'EOHERE'; done()\nline1\n'line2'\nEOHERE\n and next
1N/A<<'EOHERE;'; done()\nline1\nline2\nEOHERE;\n and next
1N/A<<" EOHERE"; done() \nline1\nline2\n EOHERE\nand next
1N/A<<""; done()\nline1\nline2\n\n and next
1N/A<<; done()\nline1\nline2\n\n and next
1N/A
1N/A
1N/A"this is a nested $var[$x] {";
1N/A/a/gci;
1N/Am/a/gci;
1N/A
1N/Aq(d);
1N/Aqq(e);
1N/Aqx(f);
1N/Aqr(g);
1N/Aqw(h i j);
1N/Aq{d};
1N/Aqq{e};
1N/Aqx{f};
1N/Aqr{g};
1N/Aqq{a nested { and } are okay as are () and <> pairs and escaped \}'s };
1N/Aq/slash/;
1N/Aq # slash #;
1N/Aqr qw qx;
1N/A
1N/As/x/y/;
1N/As/x/y/cgimsox;
1N/As{a}{b};
1N/As{a}\n {b};
1N/As(a){b};
1N/As(a)/b/;
1N/As/'/\\'/g;
1N/Atr/x/y/;
1N/Ay/x/y/;
1N/A
1N/A# THESE SHOULD FAIL
1N/As<$self->{pat}>{$self->{sub}}; # CAN'T HANDLE '>' in '->'
1N/As-$self->{pap}-$self->{sub}-; # CAN'T HANDLE '-' in '->'
1N/A<<EOHERE; done();\nline1\nline2\nEOHERE;\n; next; # RDEL HAS NO ';'
1N/A<<'EOHERE'; done();\nline1\nline2\nEOHERE;\n; next; # RDEF HAS NO ';'
1N/A << EOTHERE; done();\nline1\nline2\n EOTHERE\n; next; # RDEL IS "" (!)