|
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 |
# _internal_method not blocked by default
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[_internal_method]') };
|
|
Packit |
f92f8e |
is( $res, "_internal_method_response", '_internal_method allowed when no whitelist defined' );
|
|
Packit |
f92f8e |
is( $@, '', 'no exception thrown by use of _internal_method without whitelist setting' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# whitelisting sprintf
|
|
Packit |
f92f8e |
$lh->whitelist('sprintf');
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# _internal_method blocked by whitelist
|
|
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/, '_internal_method blocked in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# sprintf allowed by whitelist
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[sprintf,%s,hello]') };
|
|
Packit |
f92f8e |
is( $res, "hello", 'sprintf allowed in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
is( $@, '', 'no exception thrown by use of sprintf with whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# custom_handler blocked by whitelist
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[custom_handler]') };
|
|
Packit |
f92f8e |
is( $res, undef, 'no return value from blocked expansion' );
|
|
Packit |
f92f8e |
like( $@, qr/Can't use .* as a method name/, 'custom_handler blocked in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# adding custom_handler to whitelist
|
|
Packit |
f92f8e |
$lh->whitelist('custom_handler');
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# sprintf still allowed by whitelist
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[sprintf,%s,hello]') };
|
|
Packit |
f92f8e |
is( $res, "hello", 'sprintf allowed in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
is( $@, '', 'no exception thrown by use of sprintf with whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# custom_handler allowed by whitelist
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[custom_handler]') };
|
|
Packit |
f92f8e |
is( $res, "custom_handler_response", 'custom_handler allowed in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
is( $@, '', 'no exception thrown by use of custom_handler with whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# _internal_method blocked by whitelist
|
|
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/, '_internal_method blocked in bracket notation by whitelist' );
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# adding fail_with to whitelist
|
|
Packit |
f92f8e |
$lh->whitelist('fail_with');
|
|
Packit |
f92f8e |
|
|
Packit |
f92f8e |
# fail_with still blocked by blacklist
|
|
Packit |
f92f8e |
$res = eval { $lh->maketext('[fail_with,xyzzy]') };
|
|
Packit |
f92f8e |
is( $res, undef, 'no return value from blocked expansion' );
|
|
Packit |
f92f8e |
like( $@, qr/Can't use .* as a method name/, 'fail_with blocked in bracket notation by blacklist even when whitelisted' );
|
|
Packit |
f92f8e |
|