]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
jinja : add missing tojson filter for bool (#18900)
authorSigbjørn Skjæret <redacted>
Sun, 18 Jan 2026 00:05:09 +0000 (01:05 +0100)
committerGitHub <redacted>
Sun, 18 Jan 2026 00:05:09 +0000 (01:05 +0100)
* add missing tojson for bool

* add more literal tests

common/jinja/value.cpp
tests/test-jinja.cpp

index fc1023ff2f66e45693fa9237808cefe4124c639c..acf24257fb624305a54250eb406abc86d9236083 100644 (file)
@@ -698,6 +698,7 @@ const func_builtins & value_bool_t::get_builtins() const {
             bool val = args.get_pos(0)->as_bool();
             return mk_val<value_string>(val ? "True" : "False");
         }},
+        {"tojson", tojson},
     };
     return builtins;
 }
index ed75f7089766c52f72448d0f6b306c3dad6ca11a..6ed04876856f1283ed5240318ab69cff2ba00d2e 100644 (file)
@@ -540,6 +540,66 @@ static void test_literals(testing & t) {
         json::object(),
         "1"
     );
+
+    test_template(t, "integer|abs",
+        "{{ -42 | abs }}",
+        json::object(),
+        "42"
+    );
+
+    test_template(t, "integer|float",
+        "{{ 42 | float }}",
+        json::object(),
+        "42.0"
+    );
+
+    test_template(t, "integer|tojson",
+        "{{ 42 | tojson }}",
+        json::object(),
+        "42"
+    );
+
+    test_template(t, "float|abs",
+        "{{ -3.14 | abs }}",
+        json::object(),
+        "3.14"
+    );
+
+    test_template(t, "float|int",
+        "{{ 3.14 | int }}",
+        json::object(),
+        "3"
+    );
+
+    test_template(t, "float|tojson",
+        "{{ 3.14 | tojson }}",
+        json::object(),
+        "3.14"
+    );
+
+    test_template(t, "string|tojson",
+        "{{ 'hello' | tojson }}",
+        json::object(),
+        "\"hello\""
+    );
+
+    test_template(t, "boolean|int",
+        "{{ true | int }}",
+        json::object(),
+        "1"
+    );
+
+    test_template(t, "boolean|float",
+        "{{ true | float }}",
+        json::object(),
+        "1.0"
+    );
+
+    test_template(t, "boolean|tojson",
+        "{{ true | tojson }}",
+        json::object(),
+        "true"
+    );
 }
 
 static void test_comments(testing & t) {