summaryrefslogtreecommitdiffstats
path: root/t/expressions.t
blob: f12022c7363d225d92f6fc20f5ee91c7e57f5c73 (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Handlebars;

render_ok(
    '<h1>{{title}}</h1>',
    { title => 'Xslate rocks' },
    '<h1>Xslate rocks</h1>',
    "basic variables"
);

render_ok(
    '<h1>{{article.title}}</h1>',
    { article => { title => 'Hash references rock' } },
    '<h1>Hash references rock</h1>',
    ". separator"
);

render_ok(
    '<h1>{{article/title}}</h1>',
    { article => { title => 'Deprecated syntax does not' } },
    '<h1>Deprecated syntax does not</h1>',
    "/ separator"
);

render_ok(
    '<h1>{{page.article.title}}</h1> - {{date}}',
    {
        page => {
            article => { title => 'Multilevel field access' },
        },
        date => '2012-10-01',
    },
    '<h1>Multilevel field access</h1> - 2012-10-01',
    "multilevel field access with ."
);

render_ok(
    '{{#article}}<h1>{{title}}</h1> - {{../date}}{{/article}}',
    { article => { title => 'Backtracking' }, date => '2012-10-01' },
    '<h1>Backtracking</h1> - 2012-10-01',
    "backtracking with ../"
);

render_ok(
    <<'TEMPLATE',
{{#page}}
{{#article}}<h1>{{title}}</h1> - {{../../date}}{{/article}}
{{/page}}
TEMPLATE
    {
        page => {
            article => { title => 'Multilevel Backtracking' },
        },
        date => '2012-10-01',
    },
    <<'RENDERED',
<h1>Multilevel Backtracking</h1> - 2012-10-01
RENDERED
    "multilevel backtracking with ../"
);

render_ok(
    '{{#article}}<h1>{{title}}</h1> - {{../metadata.date}}{{/article}}',
    {
        article  => { title => 'Backtracking' },
        metadata => { date  => '2012-10-01' },
    },
    '<h1>Backtracking</h1> - 2012-10-01',
    "backtracking into other hash variables with ../ and ."
);

{ local $TODO = "unimplemented";
render_ok(
    '{{articles.[10].comments}}',
    {
        articles => [
            (({}) x 10),
            { comments => "First post!" },
        ],
    },
    'First post!',
    "array dereferencing"
);
}

render_ok(
    '{{.}} {{this}}',
    "foo",
    "foo foo",
    "top level current context"
);

render_ok(
    '{{#thing}}{{.}} {{this}}{{/thing}}',
    {
        thing => [ "foo" ],
    },
    "foo foo",
    "nested current context"
);

done_testing;