File: 007_data_section.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 (63 lines) | stat: -rw-r--r-- 1,242 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
#!perl -w

use strict;
use Test::More;

use Text::Xslate;
use lib "t/lib";
use Util;

use File::Path qw(rmtree);

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

my %vpath = (
    'foo.tx' => 'Hello, <: $lang :> world!',

    'base.tx'  => <<'T',
<html>
<body><: block body -> { :>default body<: } :></body>
</html>
T

    'child.tx' => <<'T',
: cascade base;
: override body -> {
child body
: } # endblock body
T
);

for my $cache(0 .. 2) {
    note "cache => $cache";
    my $tx = Text::Xslate->new(
        path      => [ \%vpath, path ],
        cache_dir => cache_dir,
        cache     => $cache,
    );

    is $tx->render('foo.tx', { lang => 'Xslate' }), 'Hello, Xslate world!', "(1)";
    is $tx->render('foo.tx', { lang => 'Perl' }),   'Hello, Perl world!',   "(2)";

    is $tx->render('child.tx'), <<'X' for 1 .. 2;
<html>
<body>child body
</body>
</html>
X

    is $tx->render('hello.tx', { lang => 'Xslate' }), "Hello, Xslate world!\n", "for real files";


    # reload
    local $vpath{'foo.tx'} = 'Modified';
    $tx = Text::Xslate->new(
        path      => \%vpath,
        cache_dir => cache_dir,
        cache     => $cache,
    );
    is $tx->render('foo.tx', { lang => 'Xslate' }), 'Modified', 'reloaded';
}

done_testing;