File: 003_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 (108 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!perl -w
use strict;
use Test::More;

use Text::Xslate qw(mark_raw);
use utf8;

use lib "t/lib";
use Util;
use File::Path qw(rmtree);

rmtree(cache_dir);
END{ rmtree(cache_dir) }

for my $type (qw(html xml text)) {
# intentionally no indents because it breaks here documents

my $tx = Text::Xslate->new(
    path      => [path],
    cache_dir =>  cache_dir,
    type      => $type,
);

note "for strings (type=$type)";

is $tx->render_string(<<'T', { value => "エクスレート" }),
ようこそ <:= $value :> の世界へ!
T
    "ようこそ エクスレート の世界へ!\n", "utf8";

is $tx->render_string(<<'T', { value => "Xslate" }),
ようこそ <:= $value :> の世界へ!
T
    "ようこそ Xslate の世界へ!\n", "utf8";


is $tx->render_string(<<'T'), <<'X', 'macro';
: macro lang -> { "エクスレート" }
ようこそ <:= lang() :> の世界へ!
T
ようこそ エクスレート の世界へ!
X

is $tx->render_string(<<'T', { value => "エクスレート" }),
Hello, <:= $value :> world!
T
    "Hello, エクスレート world!\n";

is $tx->render_string(q{<: $value :>}, { value => "エクスレート" }),
    "エクスレート";

is $tx->render_string(q{<: $value :> <: $value :>}, { value => "エクスレート" }),
    "エクスレート エクスレート";

is $tx->render_string(<<'T', { value => mark_raw("エクスレート") }),
Hello, <:= $value :> world!
T
    "Hello, エクスレート world!\n";

is $tx->render_string(q{<: $value :>}, { value => mark_raw("エクスレート") }),
    "エクスレート";

is $tx->render_string(q{<: $value :> <: $value :>}, { value => mark_raw("エクスレート") }),
    "エクスレート エクスレート";


note 'for files';

is $tx->render("hello_utf8.tx", { name => "エクスレート" }),
    "こんにちは! エクスレート!\n", "in files" for 1 .. 2;

for(1 .. 2) {
    $tx = Text::Xslate->new(
        path        => [path],
        cache_dir   =>  cache_dir,
        input_layer => ":encoding(utf-8)",
    );

    is $tx->render("hello_utf8.tx", { name => "エクスレート" }),
        "こんにちは! エクスレート!\n", ":encoding(utf-8)";
}

for(1 .. 2) {
    $tx = Text::Xslate->new(
        path        => [path],
        cache_dir   =>  cache_dir,
        input_layer => ":encoding(Shift_JIS)",
    );

    is $tx->render("hello_sjis.tx", { name => "エクスレート" }),
        "こんにちは! エクスレート!\n", ":encoding(Shift_JIS)";
}


for(1 .. 2) {
    no utf8;
    $tx = Text::Xslate->new(
        path        => [path],
        cache_dir   =>  cache_dir,
        input_layer => ":bytes",
        type        => $type,
    );
    #use Devel::Peek; Dump($tx->render("hello_utf8.tx", { name => "エクスレート" }));
    is $tx->render("hello_utf8.tx", { name => "エクスレート" }),
        "こんにちは! エクスレート!\n", ":bytes";
}
} # escape mode
done_testing;