char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
d9f918d2d
char/aliceai-t5-moe
1#include "tests.h" 2 3void test_json_serialization (testing & t ) { 4auto original = build_peg_parser ([](common_peg_parser_builder & p ) { 5return "<tool_call>" + p .json ()+ "</tool_call>" ; 6 }); 7 8auto json_serialized = original .to_json ().dump (); 9 10t .test ("compare before/after" , [& ](testing & t ) { 11auto deserialized = common_peg_arena::from_json (common_json::parse (json_serialized )); 12 13// Test complex JSON 14 std::string input = R"({"name": "test", "values": [1, 2, 3], "nested": {"a": true}})" ; 15common_peg_parse_context ctx1 (input ); 16common_peg_parse_context ctx2 (input ); 17 18auto result1 = original .parse (ctx1 ); 19auto result2 = deserialized .parse (ctx2 ); 20 21t .assert_equal ("both_succeed" ,result1 .success (),result2 .success ()); 22t .assert_equal ("same_end_pos" ,result1 .end ,result2 .end ); 23 }); 24 25t .bench ("deserialize" , [& ]() { 26auto deserialized = common_peg_arena::from_json (common_json::parse (json_serialized )); 27 },100 ); 28}