more fixage because the perl parser hates me
[scpubgit/HTML-String.git] / xt / tt.t
CommitLineData
f49292d9 1use strictures 1;
2use Test::More;
3use HTML::String::TT;
4
5my $tt = HTML::String::TT->new;
6
7sub do_tt {
8 my $output;
9 $tt->process(\$_[0], $_[1], \$output) or die $tt->error;
10 return "$output";
11}
12
13is(
14 do_tt('<tag>[% foo %]</tag>', { foo => 'Hi <bob>' }),
15 '<tag>Hi &lt;bob&gt;</tag>',
16);
17
18is(
19 do_tt(q{[%
20 VIEW myview; BLOCK render; '<tag>'; foo; '</tag>'; END; END;
21 myview.include('render');
22 %]}, { foo => 'Hi <bob>' }),
23 '<tag>Hi &lt;bob&gt;</tag>',
24);
25
51eaef0b 26is(
27 do_tt('<tag>[% foo | no_escape %]</tag>', { foo => 'Hi <bob>' }),
28 '<tag>Hi <bob></tag>',
29);
30
5c65e9e1 31# Check we aren't nailed by https://rt.perl.org/rt3/Ticket/Display.html?id=49594
32
5bee64f9 33is(
34 do_tt('<foo>"$bar"</foo>'."\n"),
35 '<foo>"$bar"</foo>'."\n"
36);
37
ac4c210b 38is(
39 do_tt(
40 '[% FOREACH item IN items %][% item %][% END %]',
41 { items => [ '<script>alert("lalala")</script>', '-> & so "on" <-' ] }
42 ),
43 '&lt;script&gt;alert(&quot;lalala&quot;)&lt;/script&gt;'
44 .'-&gt; &amp; so &quot;on&quot; &lt;-'
45);
46
10c4bc68 47is( do_tt('"0"', {}), '"0"' );
48
c3ffad02 49{
1ddb0236 50 use utf8;
51
52 is(
53 do_tt('<li>foo – bar.</li>', {}),
54 '<li>foo – bar.</li>',
55 );
56}
57
58{
c3ffad02 59 my $tmpl = q[
60 [%- MACRO test(name, value) BLOCK;
61 IF !value.length;
62 "ok";
63 END;
64 END; -%]
65[%- test("foo", "") -%]
66];
67
68 my $with_html_string_tt = do_tt($tmpl, {});
69
70 $tt = Template->new(STASH => Template::Stash->new);
71 my $with_template = do_tt($tmpl, {});
72
73 is $with_html_string_tt, $with_template;
74}
75
f49292d9 76done_testing;