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
|
#!/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 ."
);
done_testing;
|