File: 004_encoding.t

package info (click to toggle)
libtext-xslate-perl 3.5.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,108 kB
  • sloc: perl: 19,756; ansic: 214; pascal: 182; makefile: 9; cs: 8
file content (46 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (5)
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
#!perl
use strict;
use warnings;
use utf8;

use Test::More;
use SelectSaver;
use Text::Xslate::Runner;

use Encode qw(encode decode);

sub capture(&) {
    my($block) = @_;

    my $s = '';

    {
        open my $out, '>', \$s;
        my $saver = SelectSaver->new($out);
        $block->();
    }
    return $s;
}

my $app = Text::Xslate::Runner->new(
    define => { name => '<Xslate>' },
    cache_dir => '.xslate_cache/app3',
);
is capture { $app->run('t/template/hello_utf8.tx') },
    encode("UTF-8", "こんにちは! &lt;Xslate&gt;!\n");

$app->output_encoding('Shift_JIS');
is capture { $app->run('t/template/hello_utf8.tx') },
    encode("Shift_JIS", "こんにちは! &lt;Xslate&gt;!\n");

$app->input_encoding('Shift_JIS');
$app->output_encoding('utf-8');
is capture { $app->run('t/template/hello_sjis.tx') },
    encode("UTF-8", "こんにちは! &lt;Xslate&gt;!\n");

$app->input_encoding('Shift_JIS');
$app->output_encoding('Shift_JIS');
is capture { $app->run('t/template/hello_sjis.tx') },
    encode("Shift_JIS", "こんにちは! &lt;Xslate&gt;!\n");

done_testing;