1 module tests.statements.other_;
2 
3 private
4 {
5     import tests.asserts;
6 }
7 
8 
9 // Whitespace control
10 unittest
11 {
12     assertRender(`{% if true %}`~" \n\t test \n\t "~`{% endif %}`, " \n\t test \n\t ");
13 
14     assertRender(`
15         {%- for item in [1,2,3,4,5] -%}
16             {{ item }}
17         {%- endfor -%}
18             `,
19         "12345");
20 
21     assertRender(`
22         {%- macro bubbleSort(l) %}
23             {%- for i in l.length.range %}
24                 {%- for j in range(l.length - i - 1) %}
25                     {%- if l[j] > l[j + 1]%}
26                         {%- set l[j], l[j+1] = l[j+1], l[j] %}
27                     {%- endif %}            
28                 {%- endfor %}
29             {%- endfor %}
30         {%- endmacro return l %}
31 
32         {%- set list = [5,4,3,2,1,0] -%}
33 
34         {{ bubbleSort(list) }}`,
35         "[0, 1, 2, 3, 4, 5]");
36 }
37 
38 // Inline statements
39 unittest
40 {
41     assertRender(
42 `       # macro bubbleSort(l) ## comment
43             # for i in l.length.range
44                 # for j in range(l.length - i - 1)
45                     # if l[j] > l[j + 1]
46                         # set l[j], l[j+1] = l[j+1], l[j]
47                     # endif
48                 # endfor
49             # endfor
50         # endmacro return l ## inline comment
51 
52         #- set list = [5,4,3,2,1,0] -
53 
54         {{ bubbleSort(list) }}`,
55         "[0, 1, 2, 3, 4, 5]");
56 
57     // Multiline inline statements
58     assertRender(
59 `# set a = [\
60             1, \
61                \
62             2, \
63                \
64             3, \
65           ] 
66 {{ a }}`,
67         "[1, 2, 3]");
68 }