xref: /freebsd/crypto/openssl/external/perl/Text-Template-1.56/t/template-encoding.t (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1#!perl
2
3use utf8;
4use strict;
5use warnings;
6use Test::More;
7use Encode;
8use File::Temp;
9
10# Non-CORE module(s)
11unless (eval { require Test::More::UTF8; 1; } ) {
12    plan skip_all => '[ Test::More::UTF8 ] is required for testing';
13}
14
15plan tests => 3;
16
17use_ok 'Text::Template' or exit 1;
18
19my $tmp_fh = File::Temp->new;
20
21print $tmp_fh encode('UTF-8', "\x{4f60}\x{597d} {{\$name}}");
22
23$tmp_fh->flush;
24
25# UTF-8 encoded template file
26my $str = Text::Template->new(
27    TYPE     => 'FILE',
28    SOURCE   => $tmp_fh->filename,
29    ENCODING => 'UTF-8'
30)->fill_in(HASH => { name => 'World' });
31
32is $str, "\x{4f60}\x{597d} World";
33
34$tmp_fh = File::Temp->new;
35
36print $tmp_fh encode('iso-8859-1', "Ol\x{e1} {{\$name}}");
37
38$tmp_fh->flush;
39
40# ISO-8859-1 encoded template file
41$str = Text::Template->new(
42    TYPE     => 'FILE',
43    SOURCE   => $tmp_fh->filename,
44    ENCODING => 'iso-8859-1'
45)->fill_in(HASH => { name => 'World' });
46
47is $str, "Ol\x{e1} World";
48