#!perl -Tw
use strict;
use Test;
my $DEBUG = 2;
BEGIN { plan tests => 40 }
use HTML::TreeBuilder;
print "#Using HTML::TreeBuilder version v$HTML::TreeBuilder::VERSION\n";
print "#Using HTML::Element version v$HTML::Element::VERSION\n";
print "#Using HTML::Parser version v", $HTML::Parser::VERSION || "?", "\n";
print "#Using HTML::Entities version v", $HTML::Entities::VERSION || "?", "\n";
print "#Using HTML::Tagset version v", $HTML::Tagset::VERSION || "?", "\n";
print "# Running under perl version $] for $^O",
(chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n";
print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber();
print "# MacPerl verison $MacPerl::Version\n"
if defined $MacPerl::Version;
printf
"# Current time local: %s\n# Current time GMT: %s\n",
scalar(localtime($^T)), scalar(gmtime($^T));
ok 1;
{
my $tree = HTML::TreeBuilder->new;
$tree->parse('
fooI like pie');
$tree->eof;
ok($tree->as_XML,
"
foo"
."I like pie
\n"
);
$tree->delete;
}
ok !same('x' => 'y', 1);
ok !same('' => 'y', 1);
ok same('' => '');
ok same('' => ' ');
ok same('' => ' ');
ok same('' => '');
ok same('' => '');
ok same('' => \'
');
ok same('' => '');
ok same('' => \'');
ok same( '
' => '
' );
ok same( '
' => '
' );
ok same( '
' => '
' );
ok !same( '
' => '
', 1 );
ok same( 'abc xyz' => 'abc xyz' );
ok same( 'abc xyz' => 'abc xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
print "#\n# Now some list tests.\n#\n";
ok same('after' => 'after');
ok same('after' => 'after');
ok same('after' => 'after');
ok same('after' =>
\'after');
print "#\n# Now some table tests.\n#\n";
ok same('x| y | z'
=> '');
ok same('x| y | z'
=> '');
ok same( ''
=> '');
ok same( ''
=> \'');
ok same('x' => 'x');
ok same('x' => 'x');
ok same('x' => 'x');
ok same('x' => 'x');
ok same('x' => 'x');
ok same('x' => '| x');
print "#\n# Now some p tests.\n#\n";
ok same(' x y z' => ' x y z');
ok same(' x y z' => ' x y z ');
ok same('x y z' => ' x y z ');
ok same('x y z' => \' x y z ');
sub same {
my($code1, $code2, $flip) = @_;
my $t1 = HTML::TreeBuilder->new;
my $t2 = HTML::TreeBuilder->new;
if(ref $code1) { $t1->implicit_tags(0); $code1 = $$code1 }
if(ref $code2) { $t2->implicit_tags(0); $code2 = $$code2 }
$t1->parse($code1); $t1->eof;
$t2->parse($code2); $t2->eof;
my $out1 = $t1->as_XML;
my $out2 = $t2->as_XML;
my $rv = ($out1 eq $out2);
#print $rv? "RV TRUE\n" : "RV FALSE\n";
#print $flip? "FLIP TRUE\n" : "FLIP FALSE\n";
if($flip ? (!$rv) : $rv) {
if($DEBUG > 2) {
print
"In1 $code1\n",
"In2 $code2\n",
"Out1 $out1\n",
"Out2 $out2\n",
"\n\n";
}
} else {
local $_;
foreach my $line (
'',
"The following failure is at " . join(' : ' ,caller),
"Explanation of failure: " . ($flip ? 'same' : 'different')
. " parse trees!",
"Input code 1:", $code1,
"Input code 2:", $code2,
"Output tree (as XML) 1:", $out1,
"Output tree (as XML) 2:", $out2,
) {
$_ = $line;
s/\n/\n# /g;
print "# ", $_, "\n";
}
}
$t1->delete;
$t2->delete;
return $rv;
}
|
| |
| |