App-MtAws
view release on metacpan or search on metacpan
t/unit/filter.t view on Meta::CPAN
#
# _patterns_to_regexp correctness of escapes
#
check 'z/ex.mple',
ismatch => ['z/ex.mple'],
nomatch => ['z/exNmple'];
check 'z/ex\\dmple',
ismatch => ['z/ex\\dmple'],
nomatch => ['z/ex1mple'];
check 'z/ex{1,2}mple',
ismatch => ['z/ex{1,2}mple'],
nomatch => ['z/exmple', 'z/exxmple'];
check 'z/ex[1|2]mple',
ismatch => ['z/ex[1|2]mple'],
nomatch => ['z/ex2mple', 'z/ex1mple'];
# simply test with fixtures
{
my $F = {};
App::MtAws::Filter::_init_substitutions($F, "\Q**\E" => '.*', "\Q*\E" => '[^/]*');
is $F->{all_re}, '(\\\\\\*\\\\\\*|\\\\\\*)';
cmp_deeply $F->{subst}, {'\\*' => '[^/]*','\\*\\*' => '.*'}, "substitutions work";
$F = {};
App::MtAws::Filter::_init_substitutions($F, "\Q*\E" => '[^/]*');
is $F->{all_re}, '(\\\\\\*)';
cmp_deeply $F->{subst}, {'\\*' => '[^/]*'}, "substitutions work";
}
#
# parse_filters
#
# simply test with fixtures
{
my $F = App::MtAws::Filter->new();
$F->parse_filters('-abc -dir/ +*.gz', '-!*.txt');
cmp_deeply $F->{filters},
[
{
'pattern' => 'abc',
're' => qr/(^|\/)abc$/,
'action' => '-',
'match_subdirs' => '',
'notmatch' => '',
},
{
'pattern' => 'dir/',
# Test::Deep problem here https://rt.cpan.org/Ticket/Display.html?id=85785
# looks like perl 5.8.x issue with regexp stringification
're' => do { my $s = '(^|/)dir\/'; qr/$s/ },
'action' => '-',
'match_subdirs' => 1,
'notmatch' => '',
},
{
'pattern' => '*.gz',
're' => qr/(^|\/)[^\/]*\.gz$/,
'action' => '+',
'match_subdirs' => '',
'notmatch' => '',
},
{
'pattern' => '!*.txt',
're' => qr/(^|\/)[^\/]*\.txt$/,
'action' => '-',
'match_subdirs' => '',
'notmatch' => '1',
}
];
}
#
# parse_include
#
{
my $F = App::MtAws::Filter->new();
$F->parse_include('*.gz');
cmp_deeply $F->{filters},[{
'pattern' => '*.gz',
'notmatch' => bool(0),
're' => qr/(^|\/)[^\/]*\.gz$/,
'action' => '+',
'match_subdirs' => bool(0)
}];
}
{
my $F = App::MtAws::Filter->new();
$F->parse_include('!*.gz');
cmp_deeply $F->{filters}, [{
'pattern' => '!*.gz',
'notmatch' => bool(1),
're' => qr/(^|\/)[^\/]*\.gz$/,
'action' => '+',
'match_subdirs' => bool(0)
}];
}
{
my $F = App::MtAws::Filter->new();
$F->parse_exclude('*.gz');
cmp_deeply $F->{filters},[{
'pattern' => '*.gz',
'notmatch' => bool(0),
're' => qr/(^|\/)[^\/]*\.gz$/,
'action' => '-',
'match_subdirs' => bool(0)
}];
( run in 1.979 second using v1.01-cache-2.11-cpan-98e64b0badf )