From c1e62143efd788bfbf9928fbbda512a0e978ec01 Mon Sep 17 00:00:00 2001 From: Cosimo Streppone Date: Sun, 27 Jun 2010 17:49:21 +0200 Subject: [PATCH] Tests for the URL parsing code --- t/parse-url.t | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 t/parse-url.t diff --git a/t/parse-url.t b/t/parse-url.t new file mode 100644 index 0000000..0992091 --- /dev/null +++ b/t/parse-url.t @@ -0,0 +1,41 @@ +# +# 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"); +} + +done_testing; +