File: rfc3986_appendix_c.t

package info (click to toggle)
liburi-find-perl 20160806-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 248 kB
  • ctags: 21
  • sloc: perl: 1,388; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 974 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
#!/usr/bin/perl -w

use strict;


# RFC 3986 Appendix C covers "Delimiting a URI in Context"
# and it has this example...

my $Example = <<"END";
Yes, Jim, I found it under "http://www.w3.org/Addressing/",
but you can probably pick it up from <ftp://foo.example.
com/rfc/>.  Note the warning in <http://www.ics.uci.edu/pub/
ietf/uri/historical.html#WARNING>. Also <foo bar>.
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",
);

use Test::More tests => 4;
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, "RFC 3986 Appendix C example";
like($Example, qr/"Link 1"/, 'replaced link 1');
like($Example, qr/<Link 2>/, 'replaced link 2');
like($Example, qr/<Link 3>/, 'replaced link 3');