8 # Before `make install' is performed this script should be runnable with
9 # `make test'. After `make install' it should work as `perl test.pl'
11 ######################### We start with some black magic to print on failure.
13 # Change 1..1 below to 1..last_test_to_print .
14 # (It may become useful if the test is moved to ./t subdirectory.)
16 BEGIN { $| = 1; print "1..37\n"; }
17 END {print "not ok 1\n" unless $loaded;}
18 use Text::Balanced qw ( gen_extract_tagged );
22 use vars qw( $DEBUG );
23 sub debug { print "\t>>>",@_ if $DEBUG }
25 ######################### End of black magic.
30 while (defined($str = <DATA>))
34 if ($str =~ s/\A# USING://)
37 eval{local$^W;*f = eval $str || die};
40 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
41 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
43 debug "\tUsing: $cmd\n";
44 debug "\t on: [$str]\n";
47 $var = eval { @res = f($str) };
48 debug "\t list got: [" . join("|",@res) . "]\n";
49 debug "\t list left: [$str]\n";
50 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
51 print "ok ", $count++;
52 print " ($@)" if $@ && $DEBUG;
56 $var = eval { scalar f($str) };
57 $var = "<undef>" unless defined $var;
58 debug "\t scalar got: [$var]\n";
59 debug "\t scalar left: [$str]\n";
60 print "not " if ($str =~ '\A;')==$neg;
61 print "ok ", $count++;
62 print " ($@)" if $@ && $DEBUG;
68 # USING: gen_extract_tagged('{','}');
71 # USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
72 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
74 # USING: gen_extract_tagged("BEGIN","END");
75 BEGIN at the BEGIN keyword and END at the END;
76 BEGIN at the beginning and end at the END;
78 # USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
79 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
81 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
84 # USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
85 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
88 BEGIN at the beginning and end at the end;
89 BEGIN at the BEGIN keyword and END at the end;
91 # TEST EXTRACTION OF TAGGED STRINGS
92 # USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
94 BEGIN at the BEGIN keyword and END at the end;
96 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
100 # USING: gen_extract_tagged();
102 <B>some text<A>other text</A></B>;
103 <A>some text<A>other text</A></A>;
104 <A HREF="#section2">some text</A>;
108 <A>some text<A>other text</A>;
109 <B>some text<A>other text</B>;