1use warnings;
2use strict;
3use lib 't';
4use Test::More tests => 2;
5use_ok('HTML::Template::Compiled');
6use HTC_Utils qw($cache $tdir &cdir);
7
8eval { require URI::Escape };
9my $uri = $@ ? 0 : 1;
10eval { require Encode };
11my $encode = $@ ? 0 : 1;
12eval { require HTML::Entities };
13my $ent = $@ ? 0 : 1;
14my $template = File::Spec->catfile(qw/ t templates utf8.htc /);
15#use Devel::Peek;
16SKIP: {
17	skip "no URI::Escape, Encode, HTML::Entities installed", 1 unless $uri && $encode && $ent;
18    open my $fh, '>:utf8', $template;
19    my $string = <<"EOM";
20test utf8: \x{f6}
21<%= utf8 escape=url %>
22<%= utf8 escape=html_all %>
23EOM
24    print $fh $string;
25    #Dump $string;
26    close $fh;
27    my $htc = HTML::Template::Compiled->new(
28        filename => 'utf8.htc',
29        path => $tdir,
30        debug    => 0,
31        open_mode => '<:utf8',
32    );
33    my $u = "ä";
34    $u = Encode::decode_utf8($u);
35
36    $htc->param(
37        utf8 => $u,
38    );
39    my $out = $htc->output;
40    my $test = "\x{f6}";
41    #Dump $test;
42    $test = Encode::encode('utf-8', $test);
43    #Dump $test;
44    Encode::_utf8_on($test);
45    #print "out: $out\n";
46    #Dump $out;
47    cmp_ok($out, '=~', qr{$test.*%C3%A4.*&auml;}is, "uri_escape_utf8");
48    unlink $template;
49}
50
51
52