-
Notifications
You must be signed in to change notification settings - Fork 2
/
meta.t
185 lines (156 loc) · 3.56 KB
/
meta.t
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#============================================================= -*-perl-*-
#
# t/controls/meta.t
#
# Test script for META control directive.
#
# Run with -h option for help.
#
# Written by Andy Wardley <abw@wardley.org>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================
use Badger
lib => '../../lib';
use Template::TT3::Test
tests => 4,
debug => 'Template::TT3::Tag',
args => \@ARGV,
import => 'test_expect callsign :all';
use Template3;
my $template = Template3->template( text => <<'EOF' );
[? META title = 'Hello World' author = 'Andy Wardley' -?]
The title of this template is [% template.title %]
EOF
ok( $template, "compiled template: $template" );
my $output = Template3->process( $template );
is( $output,
"The title of this template is Hello World\n",
'got template title in output'
);
my $template2 = Template3->template( text => <<'EOF' );
[? META { title = 'Hello World' author = 'Andy Wardley' } -?]
The author of this template is [% template.author %]
EOF
ok( $template2, "compiled template: $template2" );
$output = Template3->process( $template2 );
is( $output,
"The author of this template is Andy Wardley\n",
'got template author in output'
);
exit;
test_expect(
debug => $DEBUG,
variables => callsign,
);
__DATA__
-- test one --
Hello [% a %]
-- expect --
Hello alpha
-- test tags invalid --
[? TAGS invalid -?]
Hello World
-- expect --
<ERROR:Undefined value returned by expression: invalid>
#<ERROR:Undefined value returned by TAGS expression: invalid>
-- test tags single string --
BEFORE
[? TAGS '<* *>' -?]
Hello <* a *>
-- expect --
BEFORE
Hello alpha
-- test tags list ref --
[? TAGS ['<*' '*>'] -?]
Hello <* b *>
-- expect --
Hello bravo
-- test tags equals string --
[? TAGS = '<* *>' -?]
Hello <* c *>
-- expect --
Hello charlie
-- test tags equals list ref --
[? TAGS = ['<*' '*>'] -?]
Hello <* d *>
-- expect --
Hello delta
-- test tags are --
[? TAGS are ['<*' '*>'] -?]
Hello <* e *>
-- expect --
Hello echo
-- test tags off --
[? TAGS off -?]
Hello [% f %]
-- expect --
Hello [% f %]
-- test tags off/on --
[? TAGS off -?]
Hello [% f %]
[? TAGS on -?]
Hello [% f %]
-- expect --
Hello [% f %]
Hello foxtrot
-- test tags get restored to previous state --
[? TAGS '<* *>' -?]
<* h.ucfirst *> California
[? TAGS off -?]
<* h.ucfirst *> California
[? TAGS on -?]
<* h.ucfirst *> California
-- expect --
Hotel California
<* h.ucfirst *> California
Hotel California
-- test multiple tags --
[? TAGS {
inline = '<* *>'
comment = '<# #>'
}
-?]
Hello [% i %]
Hello <* i *>
Hello [# i #]
Hello <# i #>!
-- expect --
Hello [% i %]
Hello india
Hello [# i #]
Hello !
-- test dotted inline tags --
[? TAGS.inline '<* *>' -?]
Romeo and [% j.ucfirst %]
Romeo and <* j.ucfirst *>
-- expect --
Romeo and [% j.ucfirst %]
Romeo and Juliet
-- test dotted comment tags --
[? TAGS.comment '<* *>' -?]
Romeo and [% j.ucfirst %] are lovers
Romeo and <* j.ucfirst *> are lovers
-- expect --
Romeo and Juliet are lovers
Romeo and are lovers
-- test tags reset tags --
Romeo and [% j.ucfirst %] are lovers
Romeo and <* j.ucfirst *> are lovers
-- expect --
Romeo and Juliet are lovers
Romeo and <* j.ucfirst *> are lovers
-- test TAGS.all --
[? TAGS.all off -?]
[% k %] [? k ?] [# k #]
%% k
-- expect --
[% k %] [? k ?] [# k #]
%% k
-- test dotted tags with invalid name --
[? TAGS.cheese '<* *>' -?]
Romeo and [% j.ucfirst %] are lovers
-- expect --
<ERROR:Invalid tags specified: cheese>