8 #! /usr/local/bin/perl -ws
9 # Before `make install' is performed this script should be runnable with
10 # `make test'. After `make install' it should work as `perl test.pl'
12 ######################### We start with some black magic to print on failure.
14 # Change 1..1 below to 1..last_test_to_print .
15 # (It may become useful if the test is moved to ./t subdirectory.)
17 BEGIN { $| = 1; print "1..95\n"; }
18 END {print "not ok 1\n" unless $loaded;}
19 use Text::Balanced qw ( extract_quotelike );
23 use vars qw( $DEBUG );
25 sub debug { print "\t>>>",@_ if $ENV{DEBUG} }
26 sub esc { my $x = shift; $x =~ s/\n/\\n/gs; $x }
28 ######################### End of black magic.
33 while (defined($str = <DATA>))
36 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
37 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
38 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
39 my $setup_cmd = ($str =~ s/\A\{(.*)\}//) ? $1 : '';
44 eval $setup_cmd if $setup_cmd ne '';
46 debug "\tUsing: $cmd\n";
47 debug "\t on: [" . esc($setup_cmd) . "][" . esc($str) . "]\n";
49 eval qq{\@res = $cmd; };
50 debug "\t got:\n" . join "", map { "\t\t\t$_: [" . esc($res[$_]) . "]\n"} (0..$#res);
51 debug "\t left: [" . esc($str) . "]\n";
52 debug "\t pos: [" . esc(substr($str,pos($str))) . "...]\n";
53 print "not " if (substr($str,pos($str),1) eq ';')==$neg;
54 print "ok ", $count++;
58 eval $setup_cmd if $setup_cmd ne '';
61 debug "\tUsing: scalar $cmd\n";
62 debug "\t on: [" . esc($str) . "]\n";
64 print " ($@)" if $@ && $DEBUG;
65 $var = "<undef>" unless defined $var;
66 debug "\t scalar got: [" . esc($var) . "]\n";
67 debug "\t scalar left: [" . esc($str) . "]\n";
68 print "not " if ($str =~ '\A;')==$neg;
69 print "ok ", $count++;
74 # fails in Text::Balanced 1.95
76 my @z = extract_quotelike();
77 print "not " if $z[0] eq '';
78 print "ok ", $count++;
84 # USING: extract_quotelike($str);
92 <<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
93 <<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
94 <<"EOHERE"; done()\nline1\nline2\nEOHERE\n and next
95 <<`EOHERE`; done()\nline1\nline2\nEOHERE\n and next
96 <<'EOHERE'; done()\nline1\n'line2'\nEOHERE\n and next
97 <<'EOHERE;'; done()\nline1\nline2\nEOHERE;\n and next
98 <<" EOHERE"; done() \nline1\nline2\n EOHERE\nand next
99 <<""; done()\nline1\nline2\n\n and next
100 <<; done()\nline1\nline2\n\n and next
101 # fails in Text::Balanced 1.95
103 # fails in Text::Balanced 1.95
106 "this is a nested $var[$x] {";
119 qq{a nested { and } are okay as are () and <> pairs and escaped \}'s };
134 # fails on Text-Balanced-1.95
135 { $tests = 'l'; pos($str)=6 }012345<<E;\n\nE\n
138 s<$self->{pat}>{$self->{sub}}; # CAN'T HANDLE '>' in '->'
139 s-$self->{pap}-$self->{sub}-; # CAN'T HANDLE '-' in '->'
140 <<EOHERE; done();\nline1\nline2\nEOHERE;\n; next; # RDEL HAS NO ';'
141 <<'EOHERE'; done();\nline1\nline2\nEOHERE;\n; next; # RDEF HAS NO ';'
142 << EOTHERE; done();\nline1\nline2\n EOTHERE\n; next; # RDEL IS "" (!)