1 // Make sure the trim isn't applied to standard output
2 #[test]
test_standard_output()3 fn test_standard_output() {
4 let text = r#"
5 <div>
6 <p>
7 {{ 'John' }}
8 </p>
9 </div>
10 "#;
11 let expected = r#"
12 <div>
13 <p>
14 John
15 </p>
16 </div>
17 "#;
18 assert_template_result!(expected, text);
19 }
20
21 #[test]
test_variable_output_with_multiple_blank_lines()22 fn test_variable_output_with_multiple_blank_lines() {
23 let text = r#"
24 <div>
25 <p>
26
27
28 {{- 'John' -}}
29
30
31 </p>
32 </div>
33 "#;
34 let expected = r#"
35 <div>
36 <p>John</p>
37 </div>
38 "#;
39 assert_template_result!(expected, text);
40 }
41
42 #[test]
test_tag_output_with_multiple_blank_lines()43 fn test_tag_output_with_multiple_blank_lines() {
44 let text = r#"
45 <div>
46 <p>
47
48
49 {%- if true -%}
50 yes
51 {%- endif -%}
52
53
54 </p>
55 </div>
56 "#;
57 let expected = r#"
58 <div>
59 <p>yes</p>
60 </div>
61 "#;
62 assert_template_result!(expected, text);
63 }
64
65 // Make sure the trim isn't applied to standard tags
66 #[test]
test_standard_tags()67 fn test_standard_tags() {
68 let text = r#"
69 <div>
70 <p>
71 {% if true %}
72 yes
73 {% endif %}
74 </p>
75 </div>
76 "#;
77 let expected = r#"
78 ......<div>
79 ........<p>
80 ..........
81 ..........yes
82 ..........
83 ........</p>
84 ......</div>
85 ...."#
86 .replace(".", " ");
87 assert_template_result!(expected, text);
88
89 let text = r#"
90 <div>
91 <p>
92 {% if false %}
93 no
94 {% endif %}
95 </p>
96 </div>
97 "#;
98 let expected = r#"
99 ......<div>
100 ........<p>
101 ..........
102 ........</p>
103 ......</div>
104 ...."#
105 .replace(".", " ");
106 assert_template_result!(expected, text);
107 }
108
109 // Make sure the trim isn't too aggressive
110 #[test]
test_no_trim_output()111 fn test_no_trim_output() {
112 let text = r#"<p>{{- 'John' -}}</p>"#;
113 let expected = "<p>John</p>";
114 assert_template_result!(expected, text);
115 }
116
117 // Make sure the trim isn't too aggressive
118 #[test]
test_no_trim_tags()119 fn test_no_trim_tags() {
120 let text = r#"<p>{%- if true -%}yes{%- endif -%}</p>"#;
121 let expected = r#"<p>yes</p>"#;
122 assert_template_result!(expected, text);
123
124 let text = r#"<p>{%- if false -%}no{%- endif -%}</p>"#;
125 let expected = r#"<p></p>"#;
126 assert_template_result!(expected, text);
127 }
128
129 #[test]
test_single_line_outer_tag()130 fn test_single_line_outer_tag() {
131 let text = r#"<p> {%- if true %} yes {% endif -%} </p>"#;
132 let expected = r#"<p> yes </p>"#;
133 assert_template_result!(expected, text);
134
135 let text = r#"<p> {%- if false %} no {% endif -%} </p>"#;
136 let expected = r#"<p></p>"#;
137 assert_template_result!(expected, text);
138 }
139
140 #[test]
test_single_line_inner_tag()141 fn test_single_line_inner_tag() {
142 let text = r#"<p> {% if true -%} yes {%- endif %} </p>"#;
143 let expected = r#"<p> yes </p>"#;
144 assert_template_result!(expected, text);
145
146 let text = r#"<p> {% if false -%} no {%- endif %} </p>"#;
147 let expected = r#"<p> </p>"#;
148 assert_template_result!(expected, text);
149 }
150
151 #[test]
test_single_line_post_tag()152 fn test_single_line_post_tag() {
153 let text = r#"<p> {% if true -%} yes {% endif -%} </p>"#;
154 let expected = r#"<p> yes </p>"#;
155 assert_template_result!(expected, text);
156
157 let text = r#"<p> {% if false -%} no {% endif -%} </p>"#;
158 let expected = r#"<p> </p>"#;
159 assert_template_result!(expected, text);
160 }
161
162 #[test]
test_single_line_pre_tag()163 fn test_single_line_pre_tag() {
164 let text = r#"<p> {%- if true %} yes {%- endif %} </p>"#;
165 let expected = r#"<p> yes </p>"#;
166 assert_template_result!(expected, text);
167
168 let text = r#"<p> {%- if false %} no {%- endif %} </p>"#;
169 let expected = r#"<p> </p>"#;
170 assert_template_result!(expected, text);
171 }
172
173 #[test]
test_pre_trim_output()174 fn test_pre_trim_output() {
175 let text = r#"
176 <div>
177 <p>
178 {{- 'John' }}
179 </p>
180 </div>
181 "#;
182 let expected = r#"
183 <div>
184 <p>John
185 </p>
186 </div>
187 "#;
188 assert_template_result!(expected, text);
189 }
190
191 #[test]
test_pre_trim_tags()192 fn test_pre_trim_tags() {
193 let text = r#"
194 <div>
195 <p>
196 {%- if true %}
197 yes
198 {%- endif %}
199 </p>
200 </div>
201 "#;
202 let expected = r#"
203 <div>
204 <p>
205 yes
206 </p>
207 </div>
208 "#;
209 assert_template_result!(expected, text);
210
211 let text = r#"
212 <div>
213 <p>
214 {%- if false %}
215 no
216 {%- endif %}
217 </p>
218 </div>
219 "#;
220 let expected = r#"
221 <div>
222 <p>
223 </p>
224 </div>
225 "#;
226 assert_template_result!(expected, text);
227 }
228
229 #[test]
test_post_trim_output()230 fn test_post_trim_output() {
231 let text = r#"
232 <div>
233 <p>
234 {{ 'John' -}}
235 </p>
236 </div>
237 "#;
238 let expected = r#"
239 <div>
240 <p>
241 John</p>
242 </div>
243 "#;
244 assert_template_result!(expected, text);
245 }
246
247 #[test]
test_post_trim_tags()248 fn test_post_trim_tags() {
249 let text = r#"
250 <div>
251 <p>
252 {% if true -%}
253 yes
254 {% endif -%}
255 </p>
256 </div>
257 "#;
258 let expected = r#"
259 <div>
260 <p>
261 yes
262 </p>
263 </div>
264 "#;
265 assert_template_result!(expected, text);
266
267 let text = r#"
268 <div>
269 <p>
270 {% if false -%}
271 no
272 {% endif -%}
273 </p>
274 </div>
275 "#;
276 let expected = r#"
277 <div>
278 <p>
279 </p>
280 </div>
281 "#;
282 assert_template_result!(expected, text);
283 }
284
285 #[test]
test_pre_and_post_trim_tags()286 fn test_pre_and_post_trim_tags() {
287 let text = r#"
288 <div>
289 <p>
290 {%- if true %}
291 yes
292 {% endif -%}
293 </p>
294 </div>
295 "#;
296 let expected = r#"
297 <div>
298 <p>
299 yes
300 </p>
301 </div>
302 "#;
303 assert_template_result!(expected, text);
304
305 let text = r#"
306 <div>
307 <p>
308 {%- if false %}
309 no
310 {% endif -%}
311 </p>
312 </div>
313 "#;
314 let expected = r#"
315 <div>
316 <p></p>
317 </div>
318 "#;
319 assert_template_result!(expected, text);
320 }
321
322 #[test]
test_post_and_pre_trim_tags()323 fn test_post_and_pre_trim_tags() {
324 let text = r#"
325 <div>
326 <p>
327 {% if true -%}
328 yes
329 {%- endif %}
330 </p>
331 </div>
332 "#;
333 let expected = r#"
334 <div>
335 <p>
336 yes
337 </p>
338 </div>
339 "#;
340 assert_template_result!(expected, text);
341
342 let text = r#"
343 <div>
344 <p>
345 {% if false -%}
346 no
347 {%- endif %}
348 </p>
349 </div>
350 "#;
351 let expected = r#"
352 ......<div>
353 ........<p>
354 ..........
355 ........</p>
356 ......</div>
357 ...."#
358 .replace(".", " ");
359 assert_template_result!(expected, text);
360 }
361
362 #[test]
test_trim_output()363 fn test_trim_output() {
364 let text = r#"
365 <div>
366 <p>
367 {{- 'John' -}}
368 </p>
369 </div>
370 "#;
371 let expected = r#"
372 <div>
373 <p>John</p>
374 </div>
375 "#;
376 assert_template_result!(expected, text);
377 }
378
379 #[test]
test_trim_tags()380 fn test_trim_tags() {
381 let text = r#"
382 <div>
383 <p>
384 {%- if true -%}
385 yes
386 {%- endif -%}
387 </p>
388 </div>
389 "#;
390 let expected = r#"
391 <div>
392 <p>yes</p>
393 </div>
394 "#;
395 assert_template_result!(expected, text);
396
397 let text = r#"
398 <div>
399 <p>
400 {%- if false -%}
401 no
402 {%- endif -%}
403 </p>
404 </div>
405 "#;
406 let expected = r#"
407 <div>
408 <p></p>
409 </div>
410 "#;
411 assert_template_result!(expected, text);
412 }
413
414 #[test]
test_whitespace_trim_output()415 fn test_whitespace_trim_output() {
416 let text = r#"
417 <div>
418 <p>
419 {{- 'John' -}},
420 {{- '30' -}}
421 </p>
422 </div>
423 "#;
424 let expected = r#"
425 <div>
426 <p>John,30</p>
427 </div>
428 "#;
429 assert_template_result!(expected, text);
430 }
431
432 #[test]
test_whitespace_trim_tags()433 fn test_whitespace_trim_tags() {
434 let text = r#"
435 <div>
436 <p>
437 {%- if true -%}
438 yes
439 {%- endif -%}
440 </p>
441 </div>
442 "#;
443 let expected = r#"
444 <div>
445 <p>yes</p>
446 </div>
447 "#;
448 assert_template_result!(expected, text);
449
450 let text = r#"
451 <div>
452 <p>
453 {%- if false -%}
454 no
455 {%- endif -%}
456 </p>
457 </div>
458 "#;
459 let expected = r#"
460 <div>
461 <p></p>
462 </div>
463 "#;
464 assert_template_result!(expected, text);
465 }
466
467 #[test]
test_complex_trim_output()468 fn test_complex_trim_output() {
469 let text = r#"
470 <div>
471 <p>
472 {{- 'John' -}}
473 {{- '30' -}}
474 </p>
475 <b>
476 {{ 'John' -}}
477 {{- '30' }}
478 </b>
479 <i>
480 {{- 'John' }}
481 {{ '30' -}}
482 </i>
483 </div>
484 "#;
485 let expected = r#"
486 <div>
487 <p>John30</p>
488 <b>
489 John30
490 </b>
491 <i>John
492 30</i>
493 </div>
494 "#;
495 assert_template_result!(expected, text);
496 }
497
498 #[test]
test_complex_trim()499 fn test_complex_trim() {
500 let text = r#"
501 <div>
502 {%- if true -%}
503 {%- if true -%}
504 <p>
505 {{- 'John' -}}
506 </p>
507 {%- endif -%}
508 {%- endif -%}
509 </div>
510 "#;
511 let expected = r#"
512 <div><p>John</p></div>
513 "#;
514 assert_template_result!(expected, text);
515 }
516
517 #[test]
test_right_trim_followed_by_tag()518 fn test_right_trim_followed_by_tag() {
519 assert_template_result!(r#"ab c"#, r#"{{ "a" -}}{{ "b" }} c"#);
520 }
521
522 #[test]
test_raw_output()523 fn test_raw_output() {
524 let text = r#"
525 <div>
526 {% raw %}
527 {%- if true -%}
528 <p>
529 {{- 'John' -}}
530 </p>
531 {%- endif -%}
532 {% endraw %}
533 </div>
534 "#;
535 let expected = r#"
536 ......<div>
537 ........
538 ..........{%-.if.true.-%}
539 ............<p>
540 ..............{{-.'John'.-}}
541 ............</p>
542 ..........{%-.endif.-%}
543 ........
544 ......</div>
545 ...."#
546 .replace(".", " ");
547 assert_template_result!(expected, text);
548 }
549