6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl test.pl'
9 ######################### We start with some black magic to print on failure.
11 # Change 1..1 below to 1..last_test_to_print .
12 # (It may become useful if the test is moved to ./t subdirectory.)
14 BEGIN { $| = 1; print "1..17\n"; }
15 END {print "not ok 1\n" unless $loaded;}
16 use Text::Balanced qw ( extract_bracketed );
20 use vars qw( $DEBUG );
21 sub debug { print "\t>>>",@_ if $DEBUG }
23 ######################### End of black magic.
28 while (defined($str = <DATA>))
31 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
32 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
33 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
35 debug "\tUsing: $cmd\n";
36 debug "\t on: [$str]\n";
38 $var = eval "() = $cmd";
39 debug "\t list got: [$var]\n";
40 debug "\t list left: [$str]\n";
41 print "not " if (substr($str,pos($str),1) eq ';')==$neg;
42 print "ok ", $count++;
43 print " ($@)" if $@ && $DEBUG;
48 $var = "<undef>" unless defined $var;
49 debug "\t scalar got: [$var]\n";
50 debug "\t scalar left: [$str]\n";
51 print "not " if ($str =~ '\A;')==$neg;
52 print "ok ", $count++;
53 print " ($@)" if $@ && $DEBUG;
59 # USING: extract_bracketed($str);
60 {a nested { and } are okay as are () and <> pairs and escaped \}'s };
62 # USING: extract_bracketed($str,'{}');
63 {a nested { and } are okay as are unbalanced ( and < pairs and escaped \}'s };
66 {an unmatched nested { isn't okay, nor are ( and < };
67 {an unbalanced nested [ even with } and ] to match them;
70 # USING: extract_bracketed($str,'<"`q>');
71 <a q{uoted} ">" unbalanced right bracket of /(q>)/ either sort (`>>>""">>>>`) is okay >;
73 # USING: extract_bracketed($str,'<">');
74 <a quoted ">" unbalanced right bracket is okay >;
76 # USING: extract_bracketed($str,'<"`>');
77 <a quoted ">" unbalanced right bracket of either sort (`>>>""">>>>`) is okay >;
80 <a misquoted '>' unbalanced right bracket is bad >;