CoolFace
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 2d agoView on Hugging Face
0likes1.1kdownloads
test-json-serialization.cpp29 linesDownload Raw Back to peg-parser
1#include "tests.h"2 3void test_json_serialization(testing &t) {4    auto original = build_peg_parser([](common_peg_parser_builder & p) {5        return "<tool_call>" + p.json() + "</tool_call>";6    });7 8    auto json_serialized = original.to_json().dump();9 10    t.test("compare before/after", [&](testing &t) {11        auto deserialized = common_peg_arena::from_json(common_json::parse(json_serialized));12 13        // Test complex JSON14        std::string input = R"({"name": "test", "values": [1, 2, 3], "nested": {"a": true}})";15        common_peg_parse_context ctx1(input);16        common_peg_parse_context ctx2(input);17 18        auto result1 = original.parse(ctx1);19        auto result2 = deserialized.parse(ctx2);20 21        t.assert_equal("both_succeed", result1.success(), result2.success());22        t.assert_equal("same_end_pos", result1.end, result2.end);23    });24 25    t.bench("deserialize", [&]() {26        auto deserialized = common_peg_arena::from_json(common_json::parse(json_serialized));27    }, 100);28}29