version 1.1, 2004/12/06 20:27:38
|
version 1.2, 2004/12/06 20:34:57
|
Line 35 http://www.lon-capa.org/
|
Line 35 http://www.lon-capa.org/
|
<file> |
<file> |
<target dist="default">/home/httpd/lonUsers</target> |
<target dist="default">/home/httpd/lonUsers</target> |
<perlscript mode="fg"> |
<perlscript mode="fg"> |
#use the directory |
|
use strict; |
use strict; |
use HTML::Parser; |
use HTML::Parser; |
|
|
Line 45 my $version = $HTML::Parser::VERSION;
|
Line 45 my $version = $HTML::Parser::VERSION;
|
## First test |
## First test |
## |
## |
my $text=''; |
my $text=''; |
my $p = HTML::Parser->new(api_version => 3); |
my $p = HTML::Parser->new(api_version => 3); |
$p->handler(start => |
$p->handler(start => |
sub { |
sub { |
my($tag, $attr) = @_; |
my($tag, $attr) = @_; |
$text .= "S[$tag"; |
$text .= "S[$tag"; |
for my $k (sort keys %$attr) { |
for my $k (sort keys %$attr) { |
my $v = $attr->{$k}; |
my $v = $attr->{$k}; |
$text .= " key $k= value $v"; |
$text .= " key $k= value $v"; |
} |
} |
$text .= "]"; |
$text .= "]"; |
}, "tagname,attr"); |
}, "tagname,attr"); |
$p->handler(text => |
$p->handler(text => |
sub { |
sub { |
$text .= 'T{'.shift().'}'; |
$text .= 'T{'.shift().'}'; |
}, "text"); |
}, "text"); |
$text=''; |
$text=''; |
$p->parse('<img a="b" "=\'"\' c=d />')->eof; |
$p->parse('<img a="b" "=\'"\' c=d />')->eof; |
|
|
my $first_test_result = $text; |
my $first_test_result = $text; |
my $first_expected_result = |
my $first_expected_result = |
Line 69 my $first_expected_result =
|
Line 69 my $first_expected_result =
|
if (! $first_test_result) { |
if (! $first_test_result) { |
print "Unable to run first HTML::Parser test\n"; |
print "Unable to run first HTML::Parser test\n"; |
} elsif ($first_test_result ne $first_expected_result) { |
} elsif ($first_test_result ne $first_expected_result) { |
print <<"END"; |
print <<"END"; |
**** WARNING: HTML::Parser is not working properly. |
**** WARNING: HTML::Parser is not working properly. |
You are using version $version. For test 1 it returned |
You are using version $version. For test 1 it returned |
"$first_test_result" |
"$first_test_result" |
END |
END |
} else { |
|
print "First HTML::Parser test looks good.\n"; |
|
} |
} |
|
|
|
|
## |
## |
## Second test |
## Second test |
## |
## |
$p->xml_mode(1); |
$p->xml_mode(1); |
$text=''; |
$text=''; |
$p->parse('<img a="b" "=\'"\' c=d />')->eof; |
$p->parse('<img a="b" "=\'"\' c=d />')->eof; |
my $second_test_result = $text; |
my $second_test_result = $text; |
my $second_expected_result = |
my $second_expected_result = |
q{S[img key "= value " key a= value b key c= value d]}; |
q{S[img key "= value " key a= value b key c= value d]}; |
if (! $second_test_result) { |
if (! $second_test_result) { |
print "Unable to run second HTML::Parser test\n"; |
print "Unable to run second HTML::Parser test\n"; |
} elsif ($second_test_result ne $second_expected_result) { |
} elsif ($second_test_result ne $second_expected_result) { |
print <<"END"; |
print <<"END"; |
**** WARNING: HTML::Parser is not working properly. |
**** WARNING: HTML::Parser is not working properly. |
You are using version $version. For test 2 it returned |
You are using version $version. For test 2 it returned |
"$second_test_result" |
"$second_test_result" |
END |
END |
} else { |
|
print "Second HTML::Parser test looks good.\n"; |
|
} |
} |
|
|
</perlscript> |
</perlscript> |