File: number.t

package info (click to toggle)
libhtml-template-pluggable-perl 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 264 kB
  • ctags: 16
  • sloc: perl: 369; sh: 28; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 2,167 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
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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;
plan tests => 3 +
              5;

use_ok('HTML::Template::Pluggable');
use_ok('HTML::Template::Plugin::Dot');
use_ok('HTML::Template::Plugin::Dot::Helpers');

my $t1 = HTML::Template::Pluggable->new(
    scalarref       => \q{<tmpl_var name="Number.format_picture(some.value, '#,###,###.##')">=<tmpl_var some.value>},
    global_vars     => 1,
    case_sensitive  => 1,
    die_on_bad_params => 0,
    );
$t1->param( some => { value => 3_105_345.239_5 } );
my $o1 = $t1->output;
# diag("output: ", $o1);
like( $o1, qr/3,10/ );


my $t2 = HTML::Template::Pluggable->new(
    scalarref       => \q{<tmpl_if Number.gt(some.value,3)><tmpl_var name="Number.format_picture(some.value, '#,###,###.##')">=<tmpl_var some.value><tmpl_else>No</tmpl_if>},
    global_vars     => 1,
    case_sensitive  => 1,
    die_on_bad_params => 0,
    );
$t2->param( some => { value => 3_105_345.239_5 } );
my $o2 = $t2->output;
# diag("output: ", $o2);
like( $o2, qr/3,10/ );

$t2->param( some => { value => 1.053_45 } );
my $o3 = $t2->output;
# diag("output: ", $o3);
like( $o3, qr/No/ );

{
   package My::Obj;
   use overload q{""} => \&stringify, '0+' => \&stringify, fallback => 1;
   
   sub new { bless {id=>3}, shift }
   sub stringify { return $_[0]->{id} }
}

my $t3 = HTML::Template::Pluggable->new(
    scalarref       => \q{<tmpl_if name="Number.lt(some.obj, some.value)">Yes<tmpl_else>No</tmpl_if> (<tmpl_var some.value> <tmpl_var some.obj>)},
    global_vars     => 1,
    case_sensitive  => 1,
    die_on_bad_params => 0,
    );
$t3->param( some => { value => 3_105_345.239_5, obj => My::Obj->new  } );
my $o4 = $t3->output;
# diag("output: ", $o4);
like( $o4, qr/Yes/ );

SKIP: {
    skip "test dependent on locale", 1;
my $t4 = HTML::Template::Pluggable->new(
    scalarref       => \q{<tmpl_loop o.v:h><tmpl_var h.n> <tmpl_var name="Number.format_price(h.n)"></tmpl_loop>},
    global_vars     => 1,
    case_sensitive  => 1,
    die_on_bad_params => 0,
    );
$t4->param( o => { v => [ { n => 1.25 }, { n => 2.25 } ] } );
my $o5 = $t4->output;
# diag("output: ", $o4);
like( $o5, qr/USD 2.25/ );
};


__END__