summaryrefslogtreecommitdiff
path: root/llama.cpp/tests/peg-parser/test-json-serialization.cpp
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
commitb333b06772c89d96aacb5490d6a219fba7c09cc6 (patch)
tree211df60083a5946baa2ed61d33d8121b7e251b06 /llama.cpp/tests/peg-parser/test-json-serialization.cpp
downloadllmnpc-b333b06772c89d96aacb5490d6a219fba7c09cc6.tar.gz
Engage!
Diffstat (limited to 'llama.cpp/tests/peg-parser/test-json-serialization.cpp')
-rw-r--r--llama.cpp/tests/peg-parser/test-json-serialization.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llama.cpp/tests/peg-parser/test-json-serialization.cpp b/llama.cpp/tests/peg-parser/test-json-serialization.cpp
new file mode 100644
index 0000000..a858010
--- /dev/null
+++ b/llama.cpp/tests/peg-parser/test-json-serialization.cpp
@@ -0,0 +1,28 @@
+#include "tests.h"
+
+void test_json_serialization(testing &t) {
+ auto original = build_peg_parser([](common_peg_parser_builder & p) {
+ return "<tool_call>" + p.json() + "</tool_call>";
+ });
+
+ auto json_serialized = original.to_json().dump();
+
+ t.test("compare before/after", [&](testing &t) {
+ auto deserialized = common_peg_arena::from_json(nlohmann::json::parse(json_serialized));
+
+ // Test complex JSON
+ std::string input = R"({"name": "test", "values": [1, 2, 3], "nested": {"a": true}})";
+ common_peg_parse_context ctx1(input);
+ common_peg_parse_context ctx2(input);
+
+ auto result1 = original.parse(ctx1);
+ auto result2 = deserialized.parse(ctx2);
+
+ t.assert_equal("both_succeed", result1.success(), result2.success());
+ t.assert_equal("same_end_pos", result1.end, result2.end);
+ });
+
+ t.bench("deserialize", [&]() {
+ auto deserialized = common_peg_arena::from_json(nlohmann::json::parse(json_serialized));
+ }, 100);
+}