MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / test_json_with_dumped_args

Function test_json_with_dumped_args

smallthinker/tests/test-chat-parser.cpp:211–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211static void test_json_with_dumped_args() {
212
213 // Partial content.
214 test("{\"content\": \"t", true, {}, {{"content"}}, "{\"content\":\"t\"}");
215 test("{\"content\": \"", true, {}, {{"content"}}, "{\"content\":\"\"}");
216 test("{\"content\": ", true, {}, {{"content"}}, "{}");
217
218 // If the entire JSON is the arguments, healing it them dumping it produces the same output as the input (just reformatted).
219 test("{\"name\": \"python", true, {{}}, {}, "{\"name\":\"python");
220 for (const auto & src : barely_healable_jsons) {
221 test(src, true, {{}}, {}, src);
222 }
223
224 // Full JSON w/ args
225 for (auto parse_as_partial : {true, false}) {
226 test_with_args(
227 R"({"name": "python", "args": {"arg1": 1}})",
228 R"({"name":"python","args":"{\"arg1\":1}"})",
229 parse_as_partial,
230 /* is_partial= */ false
231 );
232 }
233
234 // Partial JSON w/ partial args
235 test_with_args(
236 R"({"foo": "bar", "args": {")",
237 R"({"foo":"bar","args":"{\""})"
238 );
239 // Partial args broken in object key
240 test_with_args(
241 R"({"foo": "bar", "args": {"ar)",
242 R"({"foo":"bar","args":"{\"ar"})"
243 );
244 // Partial args broken after object key
245 test_with_args(
246 R"({"foo": "bar", "args": {"arg1")",
247 R"({"foo":"bar","args":"{\"arg1\""})"
248 );
249 // Partial args broken before object value
250 test_with_args(
251 R"({"foo": "bar", "args": {"arg1":)",
252 R"({"foo":"bar","args":"{\"arg1\":"})"
253 );
254 // Partial args broken before object value (space)
255 test_with_args(
256 R"({"foo": "bar", "args": {"arg1": )",
257 R"({"foo":"bar","args":"{\"arg1\":"})"
258 );
259 // Partial args broken in object value that may not be complete (int)
260 test_with_args(
261 R"({"foo": "bar", "args": {"arg1": 1)",
262 R"({"foo":"bar","args":"{\"arg1\":"})"
263 );
264 // Partial args broken in object value that is complete (int)
265 test_with_args(
266 R"({"foo": "bar", "args": {"arg1": 1 )",
267 R"({"foo":"bar","args":"{\"arg1\":1"})"
268 );

Callers 1

mainFunction · 0.85

Calls 2

test_with_argsFunction · 0.85
testFunction · 0.70

Tested by

no test coverage detected