summaryrefslogtreecommitdiff
path: root/t/linkextor-rel.t
blob: 1190a96c3f0c70e709a2893752c6b2b6890f56d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use Test::More tests => 4;

require HTML::LinkExtor;

$HTML = <<HTML;
<head>
<base href="http://www.sn.no/">
</head>
<body background="http://www.sn.no/sn.gif">

This is <A HREF="link.html">link</a> and an <img SRC="img.jpg"
lowsrc="img.gif" alt="Image">.
HTML


# Try the callback interface
$links = "";
$p = HTML::LinkExtor->new(
  sub {
      my($tag, %links) = @_;
      #diag "$tag @{[%links]}";
      $links .= "$tag @{[%links]}\n";
  });

$p->parse($HTML); $p->eof;

ok($links =~ m|^base href http://www\.sn\.no/$|m);
ok($links =~ m|^body background http://www\.sn\.no/sn\.gif$|m);
ok($links =~ m|^a href link\.html$|m);

# Used to be problems when using the links method on a document with
# no links it it.  This is a test to prove that it works.
$p = new HTML::LinkExtor;
$p->parse("this is a document with no links"); $p->eof;
@a = $p->links;
is(@a, 0);