File: linkextor-base.t

package info (click to toggle)
libhtml-parser-perl 3.55-1%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 528 kB
  • ctags: 192
  • sloc: ansic: 1,986; perl: 1,935; makefile: 43
file content (41 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (7)
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
37
38
39
40
41
# This test that HTML::LinkExtor really absolutize links correctly
# when a base URL is given to the constructor.

use Test::More tests => 5;
require HTML::LinkExtor;

SKIP: {
eval {
   require URI;
};
skip $@, 5 if $@;

# Try with base URL and the $p->links interface.
$p = HTML::LinkExtor->new(undef, "http://www.sn.no/foo/foo.html");
$p->parse(<<HTML)->eof;
<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

@p = $p->links;

# There should be 4 links in the document
is(@p, 4);

for (@p) {
    ($t, %attr) = @$_ if $_->[0] eq 'img';
}

is($t, 'img');

is(delete $attr{src}, "http://www.sn.no/foo/img.jpg");

is(delete $attr{lowsrc}, "http://www.sn.no/foo/img.gif");

ok(!scalar(keys %attr)); # there should be no more attributes
}