### ----------------------------------------------------
### -- URI
### -- Licenses: Artistic-2.0
### -- Authors: Raku community
### -- File: t/path.rakutest
### ----------------------------------------------------
use Test;

use URI;

plan 14;

my $q = URI.new('foo:/a/b/c');
isa-ok $q.path, URI::Path;
ok $q.path.defined;

with $q.path {
    is $_, "/a/b/c";
    is .path, "/a/b/c";
    is-deeply .segments, $('', 'a', 'b', 'c');
}

$q.path('a/b/c');
with $q.path {
    is $_, "a/b/c";
    is .path, "a/b/c";
    is-deeply .segments, $('a', 'b', 'c');
}

# with auth, path starting with / is required
throws-like {
    $q.host('localhost');
}, X::URI::Invalid;

$q.path('/a/b/c');
lives-ok {
    $q.host('localhost');
};
is "$q", 'foo://localhost/a/b/c';

$q.host('');
is "$q", 'foo:///a/b/c';

$q.authority(Nil);
is "$q", 'foo:/a/b/c';

# without auth first segment after / must be non-zero length
throws-like {
    $q.path('//a/b/c');
}, X::URI::Invalid;

# vim: expandtab shiftwidth=4


