Add contact information for Sullivan Beck
[p5sagit/p5-mst-13.2.git] / cpan / Text-Balanced / t / 02_extbrk.t
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'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9 BEGIN { $| = 1; print "1..19\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Text::Balanced qw ( extract_bracketed );
12 $loaded = 1;
13 print "ok 1\n";
14 $count=2;
15 use vars qw( $DEBUG );
16 sub debug { print "\t>>>",@_ if $DEBUG }
17
18 ######################### End of black magic.
19
20
21 $cmd = "print";
22 $neg = 0;
23 while (defined($str = <DATA>))
24 {
25         chomp $str;
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 }
29         $str =~ s/\\n/\n/g;
30         debug "\tUsing: $cmd\n";
31         debug "\t   on: [$str]\n";
32
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;
39         print "\n";
40
41         pos $str = 0;
42         $var = eval $cmd;
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;
49         print "\n";
50 }
51
52 __DATA__
53
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 };
57
58 # USING: extract_bracketed($str,'{}');
59 {a nested { and } are okay as are unbalanced ( and < pairs and escaped \}'s };
60
61 # THESE SHOULD FAIL
62 {an unmatched nested { isn't okay, nor are ( and < };
63 {an unbalanced nested [ even with } and ] to match them;
64
65
66 # USING: extract_bracketed($str,'<"`q>');
67 <a q{uoted} ">" unbalanced right bracket of /(q>)/ either sort (`>>>""">>>>`) is okay >;
68
69 # USING: extract_bracketed($str,'<">');
70 <a quoted ">" unbalanced right bracket is okay >;
71
72 # USING: extract_bracketed($str,'<"`>');
73 <a quoted ">" unbalanced right bracket of either sort (`>>>""">>>>`) is okay >;
74
75 # THIS SHOULD FAIL
76 <a misquoted '>' unbalanced right bracket is bad >;