1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!perl
use strict;
use Test::More tests => 2;
use String::Formatter;
{
my $fmt = String::Formatter->new({
input_processor => 'require_named_input',
string_replacer => 'named_replace',
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
});
{
my $have = $fmt->format(
q(do it %{alfa}f way and %{beta}r way),
{ alfa => 'this', beta => 'that' },
);
my $want = 'do it this way and taht way';
is($have, $want, "named args via conversions");
}
}
{
my $fmt = String::Formatter->new({
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
});
{
my $have = $fmt->format(
q(do it %f way and %r way),
qw(this that),
);
my $want = 'do it this way and taht way';
is($have, $want, "positional args via conversions");
}
}
|