mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-08-26 06:31:04 +02:00
d9f918d2d0
* add common/json * migrate common * adapt jinja * migrate server * big wip * migrate tests * wip * revert some excessive changes * wip * wip 2 * revert redundant changes * fix server crash * various fixes * fix ci * harden a bit * clean up * rm json-shim * add some comments * rm redundant decl
29 lines
1015 B
C++
29 lines
1015 B
C++
#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(common_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(common_json::parse(json_serialized));
|
|
}, 100);
|
|
}
|