This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
[perl5.git] / t / lib / tb-xbrak.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5
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'
8
9 ######################### We start with some black magic to print on failure.
10
11 # Change 1..1 below to 1..last_test_to_print .
12 # (It may become useful if the test is moved to ./t subdirectory.)
13
14 BEGIN { $| = 1; print "1..19\n"; }
15 END {print "not ok 1\n" unless $loaded;}
16 use Text::Balanced qw ( extract_bracketed );
17 $loaded = 1;
18 print "ok 1\n";
19 $count=2;
20 use vars qw( $DEBUG );
21 sub debug { print "\t>>>",@_ if $DEBUG }
22
23 ######################### End of black magic.
24
25
26 $cmd = "print";
27 $neg = 0;
28 while (defined($str = <DATA>))
29 {
30         chomp $str;
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 }
34         $str =~ s/\\n/\n/g;
35         debug "\tUsing: $cmd\n";
36         debug "\t   on: [$str]\n";
37
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;
44         print "\n";
45
46         pos $str = 0;
47         $var = eval $cmd;
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;
54         print "\n";
55 }
56
57 __DATA__
58
59 # USING: extract_bracketed($str);
60 {a nested { and } are okay as are () and <> pairs and escaped \}'s };
61 {a nested\n{ and } are okay as are\n() and <> pairs and escaped \}'s };
62
63 # USING: extract_bracketed($str,'{}');
64 {a nested { and } are okay as are unbalanced ( and < pairs and escaped \}'s };
65
66 # THESE SHOULD FAIL
67 {an unmatched nested { isn't okay, nor are ( and < };
68 {an unbalanced nested [ even with } and ] to match them;
69
70
71 # USING: extract_bracketed($str,'<"`q>');
72 <a q{uoted} ">" unbalanced right bracket of /(q>)/ either sort (`>>>""">>>>`) is okay >;
73
74 # USING: extract_bracketed($str,'<">');
75 <a quoted ">" unbalanced right bracket is okay >;
76
77 # USING: extract_bracketed($str,'<"`>');
78 <a quoted ">" unbalanced right bracket of either sort (`>>>""">>>>`) is okay >;
79
80 # THIS SHOULD FAIL
81 <a misquoted '>' unbalanced right bracket is bad >;