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