Add contact information for Sullivan Beck
[p5sagit/p5-mst-13.2.git] / cpan / Text-Balanced / t / 07_exttag.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
9BEGIN { $| = 1; print "1..53\n"; }
10END {print "not ok 1\n" unless $loaded;}
11use Text::Balanced qw ( extract_tagged 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 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 my @res;
34 $var = eval "\@res = $cmd";
49c03c89 35 debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
3270c621 36 debug "\t list left: [$str]\n";
37 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
38 print "ok ", $count++;
39 print " ($@)" if $@ && $DEBUG;
40 print "\n";
41
42 pos $str = 0;
43 $var = eval $cmd;
44 $var = "<undef>" unless defined $var;
45 debug "\t scalar got: [$var]\n";
46 debug "\t scalar left: [$str]\n";
47 print "not " if ($str =~ '\A;')==$neg;
48 print "ok ", $count++;
49 print " ($@)" if $@ && $DEBUG;
50 print "\n";
51}
52
53__DATA__
54# USING: gen_extract_tagged("BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)")->($str);
55 ignore\n this and then BEGINHERE at the ENDHERE;
56 ignore\n this and then BEGINTHIS at the ENDTHIS;
57
58# USING: extract_tagged($str,"BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)");
59 ignore\n this and then BEGINHERE at the ENDHERE;
60 ignore\n this and then BEGINTHIS at the ENDTHIS;
61
62# USING: extract_tagged($str,"BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)");
63 ignore\n this and then BEGINHERE at the ENDHERE;
64 ignore\n this and then BEGINTHIS at the ENDTHIS;
65
66# THIS SHOULD FAIL
67 ignore\n this and then BEGINTHIS at the ENDTHAT;
68
69# USING: extract_tagged($str,"BEGIN","END","(?s).*?(?=BEGIN)");
70 ignore\n this and then BEGIN at the END;
71
72# USING: extract_tagged($str);
73 <A-1 HREF="#section2">some text</A-1>;
74
75# USING: extract_tagged($str,qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
76 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
77
78# USING: extract_tagged($str,"BEGIN","END");
79 BEGIN at the BEGIN keyword and END at the END;
80 BEGIN at the beginning and end at the END;
81
82# USING: extract_tagged($str,undef,undef,undef,{ignore=>["<[^>]*/>"]});
83 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
84
85# USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"MAX"});
86 ; at the ;-) keyword
87
88# USING: extract_tagged($str,"<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
89 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
90
91# THESE SHOULD FAIL
92 BEGIN at the beginning and end at the end;
93 BEGIN at the BEGIN keyword and END at the end;
94
95# TEST EXTRACTION OF TAGGED STRINGS
96# USING: extract_tagged($str,"BEGIN","END",undef,{reject=>["BEGIN","END"]});
97# THESE SHOULD FAIL
98 BEGIN at the BEGIN keyword and END at the end;
99
100# USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"PARA"});
101 ; at the ;-) keyword
102
103
104# USING: extract_tagged($str);
105 <A>some text</A>;
106 <B>some text<A>other text</A></B>;
107 <A>some text<A>other text</A></A>;
108 <A HREF="#section2">some text</A>;
109
110# THESE SHOULD FAIL
111 <A>some text
112 <A>some text<A>other text</A>;
113 <B>some text<A>other text</B>;