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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Data::Stream::Bulk::Path::Class;
use Path::Class;
my $dist = file(__FILE__)->parent->parent;
foreach my $dir ( $dist->subdir("t"), $dist->subdir("lib"), $dist ) {
{
my $paths = Data::Stream::Bulk::Path::Class->new(
dir => $dir,
chunk_size => 2,
depth_first => 0,
);
my $strings = $paths->filter(sub {[ grep { !/tmp/ } map { "$_" } @$_ ]});
my @rec;
$dir->recurse( callback => sub { push @rec, "$_[0]" unless $_[0] =~ /tmp/ }, depthfirst => 0, preorder => 1 );
ok( !$_->is_done, "not done" ) for $paths, $strings;
my @all = $strings->all;
ok( $_->is_done, "done" ) for $paths, $strings;
is_deeply(
[ sort @all ],
[ sort @rec ],
"breadth first traversal path set",
);
is_deeply(
\@all,
\@rec,
"breadth first traversal order",
);
}
{
my $paths = Data::Stream::Bulk::Path::Class->new(
dir => $dir,
chunk_size => 2,
depth_first => 1,
);
my $strings = $paths->filter(sub {[ grep { !/tmp/ } map { "$_" } @$_ ]});
my @rec;
$dir->recurse( callback => sub { push @rec, "$_[0]" unless $_[0] =~ /tmp/ }, depthfirst => 1, preorder => 1 );
ok( !$_->is_done, "not done" ) for $paths, $strings;
my @all = $strings->all;
ok( $_->is_done, "done" ) for $paths, $strings;
is_deeply(
[ sort @all ],
[ sort @rec ],
"depth first traversal path set",
);
is_deeply(
\@all,
\@rec,
"depth first traversal order",
);
}
{
my $paths = Data::Stream::Bulk::Path::Class->new(
dir => $dir,
chunk_size => 2,
depth_first => 0,
only_files => 1,
);
my $strings = $paths->filter(sub {[ grep { !/tmp/ } map { "$_" } @$_ ]});
my @rec;
$dir->recurse( callback => sub { push @rec, "$_[0]" if $_[0] !~ /tmp/ and -f $_[0] }, depthfirst => 0, preorder => 1 );
ok( !$_->is_done, "not done" ) for $paths, $strings;
my @all = $strings->all;
ok( $_->is_done, "done" ) for $paths, $strings;
is_deeply(
[ sort @all ],
[ sort @rec ],
"breadth first traversal path set",
);
is_deeply(
\@all,
\@rec,
"breadth first traversal order",
);
}
}
done_testing;
|