jinja: add 4 missing features (#32352)

* jinja: add 4 missing features

* apply suggestion

Co-authored-by: Aldehir Rojas <hello@alde.dev>

* fix error msg

---------

Co-authored-by: Aldehir Rojas <hello@alde.dev>
This commit is contained in:
Xuan-Son NguyenandAldehir Rojas authored and GitHub committed 2026-11-16 00:40:44 +01:00
1 parent 1719dbb0ee
commit b4c0e00a4f
6 files changed
+97 -46

No files matched your search

+42
View File
@@ -662,6 +662,42 @@ static void test_expressions(testing & t) {
"20"
);
test_template(t, "floor division",
"{{ 7 // 2 }},{{ -7 // 2 }},{{ 7 // -2 }},{{ 7.5 // 2 }},{{ a // b }}",
{{"a", 10}, {"b", 3}},
"3,-4,-4,3.0,3"
);
test_template(t, "string comparison",
"{{ 'b' > 'a' }},{{ 'VBD' > 'VB' }},{{ 'a' <= 'a' }},{{ 'Z' < 'a' }},{{ 'ab' >= 'b' }}",
json::object(),
"True,True,True,True,False"
);
test_template(t, "unary minus after keyword",
"{{ 1 if false else -1 }},{{ not -1 }},{{ x and -2 }},{{ -3 if x }}",
{{"x", true}},
"-1,False,-2,-3"
);
test_template(t, "unary minus after elif",
"{% if false %}a{% elif -1 < 0 %}b{% endif %}",
json::object(),
"b"
);
test_template(t, "unary and binary sign",
"{{ -x }},{{ - 1 }},{{ --x }},{{ 1 - -x }},{{ 1 -1 }},{{ x -1 }},{{ [x, -1][-1] }},{{ +x }},{{ -x|abs }}",
{{"x", 3}},
"-3,-1,3,4,0,2,-1,3,3"
);
test_template(t, "binary minus after keyword attribute",
"{{ a.else - 1 }}",
{{"a", {{"else", 3}}}},
"2"
);
test_template(t, "string concat ~",
"{{ 'hello' ~ ' ' ~ 'world' }}",
json::object(),
@@ -2195,6 +2231,12 @@ static void test_array_methods(testing & t) {
"6"
);
test_template(t, "array|sum",
"{{ [1, 2.5, 3]|sum }},{{ [1, 2]|sum(start=10) }},{{ items|sum(attribute='w') }},{{ []|sum }}",
{{"items", json::array({{{"w", 1}}, {{"w", 2}}})}},
"6.5,13,3,0"
);
test_template(t, "array|min",
"{{ [tool_calls_count, tool_sep_count]|min }}",
{{"tool_calls_count", 2}, {"tool_sep_count", 1}},