#! /usr/bin/env perl6 use v6.d; use URL::Grammar; use Test; plan 3; subtest "https://www.tyil.nl", { plan 8; my $match = URL::Grammar.parse("https://www.tyil.nl"); is ~$match, "https", "Scheme is 'https'"; nok $match, "URL contains no username"; nok $match, "URL contains no password"; is ~$match, "www.tyil.nl", "Hostname is 'www.tyil.nl'"; nok $match, "URL contains no port"; nok $match, "URL contains no path"; nok $match, "URL contains no query"; nok $match, "URL contains no fragment"; }; subtest "https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#module", { plan 8; my $match = URL::Grammar.parse("https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#module"); is ~$match, "https", "Scheme is 'https'"; is ~$match, "tyil", "Username is 'tyil'"; is ~$match, "donthackme", "Password is 'donthackme'"; is ~$match, "www.tyil.nl", "Hostname is 'www.tyil.nl'"; is +$match, 8443, "Port is 8443"; is ~$match, "module", "Fragment is 'module'"; subtest "path", { plan 4; my @path = $match; is @path.elems, 3, "Path consists of 3 parts"; is @path[0], "a", "Part 0 is 'a'"; is @path[1], "path", "Part 1 is 'path'"; is @path[2], "part", "Part 2 is 'part'"; } subtest "query", { plan 5; my @query = $match; is @query.elems, 2, "Query consists of 2 parts"; is @query[0], "foo", "Part 0's key is 'foo'"; is @query[0], "bar", "Part 0's value is 'bar'"; is @query[1], "perl", "Part 1's key is 'perl'"; is @query[1], "6", "Part 1's value is '6'"; } } subtest 'https://custom.endpoint/foo/bar/', { plan 11; my $match = URL::Grammar.parse('https://custom.endpoint/foo/bar/'); is ~$match, "https", "Scheme is 'https'"; nok $match, 'URL contains no username'; nok $match, 'URL contains no password'; is ~$match, 'custom.endpoint', "Hostname is 'custom.endpoint'"; nok $match, 'URL contains no port'; ok $match, 'URL contains a path'; is $match.elems, 2, 'Path contains 2 elements'; is ~$match[0], 'foo', 'Path part 0 is "foo"'; is ~$match[1], 'bar', 'Path part 0 is "bar"'; nok $match, 'URL contains no query'; nok $match, 'URL contains no fragment'; } # vim: ft=perl6 noet