App-Relate-Complex
view release on metacpan or search on metacpan
t/00-App-Relate-Complex.t view on Meta::CPAN
my @terms = qw(sex_hundart_und_sexty_sexy compilitations);
my $how_many = 1;
foreach my $term (@terms) {
if ($loc =~ m/$term/i) {
skip "tests invalid because $term matches the path, $loc", $how_many;
last;
}
}
my $matches = $lfr->relate_complex( \@terms, { add_filters => ":c-omit"} );
my @expected = sort( (
"$tree/nother_dir/compilitations/sex_hundart_und_sexty_sexy-one.c",
"$tree/nother_dir/compilitations/sex_hundart_und_sexty_sexy-two.c",
) );
my $matches_sorted = [ sort( @{ $matches } ) ];
is_deeply( $matches_sorted, \@expected, $test_name);
} # end skip -- $term matches path
}
{ #6
my $test_name = "Testing relate_complex method using the :jpeg filter as a filter";
my $lfr = App::Relate::Complex->new( {
storage => $stash,
locatedb => $db
} );
SKIP:
{
my @terms = ('ThreeThree', '^ThreeThree' );
my $how_many = 1;
foreach my $term (@terms) {
if ($loc =~ m/$term/i) {
skip "tests invalid because $term matches the path, $loc", $how_many;
last;
}
}
my $matches = $lfr->relate_complex( \@terms, { add_filters => ":jpeg" } );
my @expected = sort( (
"$tree/ThreeThreeThree.JPG",
"$tree/ThreeThreeTwo.jpeg",
));
my @sorted_matches = sort @{ $matches };
is_deeply( \@sorted_matches, \@expected, $test_name);
} # end skip -- $term matches path
}
} # end skip -- can't create locate db
SKIP:
{ #7 - #15
# Initialize for another series of tests (working the omit filters)
my $db_loc = "$Bin/dat/slocate2";
my $db = "$db_loc/slocate.db";
my $tree = "$Bin/dat/tree2";
my $stash = "$Bin/dat/stash2/stash-not_used.yaml";
my $flh = File::Locate::Harder->new( db => undef );
my $why = '';
if ( not(
$flh->create_database( $tree, $db )
) ) {
$why = "Could not create locate database $db";
} elsif ( not( $flh->probe_db ) ) {
$why = "Can't get File::Locate::Harder to work with $db";
}
if ($why) {
my $how_many = 8;
skip $why, $how_many;
}
{ #7, #8, #9, #10, #11
my $test_name = "Testing relate_complex method using the :skipdull filter";
my $lfr = App::Relate::Complex->new( {
storage => $stash,
locatedb => $db
} );
SKIP:
{
my $loc = "$tree/test7";
my @terms = ('shadow', 'the' );
my $how_many = 5;
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 = {
};
my $opt_b = {
no_default_filters => 1,
};
my $opt_c = { # should be the same as opt_a case
add_filters => ":skipdull",
};
my $opt_d = { # should be the same as opt_a case
no_default_filters => 1,
add_filters => ":skipdull",
};
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");
t/00-App-Relate-Complex.t view on Meta::CPAN
#16
$test_case = "multiple additional filters with no defaults";
$opt = { add_filters => ':doverboys :donkeytails littleamseydivey',
no_default_filters => 1
};
$default_filters = [':skipdull'];
$filter_names = $lfr->setup_filter_names( $opt, $default_filters );
$expected_filters = [
qw( :doverboys :donkeytails littleamseydivey )
];
is_deeply( [ sort @{ $filter_names } ], [ sort @{ $expected_filters } ],
"$test_name: $test_case");
#17
$test_case = "extra-quotes on multiple filters adds, no defaults";
$opt = { add_filters => '\':doverboys :donkeytails littleamseydivey\'',
no_default_filters => 1
};
$default_filters = [':skipdull'];
$filter_names = $lfr->setup_filter_names( $opt, $default_filters );
$expected_filters = [
qw( :doverboys :donkeytails littleamseydivey )
];
is_deeply( [ sort @{ $filter_names } ], [ sort @{ $expected_filters } ],
"$test_name: $test_case");
#18
$test_case = "a single addition to the default";
$opt = { add_filters => 'but_keep_me_anyway',
};
$default_filters = [':skipdull'];
$filter_names = $lfr->setup_filter_names( $opt, $default_filters );
$expected_filters = [
qw( :skipdull but_keep_me_anyway )
];
is_deeply( [ sort @{ $filter_names } ], [ sort @{ $expected_filters } ],
"$test_name: $test_case");
#19
$test_case = "a single filter, without the default";
$opt = { add_filters => 'but_keep_me_anyway',
no_default_filters => 1
};
$default_filters = [':skipdull'];
$filter_names = $lfr->setup_filter_names( $opt, $default_filters );
$expected_filters = [
qw( but_keep_me_anyway )
];
is_deeply( [ sort @{ $filter_names } ], [ sort @{ $expected_filters } ],
"$test_name: $test_case");
}
SKIP:
{ my $test_name = "Testing relate_complex method using the image selection filters";
# Initialize for another series of tests (working the jpeg filters)
my $db_loc = "$Bin/dat/slocate3";
my $db = "$db_loc/slocate.db";
my $tree = "$Bin/dat/tree3";
my $stash = "$Bin/dat/stash3/stash-not_used.yaml";
my $flh = File::Locate::Harder->new( db => undef );
my $why = '';
if ( not(
$flh->create_database( $tree, $db )
) ) {
$why = "Could not create locate database $db";
} elsif ( not( $flh->probe_db ) ) {
$why = "Can't get File::Locate::Harder to work with $db";
}
if ($why) {
my $how_many = 4;
skip $why, $how_many;
}
{
my $lfr = App::Relate::Complex->new( {
storage => $stash,
locatedb => $db
} );
SKIP:
{
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 ) ],
( run in 2.186 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )