Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (84 sloc) 3.61 KB
use v6;
use Test;
plan 47;
use URI;
ok(1,'We use URI and we are still alive');
my $u ='');
is($u.scheme, 'http', 'scheme');
is($, '', 'host');
is($u.port, '80', 'port');
is($u.path, '/about/us', 'path');
is($u.query, 'foo', 'query');
is($u.frag, 'bar', 'frag');
is($u.segments, 'about us', 'segements');
is($u.segments[0], 'about', 'first chunk');
is($u.segments[1], 'us', 'second chunk');
is( ~$u, '',
'Complete path stringification');
# allow uri as named argument too
$u = => 'https://eXAMplE.COM');
is($u.scheme, 'https', 'scheme');
is($, '', 'host');
is( "$u", '',
'https://eXAMplE.COM stringifies to');
is($u.port, 443, 'default https port');
ok(! $u._port.defined, 'no specified port');
is($u.segments, 'foo bar baz', 'segments from absolute path');
ok($u.absolute, 'absolute path');
nok($u.relative, 'not relative path');
is($u.segments, 'foo bar baz', 'segements from relative path');
ok( $u.relative, 'relative path');
nok($u.absolute, 'not absolute path');
is($u.segments[0], 'foo', 'first segment');
is($u.segments[1], 'bar', 'second segment');
is($u.segments[*-1], 'baz', 'last segment');
# actual uri parameter not required
$u =;
ok($u.segments == 1 && $u.segments[0] eq '', ".segments return [''] for empty path");
ok($u.absolute, ' has an absolute path');
nok($u.relative, ' does not have a relative path');
is($u.port, 80, 'default http port');
# test URI parsing with <> or "" and spaces
$u.parse("<> ");
is("$u", '', '<> removed from str');
$u.parse(' ""');
is("$u", '', '"" removed from str');
my $host_in_grammar =
ok(! $host_in_grammar<IPv4address>.defined, 'grammar detected host not ip'
is($host_in_grammar<reg_name>, '', 'grammar detected registered domain style');
is($, '', 'numeric host');
$host_in_grammar =
is($host_in_grammar<IPv4address>, '', 'grammar detected ipv4');
ok(! $host_in_grammar<reg_name>.defined, 'grammar detected no registered domain style');
is($u.query, 'foo=cod&bell=bob', 'query with form params');
is($u.query_form<foo>, 'cod', 'query param foo');
is($u.query_form<bell>, 'bob', 'query param bell');
is($u.query_form<foo>[0], 'cod', 'query param foo - el 1');
is($u.query_form<foo>[1], 'trout', 'query param foo - el 2');
is($u.frag, 'bar', 'test query and frag capture');
is($u.query_form<foo>[1], 'trout', 'query param foo - el 2 without frag');
is($u.query_form<foo>[1], 'trout', 'query param foo - el 2 relative path');
is($u.query_form<foo>[1], 'trout', 'query param foo - el 2 relative path without frag');
my ($url_1_valid, $url_2_valid) = (1, 1);
try {
my $u_v ='http:://', :is_validating<1>);
is($url_1_valid, 1, 'validating parser okd good URI');
$u_v ='http:://?#?#', :is_validating<1>);
default { $url_2_valid = 0 }
is($url_2_valid, 0, 'validating parser rejected bad URI');
# vim:ft=perl6
Jump to Line
Something went wrong with that request. Please try again.