forked from cosimo/perl6-lwp-simple
/
parse-url.t
46 lines (35 loc) · 1.44 KB
/
parse-url.t
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
42
43
44
45
#
# Test the parse_url() method
#
use v6;
use Test;
use LWP::Simple;
my @test = (
'Simple URL without path',
'http://www.rakudo.org',
['http', 'www.rakudo.org', 80, '/'],
'Port other than 80',
'http://www.altavista.com:81',
['http', 'www.altavista.com', 81, '/'],
'HTTPS scheme, and default port != 80',
'https://www.rakudo.org/rakudo-latest.tar.bz2',
['https', 'www.rakudo.org', 443, '/rakudo-latest.tar.bz2'],
'#GH-1 http://github.com/cosimo/perl6-lwp-simple/issues/#issue/1',
'http://www.c64.com/path/with/multiple/slashes/',
['http', 'www.c64.com', 80, '/path/with/multiple/slashes/'],
'FTP url',
'ftp://get.opera.com/pub/opera/win/1054/en/Opera_1054_en_Setup.exe',
['ftp', 'get.opera.com', 21, '/pub/opera/win/1054/en/Opera_1054_en_Setup.exe'],
);
for @test -> $test, $url, $results {
my ($scheme, $host, $port, $path) = LWP::Simple.parse_url($url);
is($scheme, $results.[0], "Scheme for $url is $scheme");
is($host, $results.[1], "Hostname for $url is $host");
is($port, $results.[2], "Port for $url is $port");
is($path, $results.[3], "Path for $url is $path");
}
# Check that port is returned as a number,
# or IO::Socket::INET.open() fails
my ($scheme, $host, $port, $path) = LWP::Simple.parse_url('http://localhost:5984/foo/test/');
is($port.WHAT, 'Int()', 'port is returned as a Int, to avoid problems on sock.open()');
done_testing;