1use strict;
2use warnings;
3use Test::More tests => 4;
4
5use_ok('HTML::Template');
6
7# normal loop with values
8my $tmpl_string = '<tmpl_if my_loop>You have a loop<tmpl_else>Nope</tmpl_if><tmpl_loop my_loop> Foo: <tmpl_var foo></tmpl_loop>';
9my $template = HTML::Template->new_scalar_ref( \$tmpl_string );
10$template->param( my_loop => [{foo => 1}, {foo => 2}]);
11my $output = $template->output;
12is($output, 'You have a loop Foo: 1 Foo: 2', 'non-empty loop');
13
14# a loop with an empty data structure
15$template = HTML::Template->new_scalar_ref( \$tmpl_string );
16$template->param( my_loop => []);
17$output = $template->output;
18is($output, 'Nope', 'empty loop');
19
20# a loop with data inside the structure, but nothing in the template
21$tmpl_string = '<tmpl_if my_loop>You have a loop<tmpl_else>Nope</tmpl_if><tmpl_loop my_loop></tmpl_loop>';
22$template = HTML::Template->new_scalar_ref( \$tmpl_string, die_on_bad_params => 0 );
23$template->param( my_loop => [{foo => 1}, {foo => 2}]);
24$output = $template->output;
25is($output, 'You have a loop', 'non-empty structure, but empty <tmpl_loop>');
26
27=head1 NAME
28
29t/13-loop-boolean.t
30
31=head1 OBJECTIVE
32
33Provide a test to show that loops (full or empty) should be able to be used as
34booleans in a TMPL_IF along with using an empty loop.
35
36=cut
37