#!perl
use
5.020;
my
@tests
= (
{
html
=>
'<html></html>'
,
options
=> {},
expected
=> {},
name
=>
'Empty HTML'
},
{
html
=>
'<html><title>in head</title></html>'
,
options
=> {},
expected
=> {
title
=>
'in head'
},
name
=>
'title tag'
},
{
html
=>
'<html><meta property="og:title" content="FB title" /></html>'
,
options
=> {},
expected
=> {
title
=>
'FB title'
},
name
=>
'opengraph title tag'
},
{
html
=>
'<html><meta property="twitter:title" content="X title"/></html>'
,
options
=> {},
expected
=> {
title
=>
'X title'
},
name
=>
'Twitter title tag'
},
{
html
=>
'<html><title>in head</title><h1>in first H1 tag</h1></html>'
,
options
=> {},
expected
=> {
title
=>
'in head'
},
name
=>
'title tag takes precedence over H1 tag'
},
{
html
=>
'<html><h1>in first H1 tag</h1><h1>in second H1 tag</h1></html>'
,
options
=> {},
expected
=> {
title
=>
'in first H1 tag'
},
name
=>
'H1 tag'
},
{
html
=>
'<html></html>'
,
name
=>
'URL is taken from options'
},
options
=> {},
name
=>
'canonical URL'
},
name
=>
'canonical URL takes precedence'
},
);
for
my
$t
(
@tests
) {
my
$name
=
$t
->{name};
my
$tree
= XML::LibXML->new->parse_html_string(
$t
->{html},
{
recover
=> 2,
encoding
=>
'UTF-8'
}
);
my
$expected
=
$t
->{expected};
if
(! is( extract_info(
$tree
,
$t
->{options}->%* ),
$expected
,
$name
)) {
diag
$t
->{html};
}
}
done_testing();