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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!perl
use strict;
use Test::More 0.88;
use String::Formatter
stringf => {
-as => 'pos_stringf',
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
},
stringf => {
-as => 'named_stringf',
input_processor => 'require_named_input',
string_replacer => 'named_replace',
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
},
named_stringf => {
-as => 'ns2',
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
},
indexed_stringf => {
codes => {
f => sub { $_ },
r => sub { scalar reverse $_ },
},
}
;
{
my $have = pos_stringf(
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");
}
{
my $have = named_stringf(
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 $have = ns2(
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 (named_stringf import)");
}
{
my $have = indexed_stringf(
q(do it %{1}f way and %{0}r way),
[ qw(that this) ],
);
my $want = 'do it this way and taht way';
is($have, $want, "named args via conversions (indexed_stringf import)");
}
done_testing;
|