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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t'
use Test::More tests => 11;
BEGIN { use_ok('HTML::Template::Compiled') };
eval {
my $htc = HTML::Template::Compiled->new(
scalarref => \<<'EOM',
<tmpl_if foo>bar</tmpl_if>
<%if foo %>bar<%/if%>
<%if foo %>bar
EOM
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
line_numbers => 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/Missing closing tag for 'IF'/, "premature end of template");
# test wrong balanced tag
my $wrong;
eval {
$wrong = HTML::Template::Compiled->new(
path => 't/templates',
line_numbers => 1,
filename => 'wrong.html',
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/does not match opening tag/ , "wrong template");
eval {
my $htc = HTML::Template::Compiled->new(
path => 't/templates',
filename => 'notexist.htc',
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/not found/ , "template not found");
eval {
my $str = <<'EOM';
<tmpl_include name="notexist.htc">
EOM
my $htc = HTML::Template::Compiled->new(
path => 't/templates',
scalarref => \$str,
debug => $ENV{HARNESS_ACTIVE} ? 0 : 1,
);
};
print "err: $@\n" unless $ENV{HARNESS_ACTIVE};
ok($@ =~ m/not found/ , "template from include not found");
{
my @wrong = (
"<TMPL_VA foo>",
"<TMPL_VAR foo oops>",
"<TMPL_IF blah escape=html>",
"foo<TMPL_IF >",
);
for my $wrong (@wrong) {
eval {
my $htc = HTML::Template::Compiled->new(
scalarref => \$wrong,
debug => 0,
);
};
print STDERR "Error? $@\n" unless $ENV{HARNESS_ACTIVE};;
cmp_ok($@, "=~", qr{\Q: Syntax error in <TMPL_*> tag at }, "die when syntax is wrong");
}
}
{
my $tmpl = <<"EOM";
<tmpl_var foo>
<tmpl_foo
<tmpl_var foo>
end
EOM
for my $strict (0, 1) {
my $out = '';
eval {
my $htc = HTML::Template::Compiled->new(
scalarref => \$tmpl,
strict => $strict,
);
$htc->param(foo => 23);
$out = $htc->output;
};
my $err = $@;
if ($strict) {
cmp_ok($err, '=~', qr{\Q Syntax error in <TMPL_*> tag at }, "unknown tag strict");
}
else {
$out =~ s/\s+/ /g;
my $exp = '23 <tmpl_foo 23 end ';
cmp_ok($out, 'eq', $exp, "unknown tag no strict");
}
}
}
|