1 #! /usr/local/bin/perl -ws
2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
5 ######################### We start with some black magic to print on failure.
7 # Change 1..1 below to 1..last_test_to_print .
8 # (It may become useful if the test is moved to ./t subdirectory.)
10 BEGIN { $| = 1; print "1..95\n"; }
11 END {print "not ok 1\n" unless $loaded;}
12 use Text::Balanced qw ( extract_quotelike );
16 use vars qw( $DEBUG );
18 sub debug { print "\t>>>",@_ if $ENV{DEBUG} }
19 sub esc { my $x = shift||'<undef>'; $x =~ s/\n/\\n/gs; $x }
21 ######################### End of black magic.
26 while (defined($str = <DATA>))
29 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
30 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
31 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
32 my $setup_cmd = ($str =~ s/\A\{(.*)\}//) ? $1 : '';
37 eval $setup_cmd if $setup_cmd ne '';
39 debug "\tUsing: $cmd\n";
40 debug "\t on: [" . esc($setup_cmd) . "][" . esc($str) . "]\n";
42 eval qq{\@res = $cmd; };
43 debug "\t got:\n" . join "", map { "\t\t\t$_: [" . esc($res[$_]) . "]\n"} (0..$#res);
44 debug "\t left: [" . esc($str) . "]\n";
45 debug "\t pos: [" . esc(substr($str,pos($str))) . "...]\n";
46 print "not " if (substr($str,pos($str),1) eq ';')==$neg;
47 print "ok ", $count++;
51 eval $setup_cmd if $setup_cmd ne '';
54 debug "\tUsing: scalar $cmd\n";
55 debug "\t on: [" . esc($str) . "]\n";
57 print " ($@)" if $@ && $DEBUG;
58 $var = "<undef>" unless defined $var;
59 debug "\t scalar got: [" . esc($var) . "]\n";
60 debug "\t scalar left: [" . esc($str) . "]\n";
61 print "not " if ($str =~ '\A;')==$neg;
62 print "ok ", $count++;
67 # fails in Text::Balanced 1.95
69 my @z = extract_quotelike();
70 print "not " if $z[0] eq '';
71 print "ok ", $count++;
77 # USING: extract_quotelike($str);
85 <<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
86 <<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
87 <<"EOHERE"; done()\nline1\nline2\nEOHERE\n and next
88 <<`EOHERE`; done()\nline1\nline2\nEOHERE\n and next
89 <<'EOHERE'; done()\nline1\n'line2'\nEOHERE\n and next
90 <<'EOHERE;'; done()\nline1\nline2\nEOHERE;\n and next
91 <<" EOHERE"; done() \nline1\nline2\n EOHERE\nand next
92 <<""; done()\nline1\nline2\n\n and next
93 <<; done()\nline1\nline2\n\n and next
94 # fails in Text::Balanced 1.95
96 # fails in Text::Balanced 1.95
99 "this is a nested $var[$x] {";
112 qq{a nested { and } are okay as are () and <> pairs and escaped \}'s };
127 # fails on Text-Balanced-1.95
128 { $tests = 'l'; pos($str)=6 }012345<<E;\n\nE\n
131 s<$self->{pat}>{$self->{sub}}; # CAN'T HANDLE '>' in '->'
132 s-$self->{pap}-$self->{sub}-; # CAN'T HANDLE '-' in '->'
133 <<EOHERE; done();\nline1\nline2\nEOHERE;\n; next; # RDEL HAS NO ';'
134 <<'EOHERE'; done();\nline1\nline2\nEOHERE;\n; next; # RDEF HAS NO ';'
135 << EOTHERE; done();\nline1\nline2\n EOTHERE\n; next; # RDEL IS "" (!)