App-Relate-Complex
view release on metacpan or search on metacpan
t/00-App-Relate-Complex.t view on Meta::CPAN
{
my $loc = "$tree";
my @terms = ( 'AAA111', 'the_s', 'pixies' );
my $how_many = 4;
foreach my $term (@terms) {
if ($loc =~ m/$term/i) {
skip "tests invalid because $term matches the path, $loc", $how_many;
last;
}
}
my @terms_original = @terms;
my $opt_a = {
add_filters => ":jpeg",
};
my $opt_b = { # should be the same as opt_a case
no_default_filters => 1,
add_filters => ":jpeg",
};
my $opt_c = {
add_filters => ":web_img",
};
my $opt_d = { # should be the same as opt_c case
no_default_filters => 1,
add_filters => ":web_img",
};
my $matches_a = $lfr->relate_complex( \@terms, $opt_a );
my $matches_b = $lfr->relate_complex( \@terms, $opt_b );
my $matches_c = $lfr->relate_complex( \@terms, $opt_c );
my $matches_d = $lfr->relate_complex( \@terms, $opt_d );
#
is_deeply( [ sort( @terms ) ], [ sort( @terms_original ) ],
"Testing that the relate_complex method does not modify search terms array");
($DEBUG) && print STDERR "matches_a: ", Data::Dumper::Dumper($matches_a), "\n";
($DEBUG) && print STDERR "matches_b: ", Data::Dumper::Dumper($matches_b), "\n";
($DEBUG) && print STDERR "matches_c: ", Data::Dumper::Dumper($matches_c), "\n";
($DEBUG) && print STDERR "matches_d: ", Data::Dumper::Dumper($matches_d), "\n";
my @expected_a = sort( (
"$tree/AAA111/pixies/the_second.jpg",
"$tree/AAA111/pixies/the_sixth.jpg",
"$tree/AAA111/pixies/the_second.JPG",
"$tree/AAA111/pixies/the_sixth.JPG",
));
my @expected_c = sort( (
"$tree/AAA111/pixies/the_second.jpg",
"$tree/AAA111/pixies/the_sixth.jpg",
"$tree/AAA111/pixies/the_second.GIF",
"$tree/AAA111/pixies/the_sixth.GIF",
"$tree/AAA111/pixies/the_second.JPG",
"$tree/AAA111/pixies/the_sixth.JPG",
"$tree/AAA111/pixies/the_second.png",
"$tree/AAA111/pixies/the_sixth.png",
));
my @sorted_matches_a = sort @{ $matches_a };
is_deeply( \@sorted_matches_a, \@expected_a, "$test_name: ':jpeg' with default filter on");
my @sorted_matches_b = sort @{ $matches_b };
is_deeply( \@sorted_matches_b, \@expected_a, "$test_name: ':jpeg' with default off");
my @sorted_matches_c = sort @{ $matches_c };
is_deeply( \@sorted_matches_c, \@expected_c, "$test_name: ':web_img' filter with default on");
my @sorted_matches_d = sort @{ $matches_d };
is_deeply( \@sorted_matches_d, \@expected_c, "$test_name: ':web_img' filter with default off");
} # end skip -- $term matches path
}
{ #25, #26, #27, #28
# This is a contrived test to use two sets of filters together: there are *.JPG files
# hidden insides a CVS directory so they'll be screened out by the ':hide_vc'
my $test_name = "Testing relate_complex method using stacked filters and a regexp search with dwim trans";
my $lfr = App::Relate::Complex->new( {
storage => $stash,
locatedb => $db
} );
SKIP:
{
my $loc = "$tree";
my @terms = ( 'BBB222', 'the_', 'da_' ); # we will use two together as a regexp: 'the_|da_'
my $how_many = 4;
foreach my $term (@terms) {
if ($loc =~ m/$term/i) {
skip "tests invalid because $term matches the path, $loc", $how_many;
last;
}
}
my @terms_original = @terms;
# first try should match all of them
my $test_case_a = ":web_img filter, w/o default";
my $opt_a = {
no_default_filters => 1,
add_filters => ':web_img',
};
# this should screen out the ones inside the CVS directory
my $test_case_b = ":web_img and :dires-x-omit filters, w/o default";
my $opt_b = {
no_default_filters => 1,
add_filters => ":web_img :hide_vc",
};
# two relatively inane tests: the same deal with :jpeg instead of :web_img
my $test_case_c = ":jpeg filter, w/o default";
my $opt_c = { # same as set a
no_default_filters => 1,
add_filters => ":jpeg",
};
( run in 1.296 second using v1.01-cache-2.11-cpan-df04353d9ac )