1use strict;
2use warnings;
3use Test::More (tests => 9);
4use_ok('HTML::Template');
5
6# testing line 1978
7my $tmpl_text = <<EOT;
8         <TMPL_LOOP ESCAPE=HTML NAME=EMPLOYEE_INFO>
9             Name: <TMPL_VAR NAME=NAME> <br>
10             Job:  <TMPL_VAR NAME=JOB>  <p>
11          </TMPL_LOOP>
12EOT
13
14eval { HTML::Template->new_scalar_ref(\$tmpl_text) };
15
16like($@, qr/ESCAPE option invalid/, "Escape not in TMPL_VAR");
17
18# testing line 1981
19$tmpl_text = <<EOT;
20         <TMPL_LOOP DEFAULT=foo NAME=EMPLOYEE_INFO>
21             Name: <TMPL_VAR NAME=NAME> <br>
22             Job:  <TMPL_VAR NAME=JOB>  <p>
23          </TMPL_LOOP>
24EOT
25
26eval { HTML::Template->new_scalar_ref(\$tmpl_text) };
27
28like($@, qr/DEFAULT option invalid/, "Escape not in TMPL_VAR");
29
30# testing line 1984 else
31# not quite checking 1984, deserves some sober attention
32$tmpl_text = <<EOT;
33     <TMPL_HUH NAME=ZAH>
34         Name: <TMPL_VAR NAME=NAME> <br>
35         Job:  <TMPL_VAR NAME=JOB>  <p>
36      </TMPL_HUH>
37EOT
38ok(HTML::Template->new_scalar_ref(\$tmpl_text, strict => 0), "Ignores invalid TMPL tags with strict off");
39
40# now with strict on
41eval { HTML::Template->new_scalar_ref(\$tmpl_text, strict => 1) };
42like($@, qr/Syntax error/, "Spits at invalid TMPL tag with strict on");
43
44# make sure we can use <tmpl_var foo> and <tmpl_var foo /> syntax
45my $tmpl = HTML::Template->new(scalarref => \'<tmpl_var foo>:<tmpl_var foo />');
46$tmpl->param(foo => 'a');
47my $output = $tmpl->output;
48is($output, 'a:a', 'both var forms worked');
49
50# attempting to check lines 1540-44
51# test using HTML_TEMPLATE_ROOT with path
52{
53    my $file = 'four.tmpl';    # non-existent file
54    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
55    eval { HTML::Template->new(path => ['searchpath'], filename => $file) };
56    like($@, qr/Cannot open included file $file/, "Template file not found");
57}
58
59{
60    my $file = 'four.tmpl';    # non-existent file
61    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
62    eval { HTML::Template->new(filename => $file); };
63    like($@, qr/Cannot open included file $file/, "Template file not found");
64}
65
66{
67    my ($template, $output);
68    local $ENV{HTML_TEMPLATE_ROOT} = "templates";
69    $template = HTML::Template->new(filename => 'searchpath/three.tmpl');
70    $output = $template->output;
71    ok($output =~ /THREE/, "HTML_TEMPLATE_ROOT working without 'path' option being set");
72}
73
74=head1 NAME
75
76t/02-parse.t
77
78=head1 OBJECTIVE
79
80Test previously untested code inside C<HTML::Template::_parse()>.  Much
81remains to be done.
82
83=cut
84
85