Skip to content

Commit fb61306

Browse files
committed
[io grant] Test IO::Path.parts attribute
1 parent 8ae81c0 commit fb61306

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

S32-io/io-path.t

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use lib <t/spec/packages/>;
33
use Test;
44
use Test::Util;
55

6-
plan 33;
6+
plan 34;
77

88
# L<S32::IO/IO::Path>
99

@@ -293,3 +293,48 @@ subtest 'combiners on "/" do not interfere with absolute path detection' => {
293293
plan +@Path-Types;
294294
is-deeply .is-absolute, True, .perl for @Path-Types.map: *.new: "/\x[308]";
295295
}
296+
297+
subtest '.parts attribute' => {
298+
plan 5 + 6*@Path-Types;
299+
300+
sub check-parts($in, $desc, *%parts) {
301+
subtest 'parts match' => {
302+
plan 1 + %parts;
303+
is-deeply $in.WHAT, Map, 'parts is a Map';
304+
is-deeply $in{$_}, %parts{$_}, "$_ is correct" for %parts.keys;
305+
}
306+
}
307+
308+
for @Path-Types {
309+
check-parts .new('foo').parts, "foo {.perl}",
310+
:basename<foo>, :dirname<.>, :volume('');
311+
312+
check-parts .new('./foo').parts, "./foo {.perl}",
313+
:basename<foo>, :dirname<.>, :volume('');
314+
315+
check-parts .new('bar/foo').parts, "bar/foo {.perl}",
316+
:basename<foo>, :dirname<bar>, :volume('');
317+
318+
check-parts .new('/bar/foo').parts, "/bar/foo {.perl}",
319+
:basename<foo>, :dirname</bar>, :volume('');
320+
321+
my $p = .new('/').parts;
322+
check-parts $p, "/ {.perl}", :dirname</>, :volume('');
323+
cmp-ok $p<basename>, 'eq', <\ />.any, "/ {.perl} (basename)";
324+
}
325+
326+
check-parts IO::Path::Win32.new('C:foo').parts, "C:foo",
327+
:basename<foo>,:dirname<.>,:volume<C:>;
328+
329+
check-parts IO::Path::Win32.new('C:./foo').parts, "C:./foo",
330+
:basename<foo>,:dirname<.>,:volume<C:>;
331+
332+
check-parts IO::Path::Win32.new('C:bar/foo').parts, "C:bar/foo",
333+
:basename<foo>,:dirname<bar>,:volume<C:>;
334+
335+
check-parts IO::Path::Win32.new('C:/bar/foo').parts, "C:/bar/foo",
336+
:basename<foo>,:dirname</bar>,:volume<C:>;
337+
338+
check-parts IO::Path::Win32.new('C:/').parts, "C:/",
339+
:basename(\),:dirname</>,:volume<C:>;
340+
}

0 commit comments

Comments
 (0)