Blame t/92_blacklist.t

Packit f92f8e
#!/usr/bin/perl -Tw
Packit f92f8e
Packit f92f8e
use strict;
Packit f92f8e
use warnings;
Packit f92f8e
use Test::More tests => 17;
Packit f92f8e
Packit f92f8e
BEGIN {
Packit f92f8e
    use_ok("Locale::Maketext");
Packit f92f8e
}
Packit f92f8e
Packit f92f8e
{
Packit f92f8e
Packit f92f8e
    package MyTestLocale;
Packit f92f8e
    no warnings 'once';
Packit f92f8e
Packit f92f8e
    @MyTestLocale::ISA     = qw(Locale::Maketext);
Packit f92f8e
    %MyTestLocale::Lexicon = ();
Packit f92f8e
}
Packit f92f8e
Packit f92f8e
{
Packit f92f8e
Packit f92f8e
    package MyTestLocale::en;
Packit f92f8e
    no warnings 'once';
Packit f92f8e
Packit f92f8e
    @MyTestLocale::en::ISA = qw(MyTestLocale);
Packit f92f8e
Packit f92f8e
    %MyTestLocale::en::Lexicon = ( '_AUTO' => 1 );
Packit f92f8e
Packit f92f8e
    sub custom_handler {
Packit f92f8e
        return "custom_handler_response";
Packit f92f8e
    }
Packit f92f8e
Packit f92f8e
    sub _internal_method {
Packit f92f8e
        return "_internal_method_response";
Packit f92f8e
    }
Packit f92f8e
Packit f92f8e
    sub new {
Packit f92f8e
        my ( $class, @args ) = @_;
Packit f92f8e
        my $lh = $class->SUPER::new(@args);
Packit f92f8e
        $lh->{use_external_lex_cache} = 1;
Packit f92f8e
        return $lh;
Packit f92f8e
    }
Packit f92f8e
}
Packit f92f8e
Packit f92f8e
my $lh = MyTestLocale->get_handle('en');
Packit f92f8e
my $res;
Packit f92f8e
Packit f92f8e
# get_handle blocked by default
Packit f92f8e
$res = eval { $lh->maketext('[get_handle,en]') };
Packit f92f8e
is( $res, undef, 'no return value from blocked expansion' );
Packit f92f8e
like( $@, qr/Can't use .* as a method name/, 'get_handle blocked in bracket notation by default blacklist' );
Packit f92f8e
Packit f92f8e
# _ambient_langprefs blocked by default
Packit f92f8e
$res = eval { $lh->maketext('[_ambient_langprefs]') };
Packit f92f8e
is( $res, undef, 'no return value from blocked expansion' );
Packit f92f8e
like( $@, qr/Can't use .* as a method name/, '_ambient_langprefs blocked in bracket notation by default blacklist' );
Packit f92f8e
Packit f92f8e
# _internal_method not blocked by default
Packit f92f8e
$res = eval { $lh->maketext('[_internal_method]') };
Packit f92f8e
is( $res, "_internal_method_response", '_internal_method allowed in bracket notation by default blacklist' );
Packit f92f8e
is( $@, '', 'no exception thrown by use of _internal_method under default blacklist' );
Packit f92f8e
Packit f92f8e
# sprintf not blocked by default
Packit f92f8e
$res = eval { $lh->maketext('[sprintf,%s,hello]') };
Packit f92f8e
is( $res, "hello", 'sprintf allowed in bracket notation by default blacklist' );
Packit f92f8e
is( $@,   '',      'no exception thrown by use of sprintf under default blacklist' );
Packit f92f8e
Packit f92f8e
# blacklisting sprintf and numerate
Packit f92f8e
$lh->blacklist( 'sprintf', 'numerate' );
Packit f92f8e
Packit f92f8e
# sprintf blocked by custom blacklist
Packit f92f8e
$res = eval { $lh->maketext('[sprintf,%s,hello]') };
Packit f92f8e
is( $res, undef, 'no return value from blocked expansion' );
Packit f92f8e
like( $@, qr/Can't use .* as a method name/, 'sprintf blocked in bracket notation by custom blacklist' );
Packit f92f8e
Packit f92f8e
# blacklisting numf and _internal_method
Packit f92f8e
$lh->blacklist('numf');
Packit f92f8e
$lh->blacklist('_internal_method');
Packit f92f8e
Packit f92f8e
# sprintf blocked by custom blacklist
Packit f92f8e
$res = eval { $lh->maketext('[sprintf,%s,hello]') };
Packit f92f8e
is( $res, undef, 'no return value from blocked expansion' );
Packit f92f8e
like( $@, qr/Can't use .* as a method name/, 'sprintf blocked in bracket notation by custom blacklist after extension of blacklist' );
Packit f92f8e
Packit f92f8e
# _internal_method blocked by custom blacklist
Packit f92f8e
$res = eval { $lh->maketext('[_internal_method]') };
Packit f92f8e
is( $res, undef, 'no return value from blocked expansion' );
Packit f92f8e
like( $@, qr/Can't use .* as a method name/, 'sprintf blocked in bracket notation by custom blacklist after extension of blacklist' );
Packit f92f8e
Packit f92f8e
# custom_handler not in default or custom blacklist
Packit f92f8e
$res = eval { $lh->maketext('[custom_handler]') };
Packit f92f8e
is( $res, "custom_handler_response", 'custom_handler allowed in bracket notation by default and custom blacklists' );
Packit f92f8e
is( $@, '', 'no exception thrown by use of custom_handler under default and custom blacklists' );