Commit | Line | Data |
3270c621 |
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..17\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 | |
62 | # USING: extract_bracketed($str,'{}'); |
63 | {a nested { and } are okay as are unbalanced ( and < pairs and escaped \}'s }; |
64 | |
65 | # THESE SHOULD FAIL |
66 | {an unmatched nested { isn't okay, nor are ( and < }; |
67 | {an unbalanced nested [ even with } and ] to match them; |
68 | |
69 | |
70 | # USING: extract_bracketed($str,'<"`q>'); |
71 | <a q{uoted} ">" unbalanced right bracket of /(q>)/ either sort (`>>>""">>>>`) is okay >; |
72 | |
73 | # USING: extract_bracketed($str,'<">'); |
74 | <a quoted ">" unbalanced right bracket is okay >; |
75 | |
76 | # USING: extract_bracketed($str,'<"`>'); |
77 | <a quoted ">" unbalanced right bracket of either sort (`>>>""">>>>`) is okay >; |
78 | |
79 | # THIS SHOULD FAIL |
80 | <a misquoted '>' unbalanced right bracket is bad >; |