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