Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 68 lines (53 sloc) 2.963 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use v6;
use Test;
# L<S32::IO/IO::Path>

plan 37;

my $relpath = IO::Path::Unix.new('foo/bar' );
my $abspath = IO::Path::Unix.new('/foo/bar');
isa_ok $abspath, IO::Path::Unix, "Can create IO::Path::Unix";
is $abspath.volume, "", "volume is empty on POSIX";
is $abspath.directory, "/foo", 'directory "/foo/bar" -> "/foo"';
is $abspath.basename, "bar", 'basename "/foo/bar" -> "bar"';

my $path = IO::Path::Unix.new('foo//bar//');
is $path.directory, "foo", 'directory "foo//bar//" -> "foo"';
is $path.basename, "bar", 'basename "foo//bar//" -> "bar"';
isa_ok $path.path, IO::Path::Unix, ".path returns itself";
is $path.perl.EVAL, $path, ".perl loopback";

is IO::Path::Unix.new(".").Str, ".", "current directory";
is IO::Path::Unix.new("..").Str, "..", "parent directory";
is IO::Path::Unix.new('').Str, "", "empty is empty";

is IO::Path::Unix.new("/usr/////local/./bin/././perl/").cleanup, "/usr/local/bin/perl",
"cleanup '/usr/////local/./bin/././perl/' -> '/usr/local/bin/perl'";

ok $relpath.is-relative, "relative path is-relative";
nok $relpath.is-absolute, "relative path ! is-absolute";
nok $abspath.is-relative, "absolute path ! is-relative";
ok $abspath.is-absolute, "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 IO::Path::Unix.new("/usr/bin").relative("/usr"), "bin", "relative path specified";
is $relpath.absolute.relative, "foo/bar", "relative inverts absolute";
is $relpath.absolute("/foo").relative("/foo"), "foo/bar","absolute inverts relative";
#?rakudo 1 todo 'resolve NYI, needs nqp::readlink'
is $abspath.relative.absolute.resolve, "/foo/bar", "absolute inverts relative with resolve";

is IO::Path::Unix.new("foo/bar").parent, "foo", "parent of 'foo/bar' is 'foo'";
is IO::Path::Unix.new("foo").parent, ".", "parent of 'foo' is '.'";
is IO::Path::Unix.new(".").parent, "..", "parent of '.' is '..'";
is IO::Path::Unix.new("..").parent, "../..", "parent of '..' is '../..'";
is IO::Path::Unix.new("/foo").parent, "/", "parent at top level is '/'";
is IO::Path::Unix.new("/").parent, "/", "parent of root is '/'";

is IO::Path::Unix.new("/").child('foo'), "/foo", "append to root";
is IO::Path::Unix.new(".").child('foo'), "foo", "append to cwd";

my $numfile = IO::Path::Unix.new("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 IO::Path::Unix.new("foo/()").succ, "foo/()", "succ only effects basename";
is IO::Path::Unix.new("foo/()").succ, "foo/()", "pred only effects basename";

if IO::Spec.FSTYPE eq 'Unix' {
ok IO::Path::Unix.new(~$*CWD).e, "cwd exists, filetest inheritance ok";
ok IO::Path::Unix.new(~$*CWD).d, "cwd is a directory";
}
else {
skip "On-system tests for filetest inheritance", 2;
}


done;

Something went wrong with that request. Please try again.