2
0

template-encoding.t 944 B

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