File: 031_post_if.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 (66 lines) | stat: -rw-r--r-- 869 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
#!perl -w
use strict;
use Test::More;

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

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

my @data = (
    [<<'T', <<'X'],
    [<: "foo" if true :>]
T
    [foo]
X

    [<<'T', <<'X'],
    [<: "foo" if false :>]
T
    []
X

    [<<'T', <<'X'],
    [<: "foo" if $a[0] == 0 :>]
T
    [foo]
X

    [<<'T', <<'X'],
    [<: "foo" if $a[0] == 1 :>]
T
    []
X

    [<<'T', <<'X', 'include-if'],
    : include "hello.tx" if true
    : include "hello.tx" if true
T
Hello, Xslate world!
Hello, Xslate world!
X

    [<<'T', <<'X'],
    : include "hello.tx" if false
    : include "hello.tx" if false
T
X

);

my %vars = (
    lang => 'Xslate',
    a    => [ 0 .. 99 ],
);
foreach my $d(@data) {
    my($in, $out, $msg) = @$d;

    is $tx->render_string($in, \%vars), $out, $msg
        or diag $in;
}

done_testing;