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..53\n"; }
15 END {print "not ok 1\n" unless $loaded;}
16 use Text::Balanced qw ( extract_tagged 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>))
31 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
32 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
33 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
35 debug "\tUsing: $cmd\n";
36 debug "\t on: [$str]\n";
39 $var = eval "\@res = $cmd";
40 debug "\t list got: [" . join("|",@res) . "]\n";
41 debug "\t list left: [$str]\n";
42 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
43 print "ok ", $count++;
44 print " ($@)" if $@ && $DEBUG;
49 $var = "<undef>" unless defined $var;
50 debug "\t scalar got: [$var]\n";
51 debug "\t scalar left: [$str]\n";
52 print "not " if ($str =~ '\A;')==$neg;
53 print "ok ", $count++;
54 print " ($@)" if $@ && $DEBUG;
59 # USING: gen_extract_tagged("BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)")->($str);
60 ignore\n this and then BEGINHERE at the ENDHERE;
61 ignore\n this and then BEGINTHIS at the ENDTHIS;
63 # USING: extract_tagged($str,"BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)");
64 ignore\n this and then BEGINHERE at the ENDHERE;
65 ignore\n this and then BEGINTHIS at the ENDTHIS;
67 # USING: extract_tagged($str,"BEGIN([A-Z]+)",'END$1',"(?s).*?(?=BEGIN)");
68 ignore\n this and then BEGINHERE at the ENDHERE;
69 ignore\n this and then BEGINTHIS at the ENDTHIS;
72 ignore\n this and then BEGINTHIS at the ENDTHAT;
74 # USING: extract_tagged($str,"BEGIN","END","(?s).*?(?=BEGIN)");
75 ignore\n this and then BEGIN at the END;
77 # USING: extract_tagged($str);
78 <A-1 HREF="#section2">some text</A-1>;
80 # USING: extract_tagged($str,qr/<[A-Z]+>/,undef, undef, {ignore=>["<BR>"]});
81 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
83 # USING: extract_tagged($str,"BEGIN","END");
84 BEGIN at the BEGIN keyword and END at the END;
85 BEGIN at the beginning and end at the END;
87 # USING: extract_tagged($str,undef,undef,undef,{ignore=>["<[^>]*/>"]});
88 <A>aaa<B>bbb<BR/>ccc</B>ddd</A>;
90 # USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"MAX"});
93 # USING: extract_tagged($str,"<[A-Z]+>",undef, undef, {ignore=>["<BR>"]});
94 <A>aaa<B>bbb<BR>ccc</B>ddd</A>;
97 BEGIN at the beginning and end at the end;
98 BEGIN at the BEGIN keyword and END at the end;
100 # TEST EXTRACTION OF TAGGED STRINGS
101 # USING: extract_tagged($str,"BEGIN","END",undef,{reject=>["BEGIN","END"]});
103 BEGIN at the BEGIN keyword and END at the end;
105 # USING: extract_tagged($str,";","-",undef,{reject=>[";"],fail=>"PARA"});
109 # USING: extract_tagged($str);
111 <B>some text<A>other text</A></B>;
112 <A>some text<A>other text</A></A>;
113 <A HREF="#section2">some text</A>;
117 <A>some text<A>other text</A>;
118 <B>some text<A>other text</B>;