-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Compiler.errors.phpt
358 lines (292 loc) · 9.77 KB
/
Compiler.errors.phpt
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* Test: Compile errors.
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
Assert::exception(
fn() => $latte->compile('{'),
Latte\CompileException::class,
'Unexpected end, expecting end of Latte tag started on line 1 at column 1 (on line 1 at column 2)',
);
Assert::exception(
fn() => $latte->compile('{foo'),
Latte\CompileException::class,
'Unexpected end, expecting end of Latte tag started on line 1 at column 1 (on line 1 at column 5)',
);
Assert::exception(
fn() => $latte->compile("{* \n'abc}"),
Latte\CompileException::class,
'Unexpected end, expecting end of Latte comment started on line 1 at column 1 (on line 2 at column 6)',
);
Assert::exception(
fn() => $latte->compile('{syntax double} {{a'),
Latte\CompileException::class,
'Unexpected end, expecting end of Latte tag started on line 1 at column 17 (on line 1 at column 20)',
);
Assert::exception(
fn() => $latte->compile('{syntax double} {{a } b'),
Latte\CompileException::class,
"Unexpected '} b' (on line 1 at column 21)",
);
Assert::exception(
fn() => $latte->compile('<! foo'),
Latte\CompileException::class,
'Unexpected end, expecting end of HTML tag (on line 1 at column 7)',
);
Assert::exception(
fn() => $latte->compile("<a href='xx{* xx *}>"),
Latte\CompileException::class,
"Unexpected end, expecting ', end of HTML attribute started on line 1 at column 9 (on line 1 at column 21)",
);
Assert::exception(
fn() => $latte->compile("<a n:href='xx>"),
Latte\CompileException::class,
"Unexpected end, expecting ', end of n:attribute started on line 1 at column 11 (on line 1 at column 15)",
);
Assert::exception(
fn() => $latte->compile('<!-- xxx'),
Latte\CompileException::class,
'Unexpected end, expecting end of HTML comment started on line 1 at column 1 (on line 1 at column 9)',
);
Assert::exception(
fn() => $latte->compile('Block{/block}'),
Latte\CompileException::class,
"Unexpected '{' (on line 1 at column 6)",
);
Assert::exception(
fn() => $latte->compile("{var \n'abc}"),
Latte\CompileException::class,
'Unterminated string (on line 2 at column 1)',
);
Assert::exception(
fn() => $latte->compile('{contentType xml}<a n:if=1></A>'),
Latte\CompileException::class,
"Unexpected '</A>', expecting </a> for element started on line 1 at column 18 (on line 1 at column 28)",
);
Assert::exception(
fn() => $latte->compile('<a {if}n:href>'),
Latte\CompileException::class,
'Attribute n:href must not appear inside {tags} (on line 1 at column 8)',
);
Assert::exception(
fn() => $latte->compile('<a></a foo>'),
Latte\CompileException::class,
"Unexpected 'foo', expecting end of HTML tag (on line 1 at column 8)",
);
Assert::exception(
fn() => $latte->compile('<{if 1}{/if}>'),
Latte\CompileException::class,
'Only expression can be used as a HTML tag name (on line 1 at column 2)',
);
Assert::exception(
fn() => $latte->compile('<{$foo}>'),
Latte\CompileException::class,
'Unexpected end, expecting </{$foo}> for element started on line 1 at column 1 (on line 1 at column 9)',
);
Assert::exception(
fn() => $latte->compile('<{$foo}></{$bar}>'),
Latte\CompileException::class,
"Unexpected '</{\$bar}>', expecting </{\$foo}> for element started on line 1 at column 1 (on line 1 at column 9)",
);
Assert::exception(
fn() => $latte->compile('<{$foo}>...</{if 1}{/if}>'),
Latte\CompileException::class,
'Only expression can be used as a HTML tag name (on line 1 at column 14)',
);
Assert::exception(
fn() => $latte->compile('<a>...</{$foo}>'),
Latte\CompileException::class,
"Unexpected '</{\$foo}>', expecting </a> for element started on line 1 at column 1 (on line 1 at column 7)",
);
Assert::exception(
fn() => $latte->compile('<{$foo}><span></{$foo}>'),
Latte\CompileException::class,
"Unexpected '</{\$foo}>', expecting </span> for element started on line 1 at column 9 (on line 1 at column 15)",
);
Assert::exception(
fn() => $latte->compile('<{$foo}></span></{$foo}>'),
Latte\CompileException::class,
"Unexpected '</span>', expecting </{\$foo}> for element started on line 1 at column 1 (on line 1 at column 9)",
);
Assert::exception(
fn() => $latte->compile('</{$foo}>'), // bogus tag
Latte\CompileException::class,
"Unexpected '{', expecting HTML name (on line 1 at column 3)",
);
Assert::exception(
fn() => $latte->compile('<span title={if true}a b{/if}></span>'),
Latte\CompileException::class,
"Unexpected ' ', expecting {/if} (on line 1 at column 23)",
);
Assert::exception(
fn() => $latte->compile('<span title={if true}"a"{/if}></span>'),
Latte\CompileException::class,
'Unexpected \'"\', expecting {/if} (on line 1 at column 22)',
);
Assert::exception(
fn() => $latte->compile('<span {if true}title{/if}=a></span>'),
Latte\CompileException::class,
"Unexpected '=', expecting end of HTML tag (on line 1 at column 26)",
);
Assert::exception(
fn() => $latte->compile('<span title{if true}{/if}=a></span>'),
Latte\CompileException::class,
"Unexpected '=', expecting end of HTML tag (on line 1 at column 26)",
);
Assert::exception(
fn() => $latte->compile('<a n:href n:href>'),
Latte\CompileException::class,
'Found multiple attributes n:href (on line 1 at column 11)',
);
Assert::match(
'<div c=comment -->',
$latte->renderToString('<div c=comment {="--"}>'),
);
Assert::exception(
fn() => $latte->compile('<a n:class class>'),
Latte\CompileException::class,
'It is not possible to combine class with n:class (on line 1 at column 4)',
);
Assert::exception(
fn() => $latte->compile('<p title=""</p>'),
'Latte\CompileException',
"Unexpected '</p>' (on line 1 at column 12)",
);
Assert::exception(
fn() => $latte->compile('<p title=>'),
'Latte\CompileException',
"Unexpected '>' (on line 1 at column 10)",
);
Assert::exception(
fn() => $latte->compile('<a {$foo}<'),
Latte\CompileException::class,
"Unexpected '<' (on line 1 at column 10)",
);
Assert::exception(
fn() => $latte->compile('{time() /}'),
Latte\CompileException::class,
'Unexpected /} in tag {=time() /} (on line 1 at column 1)',
);
// <script> & <style> must be closed
Assert::exception(
fn() => $latte->compile('<STYLE>'),
Latte\CompileException::class,
'Unexpected end, expecting </STYLE> for element started on line 1 at column 1 (on line 1 at column 8)',
);
Assert::exception(
fn() => $latte->compile('<script>'),
Latte\CompileException::class,
'Unexpected end, expecting </script> for element started on line 1 at column 1 (on line 1 at column 9)',
);
Assert::noError(
fn() => $latte->compile('{contentType xml}<script>'),
);
// brackets balancing
Assert::exception(
fn() => $latte->compile('{=)}'),
Latte\CompileException::class,
"Unexpected ')' (on line 1 at column 3)",
);
Assert::exception(
fn() => $latte->compile('{=[(])}'),
Latte\CompileException::class,
"Unexpected ']' (on line 1 at column 5)",
);
// forbidden keywords
Assert::exception(
fn() => $latte->compile('{= function test() }'),
Latte\CompileException::class,
"Unexpected 'test' (on line 1 at column 13)",
);
Assert::exception(
fn() => $latte->compile('{= class test }'),
Latte\CompileException::class,
"Unexpected 'test' (on line 1 at column 10)",
);
Assert::exception(
fn() => $latte->compile('{= return}'),
Latte\CompileException::class,
"Unexpected 'return' (on line 1 at column 4)",
);
Assert::noError( // prints 'yield'
fn() => $latte->compile('{= yield}'),
);
Assert::exception(
fn() => $latte->compile('{= yield $x}'),
Latte\CompileException::class,
"Unexpected '\$x' (on line 1 at column 10)",
);
Assert::exception(
fn() => $latte->compile('{=`whoami`}'),
Latte\CompileException::class,
"Unexpected '`' (on line 1 at column 3)",
);
Assert::exception(
fn() => $latte->compile('{$ʟ_tmp}'),
Latte\CompileException::class,
'Forbidden variable $ʟ_tmp (on line 1 at column 2)',
);
Assert::exception(
fn() => $latte->compile('{$GLOBALS}'),
Latte\CompileException::class,
'Forbidden variable $GLOBALS (on line 1 at column 2)',
);
// unclosed macros
Assert::exception(
fn() => $latte->compile('{if 1}'),
Latte\CompileException::class,
'Unexpected end, expecting {/if} (on line 1 at column 7)',
);
Assert::exception(
fn() => $latte->compile('<p n:if=1><span n:if=1>'),
Latte\CompileException::class,
'Unexpected end, expecting </span> for element started on line 1 at column 11 (on line 1 at column 24)',
);
Assert::exception(
fn() => $latte->compile('<p n:if=1><span n:if=1></i>'),
Latte\CompileException::class,
"Unexpected '</i>', expecting </span> for element started on line 1 at column 11 (on line 1 at column 24)",
);
Assert::exception(
fn() => $latte->compile('{/if}'),
Latte\CompileException::class,
"Unexpected '{' (on line 1 at column 1)",
);
Assert::exception(
fn() => $latte->compile('{if 1}{/foreach}'),
Latte\CompileException::class,
'Unexpected {/foreach}, expecting {/if} (on line 1 at column 7)',
);
Assert::exception(
fn() => $latte->compile('{if 1}{/if 2}'),
Latte\CompileException::class,
"Unexpected '2', expecting end of tag in {/if} (on line 1 at column 12)",
);
Assert::exception(
fn() => $latte->compile('<span n:if=1>{foreach $a as $b}</span>'),
Latte\CompileException::class,
'Unexpected end, expecting {/foreach} (on line 1 at column 39)',
);
Assert::exception(
fn() => $latte->compile('<span n:if=1>{/if}'),
Latte\CompileException::class,
"Unexpected '{/if', expecting </span> for element started on line 1 at column 1 (on line 1 at column 14)",
);
Assert::exception(
fn() => $latte->compile(<<<'XX'
{foreach [] as $item}
<li><a n:tag-if="$iterator->odd"></li>
{/foreach}
XX),
Latte\CompileException::class,
"Unexpected '</li>', expecting </a> for element started on line 2 at column 8 (on line 2 at column 37)",
);
Assert::exception(
fn() => $latte->compile('{block |trim?|trim}...{/block}'),
Latte\CompileException::class,
'Nullsafe pipe is not allowed here (on line 1 at column 13)',
);