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..45\n"; } |
15 | END {print "not ok 1\n" unless $loaded;} |
16 | use Text::Balanced qw ( extract_delimited ); |
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)||0,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 | # USING: extract_delimited($str,'/#$',undef,'/#$'); |
59 | /a/; |
60 | /a///; |
61 | #b#; |
62 | #b###; |
63 | $c$; |
64 | $c$$$; |
65 | |
66 | # TEST EXTRACTION OF DELIMITED TEXT WITH ESCAPES |
67 | # USING: extract_delimited($str,'/#$',undef,'\\'); |
68 | /a/; |
69 | /a\//; |
70 | #b#; |
71 | #b\##; |
72 | $c$; |
73 | $c\$$; |
74 | |
75 | # TEST EXTRACTION OF DELIMITED TEXT |
76 | # USING: extract_delimited($str); |
77 | 'a'; |
78 | "b"; |
79 | `c`; |
80 | 'a\''; |
81 | 'a\\'; |
82 | '\\a'; |
83 | "a\\"; |
84 | "\\a"; |
85 | "b\'\"\'"; |
86 | `c '\`abc\`'`; |
87 | |
88 | # TEST EXTRACTION OF DELIMITED TEXT |
89 | # USING: extract_delimited($str,'/#$','-->'); |
90 | -->/a/; |
91 | -->#b#; |
92 | -->$c$; |
93 | |
94 | # THIS SHOULD FAIL |
95 | $c$; |