Add contact information for Sullivan Beck
[p5sagit/p5-mst-13.2.git] / cpan / Text-Balanced / t / 09_gentag.t
CommitLineData
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
48f821bf 9BEGIN { $| = 1; print "1..37\n"; }
3270c621 10END {print "not ok 1\n" unless $loaded;}
11use Text::Balanced qw ( gen_extract_tagged );
12$loaded = 1;
13print "ok 1\n";
14$count=2;
15use vars qw( $DEBUG );
16sub debug { print "\t>>>",@_ if $DEBUG }
17
18######################### End of black magic.
19
20
21$cmd = "print";
22$neg = 0;
23while (defined($str = <DATA>))
24{
25 chomp $str;
26 $str =~ s/\\n/\n/g;
27 if ($str =~ s/\A# USING://)
28 {
29 $neg = 0;
30 eval{local$^W;*f = eval $str || die};
31 next;
32 }
33 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
34 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
35 $str =~ s/\\n/\n/g;
36 debug "\tUsing: $cmd\n";
37 debug "\t on: [$str]\n";
38
39 my @res;
40 $var = eval { @res = f($str) };
49c03c89 41 debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
3270c621 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 " ($@)" if $@ && $DEBUG;
46 print "\n";
47
48 pos $str = 0;
49 $var = eval { scalar f($str) };
50 $var = "<undef>" unless defined $var;
51 debug "\t scalar got: [$var]\n";
52 debug "\t scalar left: [$str]\n";
53 print "not " if ($str =~ '\A;')==$neg;
54 print "ok ", $count++;
55 print " ($@)" if $@ && $DEBUG;
56 print "\n";
57}
58
59__DATA__
60
48f821bf 61# USING: gen_extract_tagged('{','}');
62 { a test };
63
3270c621 64# USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
65 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
66
67# USING: gen_extract_tagged("BEGIN","END");
68 BEGIN at the BEGIN keyword and END at the END;
69 BEGIN at the beginning and end at the END;
70
71# USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
72 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
73
74# USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
75 ; at the ;-) keyword
76
77# USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
78 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
79
80# THESE SHOULD FAIL
81 BEGIN at the beginning and end at the end;
82 BEGIN at the BEGIN keyword and END at the end;
83
84# TEST EXTRACTION OF TAGGED STRINGS
85# USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
86# THESE SHOULD FAIL
87 BEGIN at the BEGIN keyword and END at the end;
88
89# USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
90 ; at the ;-) keyword
91
92
93# USING: gen_extract_tagged();
94 <A>some text</A>;
95 <B>some text<A>other text</A></B>;
96 <A>some text<A>other text</A></A>;
97 <A HREF="#section2">some text</A>;
98
99# THESE SHOULD FAIL
100 <A>some text
101 <A>some text<A>other text</A>;
102 <B>some text<A>other text</B>;