Skip to content


Subversion checkout URL

You can clone with
Download ZIP
69 lines (56 sloc) 2.91 KB
use v6;
use Test;
# L<S32::IO/IO::Path>
plan 36;
# make sure we have a controlled environment here
my $*SPEC = IO::Spec::Unix;
my $*CWD = '/zip/loc'.IO;
my $relpath ='foo/bar' );
my $abspath ='/foo/bar');
isa-ok $abspath, IO::Path, "Can create IO::Path::Unix";
is $abspath.volume, "", "volume is empty on POSIX";
is $abspath.dirname, "/foo", 'dirname "/foo/bar" -> "/foo"';
is $abspath.basename, "bar", 'basename "/foo/bar" -> "bar"';
my $path ='foo//bar//');
is $path.dirname, "foo", 'dirname "foo//bar//" -> "foo"';
is $path.basename, "bar", 'basename "foo//bar//" -> "bar"';
isa-ok $path.path, Str, ".path returns Str";
say $path.perl;
is $path.perl.EVAL, $path, ".perl loopback";
is".").Str, ".", "current directory";
is"..").Str, "..", "parent directory";
throws-like { }, Exception, "no path not allowed";
throws-like {'') }, Exception, "empty not allowed";
"cleanup '/usr/////local/./bin/././perl/' -> '/usr/local/bin/perl'";
ok $, "relative path is-relative";
nok $, "relative path ! is-absolute";
nok $, "absolute path ! is-relative";
ok $, "absolute path is-absolute";
is $relpath.absolute, IO::Spec::Unix.canonpath("$*CWD/foo/bar"),
"absolute path from \$*CWD";
is $relpath.absolute("/usr"), "/usr/foo/bar",
"absolute path specified";
is"/usr/bin").relative("/usr"), "bin",
"relative path specified";
is $relpath.absolute.IO.relative, "foo/bar",
"relative inverts absolute";
is $relpath.absolute("/foo").IO.relative("/foo"),
"foo/bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink RT #124782'
is $abspath.relative.IO.absolute.IO.resolve, "/foo/bar", "absolute inverts relative with resolve";
is"foo/bar").parent, "foo", "parent of 'foo/bar' is 'foo'";
is"foo").parent, ".", "parent of 'foo' is '.'";
is".").parent, "..", "parent of '.' is '..'";
is"..").parent, "../..", "parent of '..' is '../..'";
is"/foo").parent, "/", "parent at top level is '/'";
is"/").parent, "/", "parent of root is '/'";
is"/").child('foo'), "/foo", "append to root";
is".").child('foo'), "foo", "append to cwd";
my $numfile ="foo/file01.txt");
is $numfile.succ, "foo/file02.txt", "succ basic";
is $numfile.succ.succ, "foo/file03.txt", "succ x 2";
is $numfile.pred, "foo/file00.txt", "pred basic";
is"foo/()").succ, "foo/()", "succ only effects basename";
is"foo/()").succ, "foo/()", "pred only effects basename";
Jump to Line
Something went wrong with that request. Please try again.