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