Skip to content
Go to file
Cannot retrieve contributors at this time
90 lines (70 sloc) 4.5 KB
use v6;
use Test;
# L<S32::IO/IO::Path>
plan 52;
# Make sure we have a controlled environment
my $*SPEC = IO::Spec::Cygwin;
my $*CWD = '\\zip\\loc'.IO;
my $relpath ='foo/bar' );
my $abspath ='/foo/bar');
isa-ok $abspath, IO::Path, "Can create IO::Path::Cygwin";
is $abspath.volume, "", 'volume "/foo/bar" -> ""';
is $abspath.dirname, "/foo", 'dirname "/foo/bar" -> "/foo"';
is $abspath.basename, "bar", 'basename "/foo/bar" -> "bar"';
my $path ='C:foo\\\\bar\\');
is $path.volume, "C:", 'volume "C:foo\\\\bar\\" -> "C:"';
is $path.dirname, "foo", 'dirname "C:foo\\\\bar\\" -> "foo"';
is $path.basename, "bar", 'basename "C:foo\\\\bar\\" -> "bar"';
isa-ok $path.path, Str, ".path returns Str of path";
is $path.raku.EVAL, $path, ".raku loopback";
my $uncpath ="\\\\server\\share\\");
is $uncpath.volume, "//server/share", 'volume "//server/share/" -> ""/server/share"';
is $uncpath.dirname, "/", 'dirname "\\\\server\\share\\" -> "\\"';
is $uncpath.basename, "/", 'basename "\\\\server\\share\\" -> "\\"';
is $uncpath.Str, "\\\\server\\share\\", '"\\\\server\\share" restringifies to itself';
my $uncpath2 ="//server/share/a");
is $uncpath2.volume, "//server/share", 'volume "//server/share/a" -> ""//server/share"';
is $uncpath2.dirname, "/", 'dirname "//server/share/a" -> "/"';
is $uncpath2.basename, "a", 'basename "//server/share/a" -> "a"';
is $uncpath2.Str, "//server/share/a", '"//server/share/a" restringifies to itself';
is".").Str, ".", "current directory";
is"..").Str, "..", "parent directory";
throws-like { }, Exception, "no path not allowed";
throws-like {'') }, Exception, "empty not allowed";
is"/usr/////local/./bin/.\\./perl/").cleanup, "/usr/local/bin/perl",
"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";
ok $, "UNC path is-absolute";
ok $, "UNC path with forward slash is-absolute";
ok"\\foo").is-absolute, "path beginning with backslash is absolute";
ok"A:\\").is-absolute, '"A:\\" is absolute';
ok"A:b").is-relative, '"A:b" is relative';
is $relpath.absolute, IO::Spec::Cygwin.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'
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"\\").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";
isnt'-a').absolute, '',
'.absolute on paths starting with `-` does not produce empty string';
# vim: expandtab shiftwidth=4
You can’t perform that action at this time.