<commit_before>use v6;
use Test;
# L<S32::IO/IO::Path>

plan 46;

my $relpath = IO::Path::Win32.new('foo\\bar' );
my $abspath = IO::Path::Win32.new('\\foo\\bar');

isa_ok $abspath, IO::Path::Win32, "Can create IO::Path::Win32";
is $abspath.volume,	"",		'volume "\\foo\\bar" -> ""';
is $abspath.directory, 	"\\foo",	'directory "\\foo\\bar" -> "\\foo"';
is $abspath.basename, 	"bar",		'basename "\\foo\\bar" -> "bar"';

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

my $uncpath = IO::Path::Win32.new("\\\\server\\share\\");
is $uncpath.volume,	"\\\\server\\share",	'volume "\\\\server\\share\\" -> ""\\\\server\\share"';
is $uncpath.directory, 	"\\",	'directory "\\\\server\\share\\" -> "\\"';
is $uncpath.basename, 	"\\",	'basename "\\\\server\\share\\" -> "\\"';
is $uncpath.Str, "\\\\server\\share", '"\\\\server\\share" restringifies to itself';

my $uncpath2 = IO::Path::Win32.new("//server/share/a");
is $uncpath2.volume,	"//server/share",	'volume "//server/share/a" -> ""//server/share"';
is $uncpath2.directory, "/",	'directory "//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 IO::Path::Win32.new(".").Str,		".",		"current directory";
is IO::Path::Win32.new("..").Str,		"..",		"parent directory";
is IO::Path::Win32.new('').Str,			"",		"empty is empty";

is IO::Path::Win32.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";
ok $uncpath.is-absolute,	"UNC path is-absolute";
ok $uncpath2.is-absolute,	"UNC path with forward slash is-absolute";
ok IO::Path::Win32.new("/foo").is-absolute,	"path beginning with forward slash is absolute";
ok IO::Path::Win32.new("A:\\").is-absolute,	'"A:\\" is absolute';
ok IO::Path::Win32.new("A:b").is-relative,	'"A:b" is relative';


is $relpath.absolute,		IO::Spec::Win32.canonpath("$*CWD\\foo\\bar"),	"absolute path from \$*CWD";
is $relpath.absolute("\\usr"),	"\\usr\\foo\\bar",		"absolute path specified";
is IO::Path::Win32.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 skip 'resolve NYI, needs nqp::readlink'
is $abspath.relative.absolute.resolve, "\\foo\\bar",	"absolute inverts relative with resolve";<commit_msg>fudge IO::Path.absolute due to infinite recursion on Win32<commit_after>use v6;
use Test;
# L<S32::IO/IO::Path>

plan 46;

my $relpath = IO::Path::Win32.new('foo\\bar' );
my $abspath = IO::Path::Win32.new('\\foo\\bar');

isa_ok $abspath, IO::Path::Win32, "Can create IO::Path::Win32";
is $abspath.volume,	"",		'volume "\\foo\\bar" -> ""';
is $abspath.directory, 	"\\foo",	'directory "\\foo\\bar" -> "\\foo"';
is $abspath.basename, 	"bar",		'basename "\\foo\\bar" -> "bar"';

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

my $uncpath = IO::Path::Win32.new("\\\\server\\share\\");
is $uncpath.volume,	"\\\\server\\share",	'volume "\\\\server\\share\\" -> ""\\\\server\\share"';
is $uncpath.directory, 	"\\",	'directory "\\\\server\\share\\" -> "\\"';
is $uncpath.basename, 	"\\",	'basename "\\\\server\\share\\" -> "\\"';
is $uncpath.Str, "\\\\server\\share", '"\\\\server\\share" restringifies to itself';

my $uncpath2 = IO::Path::Win32.new("//server/share/a");
is $uncpath2.volume,	"//server/share",	'volume "//server/share/a" -> ""//server/share"';
is $uncpath2.directory, "/",	'directory "//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 IO::Path::Win32.new(".").Str,		".",		"current directory";
is IO::Path::Win32.new("..").Str,		"..",		"parent directory";
is IO::Path::Win32.new('').Str,			"",		"empty is empty";

is IO::Path::Win32.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";
ok $uncpath.is-absolute,	"UNC path is-absolute";
ok $uncpath2.is-absolute,	"UNC path with forward slash is-absolute";
ok IO::Path::Win32.new("/foo").is-absolute,	"path beginning with forward slash is absolute";
ok IO::Path::Win32.new("A:\\").is-absolute,	'"A:\\" is absolute';
ok IO::Path::Win32.new("A:b").is-relative,	'"A:b" is relative';

#?rakudo 5 skip '.absolute with no args causes infinite loop on windows'
is $relpath.absolute,		IO::Spec::Win32.canonpath("$*CWD\\foo\\bar"),	"absolute path from \$*CWD";
is $relpath.absolute("\\usr"),	"\\usr\\foo\\bar",		"absolute path specified";
is IO::Path::Win32.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 skip 'resolve NYI, needs nqp::readlink'
is $abspath.relative.absolute.resolve, "\\foo\\bar",	"absolute inverts relative with resolve";
{'fraction_non_alphanumeric': 0.2679066731930168, 'fraction_numerical': 0.015500081579376733, 'mean_word_length': 3.987794955248169, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3907010', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2331, 'n_words': 484}