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..53\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Text::Balanced qw ( extract_tagged 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>))
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 }
30 debug "\tUsing: $cmd\n";
31 debug "\t on: [$str]\n";
34 $var = eval "\@res = $cmd";
35 debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
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;
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;
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;
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;
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;
67 ignore\n this and then BEGINTHIS at the ENDTHAT;
69 # USING: extract_tagged($str,"BEGIN","END","(?s).*?(?=BEGIN)");
70 ignore\n this and then BEGIN at the END;
72 # USING: extract_tagged($str);
73 <A-1 HREF="#section2">some text</A-1>;
75 # USING: extract_tagged($str,qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
76 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
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;
82 # USING: extract_tagged($str,undef,undef,undef,{ignore=>["<[^>]*/>"]});
83 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
85 # USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"MAX"});
88 # USING: extract_tagged($str,"<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
89 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
92 BEGIN at the beginning and end at the end;
93 BEGIN at the BEGIN keyword and END at the end;
95 # TEST EXTRACTION OF TAGGED STRINGS
96 # USING: extract_tagged($str,"BEGIN","END",undef,{reject=>["BEGIN","END"]});
98 BEGIN at the BEGIN keyword and END at the end;
100 # USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"PARA"});
104 # USING: extract_tagged($str);
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>;
112 <A>some text<A>other text</A>;
113 <B>some text<A>other text</B>;