-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use 5.006; | ||
use strict; | ||
use warnings; | ||
use Test::More 0.92; | ||
use File::Temp; | ||
use Test::Deep qw/cmp_deeply/; | ||
use File::pushd qw/pushd/; | ||
|
||
use lib 't/lib'; | ||
use PCNTest; | ||
|
||
use Path::Iterator::Rule; | ||
|
||
{ | ||
|
||
package CheckOrder; | ||
|
||
use parent 'Path::Iterator::Rule'; | ||
use PCNTest; | ||
|
||
our $order; | ||
our $td; | ||
|
||
sub new { | ||
( my $class, $td, $order ) = @_; | ||
$class->SUPER::new(); | ||
} | ||
|
||
sub _children { | ||
my $self = shift; | ||
my $path = "" . shift; | ||
|
||
push @$order, 'children:'. unixify( $path, $td ); | ||
|
||
opendir( my $dh, $path ); | ||
return map { [ $_, "$path/$_" ] } | ||
grep { $_ ne "." && $_ ne ".." } readdir $dh; | ||
} | ||
|
||
} | ||
|
||
#--------------------------------------------------------------------------# | ||
|
||
{ | ||
my @tree = qw( | ||
aaaa.txt | ||
bbbb.txt | ||
cccc/dddd.txt | ||
cccc/eeee/ffff.txt | ||
gggg.txt | ||
); | ||
|
||
my @breadth = qw( | ||
visit:. | ||
children:. | ||
visit:aaaa.txt | ||
visit:bbbb.txt | ||
visit:cccc | ||
visit:gggg.txt | ||
children:cccc | ||
visit:cccc/dddd.txt | ||
visit:cccc/eeee | ||
children:cccc/eeee | ||
visit:cccc/eeee/ffff.txt | ||
); | ||
|
||
my @depth_pre = qw( | ||
visit:. | ||
children:. | ||
visit:aaaa.txt | ||
visit:bbbb.txt | ||
visit:cccc | ||
children:cccc | ||
visit:cccc/dddd.txt | ||
visit:cccc/eeee | ||
children:cccc/eeee | ||
visit:cccc/eeee/ffff.txt | ||
visit:gggg.txt | ||
); | ||
|
||
my $td = make_tree(@tree); | ||
|
||
my ( $iter, @order ); | ||
my $rule = CheckOrder->new( $td, \@order ); | ||
|
||
@order = (); | ||
my $visitor = sub { | ||
push @order, 'visit:'.unixify($_, $td); | ||
}; | ||
|
||
$rule->all( { depthfirst => 0, visitor => $visitor }, $td ); | ||
cmp_deeply( \@order, \@breadth, "Breadth first iteration" ) | ||
or diag explain \@order; | ||
|
||
@order = (); | ||
$rule->all( { depthfirst => -1, visitor => $visitor }, $td ); | ||
cmp_deeply( \@order, \@depth_pre, "Depth first iteration (pre)" ) | ||
or diag explain \@order; | ||
|
||
@order = (); | ||
$rule->all( { depthfirst => 1, visitor => $visitor }, $td ); | ||
|
||
# post and pre have same visit/children pattern | ||
cmp_deeply( \@order, \@depth_pre, "Depth first iteration (post)" ) | ||
or diag explain \@order; | ||
} | ||
|
||
done_testing; | ||
# COPYRIGHT |