File: 02-parse.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 (84 lines) | stat: -rw-r--r-- 2,490 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;
use Test::More (tests => 9);
use_ok('HTML::Template');

# testing line 1978
my $tmpl_text = <<EOT;
         <TMPL_LOOP ESCAPE=HTML NAME=EMPLOYEE_INFO>
             Name: <TMPL_VAR NAME=NAME> <br>
             Job:  <TMPL_VAR NAME=JOB>  <p>
          </TMPL_LOOP>
EOT

eval { HTML::Template->new_scalar_ref(\$tmpl_text) };

like($@, qr/ESCAPE option invalid/, "Escape not in TMPL_VAR");

# testing line 1981
$tmpl_text = <<EOT;
         <TMPL_LOOP DEFAULT=foo NAME=EMPLOYEE_INFO>
             Name: <TMPL_VAR NAME=NAME> <br>
             Job:  <TMPL_VAR NAME=JOB>  <p>
          </TMPL_LOOP>
EOT

eval { HTML::Template->new_scalar_ref(\$tmpl_text) };

like($@, qr/DEFAULT option invalid/, "Escape not in TMPL_VAR");

# testing line 1984 else
# not quite checking 1984, deserves some sober attention
$tmpl_text = <<EOT;
     <TMPL_HUH NAME=ZAH>
         Name: <TMPL_VAR NAME=NAME> <br>
         Job:  <TMPL_VAR NAME=JOB>  <p>
      </TMPL_HUH>
EOT
ok(HTML::Template->new_scalar_ref(\$tmpl_text, strict => 0), "Ignores invalid TMPL tags with strict off");

# now with strict on
eval { HTML::Template->new_scalar_ref(\$tmpl_text, strict => 1) };
like($@, qr/Syntax error/, "Spits at invalid TMPL tag with strict on");

# make sure we can use <tmpl_var foo> and <tmpl_var foo /> syntax
my $tmpl = HTML::Template->new(scalarref => \'<tmpl_var foo>:<tmpl_var foo />');
$tmpl->param(foo => 'a');
my $output = $tmpl->output;
is($output, 'a:a', 'both var forms worked');

# attempting to check lines 1540-44
# test using HTML_TEMPLATE_ROOT with path
{
    my $file = 'four.tmpl';    # non-existent file
    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
    eval { HTML::Template->new(path => ['searchpath'], filename => $file) };
    like($@, qr/Cannot open included file $file/, "Template file not found");
}

{
    my $file = 'four.tmpl';    # non-existent file
    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
    eval { HTML::Template->new(filename => $file); };
    like($@, qr/Cannot open included file $file/, "Template file not found");
}

{
    my ($template, $output);
    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
    $template = HTML::Template->new(filename => 'searchpath/three.tmpl');
    $output = $template->output;
    ok($output =~ /THREE/, "HTML_TEMPLATE_ROOT working without 'path' option being set");
}

=head1 NAME

t/02-parse.t

=head1 OBJECTIVE

Test previously untested code inside C<HTML::Template::_parse()>.  Much
remains to be done.

=cut