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'
9 ######################### We start with some black magic to print on failure.
11 # Change 1..1 below to 1..last_test_to_print .
12 # (It may become useful if the test is moved to ./t subdirectory.)
14 BEGIN { $| = 1; print "1..35\n"; }
15 END {print "not ok 1\n" unless $loaded;}
16 use Text::Balanced qw ( gen_extract_tagged );
20 use vars qw( $DEBUG );
21 sub debug { print "\t>>>",@_ if $DEBUG }
23 ######################### End of black magic.
28 while (defined($str = <DATA>))
32 if ($str =~ s/\A# USING://)
35 eval{local$^W;*f = eval $str || die};
38 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
39 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
41 debug "\tUsing: $cmd\n";
42 debug "\t on: [$str]\n";
45 $var = eval { @res = f($str) };
46 debug "\t list got: [" . join("|",@res) . "]\n";
47 debug "\t list left: [$str]\n";
48 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
49 print "ok ", $count++;
50 print " ($@)" if $@ && $DEBUG;
54 $var = eval { scalar f($str) };
55 $var = "<undef>" unless defined $var;
56 debug "\t scalar got: [$var]\n";
57 debug "\t scalar left: [$str]\n";
58 print "not " if ($str =~ '\A;')==$neg;
59 print "ok ", $count++;
60 print " ($@)" if $@ && $DEBUG;
66 # USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
67 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
69 # USING: gen_extract_tagged("BEGIN","END");
70 BEGIN at the BEGIN keyword and END at the END;
71 BEGIN at the beginning and end at the END;
73 # USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
74 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
76 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
79 # USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
80 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
83 BEGIN at the beginning and end at the end;
84 BEGIN at the BEGIN keyword and END at the end;
86 # TEST EXTRACTION OF TAGGED STRINGS
87 # USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
89 BEGIN at the BEGIN keyword and END at the end;
91 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
95 # USING: gen_extract_tagged();
97 <B>some text<A>other text</A></B>;
98 <A>some text<A>other text</A></A>;
99 <A HREF="#section2">some text</A>;
103 <A>some text<A>other text</A>;
104 <B>some text<A>other text</B>;