File: RT40714-2.t

package info (click to toggle)
libhtml-template-pluggable-perl 0.22%2B~cs0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 312 kB
  • sloc: perl: 421; makefile: 17
file content (44 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
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
use Test::More;
use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
eval "use Number::Format;";
plan skip_all => 'Number::Format required for these tests' if $@;
plan tests => 3;

sub render {
    my( $template, %vars ) = @_;
    my $result;

    eval {     
        my $t = new HTML::Template::Pluggable(
            scalarref => \$template,
            case_sensitive => 1,
        );
        $t->param( %vars );
    
        $result = $t->output;
    };
    diag $@ if $@;
    return $result;
}

my $out;

$out = render( 
    "Amount: <tmpl_var order.total_amount>",
    order     => { total_amount => 12.2 }
);
is( $out, 'Amount: 12.2', 'Substitute value from hashref' );

my $formatter = new Number::Format;
ok( $formatter && $formatter->isa('Number::Format'), 'Instantiate Number::Format' );

$out = render(
    q{Amount: <tmpl_var name="Formatter.format_price(order.total_amount, 2, 'USD ')">},
    Formatter => $formatter,
    order     => { total_amount => 12.2 }
);
is( $out, 'Amount: ' . $formatter->format_price(12.20, 2, 'USD ') );

__END__
1..0 # SKIP Number::Format required for these tests