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'
4 ######################### We start with some black magic to print on failure.
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
9 BEGIN { $| = 1; print "1..35\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Text::Balanced qw ( gen_extract_tagged );
15 use vars qw( $DEBUG );
16 sub debug { print "\t>>>",@_ if $DEBUG }
18 ######################### End of black magic.
23 while (defined($str = <DATA>))
27 if ($str =~ s/\A# USING://)
30 eval{local$^W;*f = eval $str || die};
33 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
34 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
36 debug "\tUsing: $cmd\n";
37 debug "\t on: [$str]\n";
40 $var = eval { @res = f($str) };
41 debug "\t list got: [" . join("|",@res) . "]\n";
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;
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;
61 # USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
62 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
64 # USING: gen_extract_tagged("BEGIN","END");
65 BEGIN at the BEGIN keyword and END at the END;
66 BEGIN at the beginning and end at the END;
68 # USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
69 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
71 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
74 # USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
75 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
78 BEGIN at the beginning and end at the end;
79 BEGIN at the BEGIN keyword and END at the end;
81 # TEST EXTRACTION OF TAGGED STRINGS
82 # USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
84 BEGIN at the BEGIN keyword and END at the end;
86 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
90 # USING: gen_extract_tagged();
92 <B>some text<A>other text</A></B>;
93 <A>some text<A>other text</A></A>;
94 <A HREF="#section2">some text</A>;
98 <A>some text<A>other text</A>;
99 <B>some text<A>other text</B>;