@@ -194,6 +194,57 @@ a[4] = image[b];
194
194
EXPECT_EQ (expectedResult, result);
195
195
}
196
196
197
+ TEST (ForLoopTest, LoopWithIf)
198
+ {
199
+ std::string source = R"(
200
+ {% for i in range(10) if i is even %}
201
+ a[{{i}}] = image[{{i}}];
202
+ {% endfor %}
203
+ )" ;
204
+
205
+ Template tpl;
206
+ ASSERT_TRUE (tpl.Load (source));
207
+
208
+ ValuesMap params = {
209
+ };
210
+
211
+ std::string result = tpl.RenderAsString (params);
212
+ std::cout << result << std::endl;
213
+ std::string expectedResult = R"(
214
+ a[0] = image[0];
215
+ a[2] = image[2];
216
+ a[4] = image[4];
217
+ a[6] = image[6];
218
+ a[8] = image[8];
219
+ )" ;
220
+ EXPECT_EQ (expectedResult, result);
221
+ }
222
+
223
+ TEST (ForLoopTest, LoopVariableWithIf)
224
+ {
225
+ std::string source = R"(
226
+ {% for i in its if i is even%}
227
+ {{i}} length={{loop.length}}, index={{loop.index}}, index0={{loop.index0}}, first={{loop.first}}, last={{loop.last}}, previtem={{loop.previtem}}, nextitem={{loop.nextitem}};
228
+ {% endfor %}
229
+ )" ;
230
+
231
+ Template mytemplate;
232
+ ASSERT_TRUE (mytemplate.Load (source));
233
+
234
+ ValuesMap params = {
235
+ {" its" , ValuesList{0 , 1 , 2 , 3 , 4 } }
236
+ };
237
+
238
+ std::string result = mytemplate.RenderAsString (params);
239
+ std::cout << result << std::endl;
240
+ std::string expectedResult = R"(
241
+ 0 length=3, index=1, index0=0, first=true, last=false, previtem=, nextitem=2;
242
+ 2 length=3, index=2, index0=1, first=false, last=false, previtem=0, nextitem=4;
243
+ 4 length=3, index=3, index0=2, first=false, last=true, previtem=2, nextitem=;
244
+ )" ;
245
+ EXPECT_EQ (expectedResult, result);
246
+ }
247
+
197
248
TEST (ForLoopTest, LoopVariable)
198
249
{
199
250
std::string source = R"(
0 commit comments