#!/usr/bin/perl -T
our
$tests
;
BEGIN { ++
$INC
{
'tests.pm'
} }
sub
tests'VERSION {
$tests
+=
pop
};
plan
tests
=>
$tests
;
{
my
$doc
= new HTML::DOM;
$doc
->
write
(
'<title></title><body>some text</body>'
);
is+(
my
$elem
=
$doc
->documentElement)->as_text,
'some text'
,
'HTML::DOM::Element::HTML->as_text'
;
like
$elem
->as_HTML,
qr/^[^~]+\z/
,
'HTML::DOM::Element::HTML->as_HTML'
;
isa_ok
$elem
, HTML::DOM::Element::class_for(
'html'
);
can_ok
$elem
,
'version'
;
}
{
my
$doc
= new HTML::DOM;
$doc
->
write
(
'<table><tr><td>foo</table>'
);
like
$doc
->find(
'table'
)->as_HTML,
qr\<table><tbody><tr><td>foo</td></tr></tbody></table>$\
,
'implicit tbody'
;
}
{
my
$doc
= new HTML::DOM;
$doc
->
write
(
'<table><tr><td>a<td>b</table>'
);
$doc
->
close
;
like
$doc
->documentElement->as_HTML,
qr\^<html><head></head><body>(?x:
)<table>(?x:
)<tbody><tr><td>a</td><td>b</td></tr></tbody>(?x:
)</table>(?x:
)</body></html>$\
,
'<td><td>'
;
}
{
my
$doc
= new HTML::DOM;
$doc
->
write
(
'<body><!--foo-->'
);
$doc
->
close
;
like
$doc
->documentElement->as_HTML,
qr\^<html><head></head><body>(?x:
)<!--foo-->(?x:
)</body></html>$\
,
'parsing comments'
;
isa_ok
$doc
->body->firstChild,
'HTML::DOM::Comment'
,
'parsed comment'
;
}
{
my
$doc
= new HTML::DOM;
$doc
->
write
(
'<table><tr><th>'
.
'<table><tr><td>'
.
'<table><tr><th>A</td><td>B</th><td>C</table>'
.
'</table></table>'
);
$doc
->
close
;
is
$doc
->innerHTML,
'<html><head></head><body>'
.
"<table><tbody><tr><th>"
.
"<table><tbody><tr><td>"
.
"<table><tbody><tr>"
.
"<th>A</th><td>B</td><td>C</td>"
.
"</tr></tbody></table>"
.
"</td></tr></tbody></table>"
.
"</th></tr></tbody></table>"
.
"</body></html>"
,
'parsing unmatched </td> and </th>'
;
}
{
my
$doc
= new HTML::DOM;
$doc
->innerHTML(
'<form><body><input name=foo value=bar>'
);
is
join
(
","
,
$doc
->forms->[0]->form),
"foo,bar"
,
'<form><body> does not imply </form>'
;
}