forked from CodeWithKyrian/jinja-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterpreterDataset.php
More file actions
164 lines (157 loc) · 5.79 KB
/
InterpreterDataset.php
File metadata and controls
164 lines (157 loc) · 5.79 KB
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
<?php
declare(strict_types=1);
const EXAMPLE_IF_TEMPLATE = "<div>\n {% if True %}\n yay\n {% endif %}\n</div>";
const EXAMPLE_FOR_TEMPLATE = "{% for item in seq %}\n {{ item }}\n{% endfor %}";
const EXAMPLE_FOR_TEMPLATE_2 = "{% for item in seq -%}\n {{ item }}\n{% endfor %}";
const EXAMPLE_FOR_TEMPLATE_3 = "{% for item in seq %}\n {{ item }}\n{%- endfor %}";
const EXAMPLE_FOR_TEMPLATE_4 = "{% for item in seq -%}\n {{ item }}\n{%- endfor %}";
const EXAMPLE_COMMENT_TEMPLATE = " {# comment #}\n {# {% if true %} {% endif %} #}\n";
const EXAMPLE_OBJECT_LITERAL_TEMPLATE = "{% set obj = { 'key1': 'value1', 'key2': 'value2' } %}{{ obj.key1 }} - {{ obj.key2 }}";
const EXAMPLE_OBJECT_GET = "{% set obj = { 'key1': 'value1', 'key2': 'value2' } %}{{ obj.get('key1') }} - {{ obj.get('key3', 'default') }}";
dataset('interpreterTestData', [
// If tests
'if (no strip or trim)' => [
'template' => EXAMPLE_IF_TEMPLATE,
'data' => [],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "<div>\n \n yay\n \n</div>",
],
// 'if (strip blocks only)' => [
// 'template' => EXAMPLE_IF_TEMPLATE,
// 'data' => [],
// 'lstrip_blocks' => true,
// 'trim_blocks' => false,
// 'target' => "<div>\n\n yay\n\n</div>",
// ],
'if (trim blocks only)' => [
'template' => EXAMPLE_IF_TEMPLATE,
'data' => [],
'lstrip_blocks' => false,
'trim_blocks' => true,
'target' => "<div>\n yay\n </div>",
],
// 'if (strip and trim blocks)' => [
// 'template' => EXAMPLE_IF_TEMPLATE,
// 'data' => [],
// 'lstrip_blocks' => true,
// 'trim_blocks' => true,
// 'target' => "<div>\n yay\n</div>",
// ],
// For tests
'for (no strip or trim)' => [
'template' => EXAMPLE_FOR_TEMPLATE,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "\n 1\n\n 2\n\n 3\n\n 4\n\n 5\n\n 6\n\n 7\n\n 8\n\n 9\n",
],
'for (lstrip blocks only)' => [
'template' => EXAMPLE_FOR_TEMPLATE,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => true,
'trim_blocks' => false,
'target' => "\n 1\n\n 2\n\n 3\n\n 4\n\n 5\n\n 6\n\n 7\n\n 8\n\n 9\n",
],
'for (trim blocks only)' => [
'template' => EXAMPLE_FOR_TEMPLATE,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => true,
'target' => " 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n",
],
'for (strip and trim blocks)' => [
'template' => EXAMPLE_FOR_TEMPLATE,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => true,
'trim_blocks' => true,
'target' => " 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n",
],
'for (single line output with no strip or trim)' => [
'template' => EXAMPLE_FOR_TEMPLATE_2,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "1\n2\n3\n4\n5\n6\n7\n8\n9\n",
],
'for (single line output, no strip or trim 2)' => [
'template' => EXAMPLE_FOR_TEMPLATE_3,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9",
],
'for (single line output, trim only)' => [
'template' => EXAMPLE_FOR_TEMPLATE_3,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => true,
'target' => " 1 2 3 4 5 6 7 8 9",
],
'for (single line output, no strip or trim 3)' => [
'template' =>
EXAMPLE_FOR_TEMPLATE_4,
'data' => ['seq' => range(1, 9)],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "123456789",
],
// Comment tests
'comment (basic)' => [
'template' => EXAMPLE_COMMENT_TEMPLATE,
'data' => [],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => " \n ",
],
// 'comment (lstrip only)' => [
// 'template' => EXAMPLE_COMMENT_TEMPLATE,
// 'data' => [],
// 'lstrip_blocks' => true,
// 'trim_blocks' => false,
// 'target' => "\n",
// ],
// 'comment (trim only)' => [
// 'template' => EXAMPLE_COMMENT_TEMPLATE,
// 'data' => [],
// 'lstrip_blocks' => false,
// 'trim_blocks' => true,
// 'target' => " ",
// ],
// 'comment (lstrip and trim)' => [
// 'template' => EXAMPLE_COMMENT_TEMPLATE,
// 'data' => [],
// 'lstrip_blocks' => true,
// 'trim_blocks' => true,
// 'target' => "",
// ],
// Object literal tests
'object literal (no strip or trim)' => [
'template' => EXAMPLE_OBJECT_LITERAL_TEMPLATE,
'data' => [],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "value1 - value2",
],
'object literal (strip and trim)' => [
'template' => EXAMPLE_OBJECT_LITERAL_TEMPLATE,
'data' => [],
'lstrip_blocks' => true,
'trim_blocks' => true,
'target' => "value1 - value2",
],
'object get method (no strip or trim)' => [
'template' => EXAMPLE_OBJECT_GET,
'data' => [],
'lstrip_blocks' => false,
'trim_blocks' => false,
'target' => "value1 - default",
],
'object get method (strip and trim)' => [
'template' => EXAMPLE_OBJECT_GET,
'data' => [],
'lstrip_blocks' => true,
'trim_blocks' => true,
'target' => "value1 - default",
],
]);