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..37\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("|",map {defined $_ ? $_ : '<undef>'} @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('{','}');
64 # USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
65 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
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;
71 # USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
72 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
74 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
77 # USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
78 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
81 BEGIN at the beginning and end at the end;
82 BEGIN at the BEGIN keyword and END at the end;
84 # TEST EXTRACTION OF TAGGED STRINGS
85 # USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
87 BEGIN at the BEGIN keyword and END at the end;
89 # USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
93 # USING: gen_extract_tagged();
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>;
101 <A>some text<A>other text</A>;
102 <B>some text<A>other text</B>;