|
Packit Service |
82e721 |
# Before `make install' is performed this script should be runnable with
|
|
Packit Service |
82e721 |
# `make test'. After `make install' it should work as `perl test.pl'
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
######################### We start with some black magic to print on failure.
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# Change 1..1 below to 1..last_test_to_print .
|
|
Packit Service |
82e721 |
# (It may become useful if the test is moved to ./t subdirectory.)
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
BEGIN { $| = 1; print "1..37\n"; }
|
|
Packit Service |
82e721 |
END {print "not ok 1\n" unless $loaded;}
|
|
Packit Service |
82e721 |
use Text::Balanced qw ( gen_extract_tagged );
|
|
Packit Service |
82e721 |
$loaded = 1;
|
|
Packit Service |
82e721 |
print "ok 1\n";
|
|
Packit Service |
82e721 |
$count=2;
|
|
Packit Service |
82e721 |
use vars qw( $DEBUG );
|
|
Packit Service |
82e721 |
sub debug { print "\t>>>",@_ if $DEBUG }
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
######################### End of black magic.
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
$cmd = "print";
|
|
Packit Service |
82e721 |
$neg = 0;
|
|
Packit Service |
82e721 |
while (defined($str = <DATA>))
|
|
Packit Service |
82e721 |
{
|
|
Packit Service |
82e721 |
chomp $str;
|
|
Packit Service |
82e721 |
$str =~ s/\\n/\n/g;
|
|
Packit Service |
82e721 |
if ($str =~ s/\A# USING://)
|
|
Packit Service |
82e721 |
{
|
|
Packit Service |
82e721 |
$neg = 0;
|
|
Packit Service |
82e721 |
eval{local$^W;*f = eval $str || die};
|
|
Packit Service |
82e721 |
next;
|
|
Packit Service |
82e721 |
}
|
|
Packit Service |
82e721 |
elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
|
|
Packit Service |
82e721 |
elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
|
|
Packit Service |
82e721 |
$str =~ s/\\n/\n/g;
|
|
Packit Service |
82e721 |
debug "\tUsing: $cmd\n";
|
|
Packit Service |
82e721 |
debug "\t on: [$str]\n";
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
my @res;
|
|
Packit Service |
82e721 |
$var = eval { @res = f($str) };
|
|
Packit Service |
82e721 |
debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
|
|
Packit Service |
82e721 |
debug "\t list left: [$str]\n";
|
|
Packit Service |
82e721 |
print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
|
|
Packit Service |
82e721 |
print "ok ", $count++;
|
|
Packit Service |
82e721 |
print " ($@)" if $@ && $DEBUG;
|
|
Packit Service |
82e721 |
print "\n";
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
pos $str = 0;
|
|
Packit Service |
82e721 |
$var = eval { scalar f($str) };
|
|
Packit Service |
82e721 |
$var = "<undef>" unless defined $var;
|
|
Packit Service |
82e721 |
debug "\t scalar got: [$var]\n";
|
|
Packit Service |
82e721 |
debug "\t scalar left: [$str]\n";
|
|
Packit Service |
82e721 |
print "not " if ($str =~ '\A;')==$neg;
|
|
Packit Service |
82e721 |
print "ok ", $count++;
|
|
Packit Service |
82e721 |
print " ($@)" if $@ && $DEBUG;
|
|
Packit Service |
82e721 |
print "\n";
|
|
Packit Service |
82e721 |
}
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
__DATA__
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged('{','}');
|
|
Packit Service |
82e721 |
{ a test };
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged(qr/<[A-Z]+>/,undef, undef, {ignore=>[" "]});
|
|
Packit Service |
82e721 |
aaabbb cccddd;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged("BEGIN","END");
|
|
Packit Service |
82e721 |
BEGIN at the BEGIN keyword and END at the END;
|
|
Packit Service |
82e721 |
BEGIN at the beginning and end at the END;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged(undef,undef,undef,{ignore=>["<[^>]*/>"]});
|
|
Packit Service |
82e721 |
aaabbb cccddd;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"MAX"});
|
|
Packit Service |
82e721 |
; at the ;-) keyword
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged("<[A-Z]+>",undef, undef, {ignore=>[" "]});
|
|
Packit Service |
82e721 |
aaabbb cccddd;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# THESE SHOULD FAIL
|
|
Packit Service |
82e721 |
BEGIN at the beginning and end at the end;
|
|
Packit Service |
82e721 |
BEGIN at the BEGIN keyword and END at the end;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# TEST EXTRACTION OF TAGGED STRINGS
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged("BEGIN","END",undef,{reject=>["BEGIN","END"]});
|
|
Packit Service |
82e721 |
# THESE SHOULD FAIL
|
|
Packit Service |
82e721 |
BEGIN at the BEGIN keyword and END at the end;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged(";","-",undef,{reject=>[";"],fail=>"PARA"});
|
|
Packit Service |
82e721 |
; at the ;-) keyword
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# USING: gen_extract_tagged();
|
|
Packit Service |
82e721 |
some text;
|
|
Packit Service |
82e721 |
some textother text;
|
|
Packit Service |
82e721 |
some textother text;
|
|
Packit Service |
82e721 |
some text;
|
|
Packit Service |
82e721 |
|
|
Packit Service |
82e721 |
# THESE SHOULD FAIL
|
|
Packit Service |
82e721 |
some text
|
|
Packit Service |
82e721 |
some textother text;
|
|
Packit Service |
82e721 |
some textother text;
|