File: 12-utf8.t

package info (click to toggle)
libhtml-template-perl 2.97-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 740 kB
  • sloc: perl: 2,572; makefile: 8
file content (64 lines) | stat: -rw-r--r-- 1,819 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
use strict;
use warnings;
use File::Temp qw(tempdir);
use Test::More ($] < 5.007001 ? (skip_all => 'utf8 needs at least perl 5.7.1') : (tests => 5));

use_ok('HTML::Template');

# make sure we can't use along with open_mode
eval { HTML::Template->new(path => 'templates', filename => 'utf8-test.tmpl', utf8 => 1, open_mode => 1)};
like($@, qr/utf8 and open_mode cannot be used/i, 'cant use uft8 and open_mode at the same time');

my $tmpl = HTML::Template->new(
    path     => 'templates',
    filename => 'utf8-test.tmpl',
    utf8     => 1,
);
my $output = $tmpl->output;
chomp $output;

is($output, chr(228), 'correct UTF8 encoded character');

my $cache_dir = tempdir(CLEANUP => 1);

# same as before, this time we test  file_cache
$tmpl = HTML::Template->new(
    path           => 'templates',
    filename       => 'utf8-test.tmpl',
    utf8           => 1,
    cache          => 0,
    file_cache     => 1,
    file_cache_dir => $cache_dir,
);

# trigger cache storage:
$output = $tmpl->output;

# this time it will implicitly read from the cache
$tmpl = HTML::Template->new(
    path           => 'templates',
    filename       => 'utf8-test.tmpl',
    utf8           => 1,
    cache          => 0,
    file_cache     => 1,
    file_cache_dir => $cache_dir,
);

$output = $tmpl->output;
chomp $output;

is($output, chr(228), 'correct UTF8 encoded character from cache');

# this time it will implicitly read from the cache w/out open_mode
# which means it won't be correct UTF8.
$tmpl = HTML::Template->new(
    path           => 'templates',
    filename       => 'utf8-test.tmpl',
    cache          => 0,
    file_cache     => 1,
    file_cache_dir => $cache_dir,
);

$output = $tmpl->output;
chomp $output;
is(sprintf('%vd', $output), "195.164", 'correct non-UTF8 bytes: different open_mode, no cache');