Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use smartmatch to compare paths #1

Merged
merged 1 commit into from Feb 14, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions t/01-file-find.t
Expand Up @@ -5,13 +5,13 @@ plan 10;

my $res = find(:dir<t/dir1>);
my @test = $res.map({ .Str }).sort;
is @test, <t/dir1/another_dir t/dir1/another_dir/empty_file t/dir1/another_dir/file.bar t/dir1/file.bar t/dir1/file.foo t/dir1/foodir t/dir1/foodir/not_a_dir>, 'just a dir';
equals @test, <t/dir1/another_dir t/dir1/another_dir/empty_file t/dir1/another_dir/file.bar t/dir1/file.bar t/dir1/file.foo t/dir1/foodir t/dir1/foodir/not_a_dir>, 'just a dir';

# names

$res = find(:dir<t/dir1>, :name(/foo/));
@test = $res.map({ .Str }).sort;
is @test, <t/dir1/file.foo t/dir1/foodir t/dir1/foodir/not_a_dir>, 'name with regex';
equals @test, <t/dir1/file.foo t/dir1/foodir t/dir1/foodir/not_a_dir>, 'name with regex';

# (default) recursive find

Expand All @@ -30,15 +30,15 @@ is $res.elems, 0, 'no results';

$res = find(:dir<t/dir1>, :type<dir>);
@test = $res.map({ .Str }).sort;
is @test, <t/dir1/another_dir t/dir1/foodir>, 'types: dir';
equals @test, <t/dir1/another_dir t/dir1/foodir>, 'types: dir';

$res = find(:dir<t/dir1>, :type<dir>, :name(/foo/));
@test = $res.map({ .Str }).sort;
is @test, <t/dir1/foodir>, 'types: dir, combined with name';
equals @test, <t/dir1/foodir>, 'types: dir, combined with name';

$res = find(:dir<t/dir1>, :type<file>, :name(/foo/));
@test = $res.map({ .Str }).sort;
is @test, <t/dir1/file.foo t/dir1/foodir/not_a_dir>,
equals @test, <t/dir1/file.foo t/dir1/foodir/not_a_dir>,
'types: file, combined with name';

#keep-going
Expand Down Expand Up @@ -71,4 +71,8 @@ if 0 {
LEAVE { &dir.unwrap($w); }
}

sub equals(\a, \b, $name) {
ok ([&&] a >>~~<< b.map(*.path)), $name
}

exit 0; # I have no idea what I'm doing, but I get Non-zero exit status w/o this