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..37\n"; } |
15 | END {print "not ok 1\n" unless $loaded;} |
16 | use Text::Balanced qw ( extract_codeblock ); |
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 | my @res; |
39 | $var = eval "\@res = $cmd"; |
40 | debug "\t Failed: $@ at " . $@+0 .")" if $@; |
41 | debug "\t list got: [" . join("|",@res) . "]\n"; |
42 | debug "\t list left: [$str]\n"; |
43 | print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg; |
44 | print "ok ", $count++; |
45 | print "\n"; |
46 | |
47 | pos $str = 0; |
48 | $var = eval $cmd; |
49 | $var = "<undef>" unless defined $var; |
50 | debug "\t scalar got: [$var]\n"; |
51 | debug "\t scalar left: [$str]\n"; |
52 | print "not " if ($str =~ '\A;')==$neg; |
53 | print "ok ", $count++; |
54 | print " ($@)" if $@ && $DEBUG; |
55 | print "\n"; |
56 | } |
57 | |
58 | __DATA__ |
59 | |
60 | # USING: extract_codeblock($str,'<>'); |
61 | < %x = ( try => "this") >; |
62 | < %x = () >; |
63 | < %x = ( $try->{this}, "too") >; |
64 | < %'x = ( $try->{this}, "too") >; |
65 | < %'x'y = ( $try->{this}, "too") >; |
66 | < %::x::y = ( $try->{this}, "too") >; |
67 | |
68 | # THIS SHOULD FAIL |
69 | < %x = do { $try > 10 } >; |
70 | |
71 | # USING: extract_codeblock($str); |
72 | |
73 | { $a = /\}/; }; |
74 | { sub { $_[0] /= $_[1] } }; # / here |
75 | { 1; }; |
76 | { $a = 1; }; |
77 | |
78 | |
79 | # USING: extract_codeblock($str,undef,'=*'); |
80 | ========{$a=1}; |
81 | |
82 | # USING: extract_codeblock($str,'{}<>'); |
83 | < %x = do { $try > 10 } >; |
84 | |
85 | # USING: extract_codeblock($str,'{}',undef,'<>'); |
86 | < %x = do { $try > 10 } >; |
87 | |
88 | # USING: extract_codeblock($str,'{}'); |
89 | { $a = $b; # what's this doing here? \n };' |
90 | { $a = $b; \n $a =~ /$b/; \n @a = map /\s/ @b }; |
91 | |
92 | # THIS SHOULD FAIL |
93 | { $a = $b; # what's this doing here? };' |
94 | { $a = $b; # what's this doing here? ;' |