File: 02-random.t

package info (click to toggle)
libhtml-template-perl 2.97-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 740 kB
  • sloc: perl: 2,572; makefile: 8
file content (18 lines) | stat: -rw-r--r-- 530 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Test::More tests => 200;
use HTML::Template;

use strict;

my $text = q{<TMPL_IF foo>YES<TMPL_ELSE>NO</TMPL_IF>};

my $template = HTML::Template->new(scalarref => \$text,);
$template->param(foo => sub { int(rand(2)) });

# make sure HTML::Template never goes both ways down an if, which it
# used to do because it would re-evaluate the conditional at the else.
# Need to test it many times to be sure since it can guess right.
my $good = 1;
for (1 .. 200) {
    my $r = $template->output;
    ok($r eq 'YES' or $r eq 'NO');
}