mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-28 17:07:31 -05:00
add tests
This commit is contained in:
+52
-4
@@ -452,6 +452,18 @@ static void test_expressions(testing & t) {
|
||||
"c"
|
||||
);
|
||||
|
||||
test_template(t, "array bool access",
|
||||
"{{ items[true] }}",
|
||||
{{"items", json::array({"a", "b", "c"})}},
|
||||
"b"
|
||||
);
|
||||
|
||||
test_template(t, "array non-index access",
|
||||
"{{ items[1.0] is undefined }}",
|
||||
{{"items", json::array({"a", "b", "c"})}},
|
||||
"True"
|
||||
);
|
||||
|
||||
test_template(t, "array slice",
|
||||
"{{ items[1:-1]|string }}",
|
||||
{{"items", json::array({"a", "b", "c"})}},
|
||||
@@ -735,6 +747,16 @@ static void test_filters(testing & t) {
|
||||
"xyz"
|
||||
);
|
||||
|
||||
test_template(t, "sort with numeric-like attribute",
|
||||
"{{ items|sort(attribute='01')|join(attribute=1) }}",
|
||||
{{"items", json::array({
|
||||
json::array({1, "z"}),
|
||||
json::array({2, "x"}),
|
||||
json::array({3, "y"}),
|
||||
})}},
|
||||
"xyz"
|
||||
);
|
||||
|
||||
test_template(t, "join",
|
||||
"{{ items|join(', ') }}",
|
||||
{{"items", json::array({"a", "b", "c"})}},
|
||||
@@ -1590,6 +1612,16 @@ static void test_array_methods(testing & t) {
|
||||
"b c "
|
||||
);
|
||||
|
||||
test_template(t, "array|selectattr numeric-like with operator",
|
||||
"{% for item in items|selectattr('0', 'gt', 1) %}{{ item.1 }} {% endfor %}",
|
||||
{{"items", json::array({
|
||||
json::array({3, "z"}),
|
||||
json::array({1, "x"}),
|
||||
json::array({2, "y"}),
|
||||
})}},
|
||||
"z y "
|
||||
);
|
||||
|
||||
test_template(t, "array|tojson",
|
||||
"{{ arr|tojson }}",
|
||||
{{"arr", json::array({1, 2, 3})}},
|
||||
@@ -1654,6 +1686,12 @@ static void test_array_methods(testing & t) {
|
||||
"123"
|
||||
);
|
||||
|
||||
test_template(t, "array|join numeric-like attribute",
|
||||
"{{ arr|join(attribute='0') }}",
|
||||
{{"arr", json::array({json::array({1}), json::array({2}), json::array({3})})}},
|
||||
"123"
|
||||
);
|
||||
|
||||
test_template(t, "array.pop() last",
|
||||
"{{ arr.pop() }}-{{ arr|join(',') }}",
|
||||
{{"arr", json::array({"a", "b", "c"})}},
|
||||
@@ -1712,6 +1750,16 @@ static void test_array_methods(testing & t) {
|
||||
"10 20 30 "
|
||||
);
|
||||
|
||||
test_template(t, "array|map with numeric-like attribute",
|
||||
"{% for v in arr|map(attribute='1') %}{{ v }} {% endfor %}",
|
||||
{{"arr", json::array({
|
||||
json::array({10, "x"}),
|
||||
json::array({20, "y"}),
|
||||
json::array({30, "z"}),
|
||||
})}},
|
||||
"x y z "
|
||||
);
|
||||
|
||||
test_template(t, "array|map with negative attribute",
|
||||
"{% for v in arr|map(attribute=-1) %}{{ v }} {% endfor %}",
|
||||
{{"arr", json::array({
|
||||
@@ -1741,21 +1789,21 @@ static void test_array_methods(testing & t) {
|
||||
);
|
||||
|
||||
test_template(t, "array|min attribute",
|
||||
"{{ items|min(attribute='x') }}",
|
||||
"{{ items|min(attribute='x')|tojson }}",
|
||||
{{"items", json::array({
|
||||
json({{"x", 2}}),
|
||||
json({{"x", 1}}),
|
||||
})}},
|
||||
"{'x': 1}"
|
||||
"{\"x\": 1}"
|
||||
);
|
||||
|
||||
test_template(t, "array|max attribute",
|
||||
"{{ items|max(attribute='x') }}",
|
||||
"{{ items|max(attribute='x')|tojson }}",
|
||||
{{"items", json::array({
|
||||
json({{"x", 2}}),
|
||||
json({{"x", 1}}),
|
||||
})}},
|
||||
"{'x': 2}"
|
||||
"{\"x\": 2}"
|
||||
);
|
||||
|
||||
// not used by any chat templates
|
||||
|
||||
Reference in New Issue
Block a user