File: html.t

package info (click to toggle)
liburi-find-perl 20100505-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 148 kB
  • ctags: 24
  • sloc: perl: 655; makefile: 38
file content (38 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w
use strict;
use warnings;

my $Example = <<"END";

Yes, Jim, I found it under "http://www.w3.org/Addressing/",
but you can probably pick it up from <a href="ftp://foo.example.com/rfc/">the RFC</a>. 
Note the <a class="warning" href="http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING" target="_blank">warning</a>.
Also <foo bar>.
<a class="junk" href="http://google.com/search?q=&lt;html&gt;">Search for some entities</a>.
END

# Which should find these URIs
my @Uris = (
      "http://www.w3.org/Addressing/",
      "ftp://foo.example.com/rfc/",
      "http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING",
      "http://google.com/search?q=&lt;html&gt;",
);

use Test::More tests => 5;
use URI::Find;

my @found;
my $finder = URI::Find->new(sub {
    my($uri) = @_;
    push @found, $uri;
    return "Link " . scalar @found;
    
});
$finder->find(\$Example);

is_deeply \@found, \@Uris, "found links in HTML";
like($Example, qr/"Link 1"/, 'link 1 replaced');
like($Example, qr/<a href="Link 2"/, 'link 2 replaced');
like($Example, qr/<a class="warning" href="Link 3"/, 'link 3 replaced');
like($Example, qr/<a class="junk" href="Link 4"/, 'link 4 replaced');