MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / test_loops

Function test_loops

subprojects/llama.cpp/tests/test-jinja.cpp:301–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301static void test_loops(testing & t) {
302 test_template(t, "simple for",
303 "{% for i in items %}{{ i }}{% endfor %}",
304 {{"items", json::array({1, 2, 3})}},
305 "123"
306 );
307
308 test_template(t, "loop.index",
309 "{% for i in items %}{{ loop.index }}{% endfor %}",
310 {{"items", json::array({"a", "b", "c"})}},
311 "123"
312 );
313
314 test_template(t, "loop.index0",
315 "{% for i in items %}{{ loop.index0 }}{% endfor %}",
316 {{"items", json::array({"a", "b", "c"})}},
317 "012"
318 );
319
320 test_template(t, "loop.first and loop.last",
321 "{% for i in items %}{% if loop.first %}[{% endif %}{{ i }}{% if loop.last %}]{% endif %}{% endfor %}",
322 {{"items", json::array({1, 2, 3})}},
323 "[123]"
324 );
325
326 test_template(t, "loop.length",
327 "{% for i in items %}{{ loop.length }}{% endfor %}",
328 {{"items", json::array({"a", "b"})}},
329 "22"
330 );
331
332 test_template(t, "for over dict items",
333 "{% for k, v in data.items() %}{{ k }}={{ v }} {% endfor %}",
334 {{"data", {{"x", 1}, {"y", 2}}}},
335 "x=1 y=2 "
336 );
337
338 test_template(t, "for else empty",
339 "{% for i in items %}{{ i }}{% else %}empty{% endfor %}",
340 {{"items", json::array()}},
341 "empty"
342 );
343
344 test_template(t, "for undefined empty",
345 "{% for i in items %}{{ i }}{% else %}empty{% endfor %}",
346 json::object(),
347 "empty"
348 );
349
350 test_template(t, "nested for",
351 "{% for i in a %}{% for j in b %}{{ i }}{{ j }}{% endfor %}{% endfor %}",
352 {{"a", json::array({1, 2})}, {"b", json::array({"x", "y"})}},
353 "1x1y2x2y"
354 );
355
356 test_template(t, "for with range",
357 "{% for i in range(3) %}{{ i }}{% endfor %}",
358 json::object(),

Callers

nothing calls this directly

Calls 1

test_templateFunction · 0.85

Tested by

no test coverage detected