@@ -165,40 +165,46 @@ const std::vector<std::string> barely_healable_jsons = {
165165 " {\" name\" :\" python" ,
166166};
167167
168- static void test (const std::string & input, bool is_partial, const std::vector<std::vector<std::string>> & args_paths, const std::string & expected) {
168+ static void test (const std::string & input, bool is_partial, const std::vector<std::vector<std::string>> & args_paths, const std::vector<std::vector<std::string>> & content_paths, const std:: string & expected) {
169169 common_chat_msg_parser builder (input, is_partial, {});
170- auto js = builder.try_consume_json_with_dumped_args (args_paths);
170+ auto js = builder.try_consume_json_with_dumped_args (args_paths, content_paths );
171171 assert_equals (true , js.has_value ());
172172 assert_equals (is_partial, js->is_partial );
173173 assert_equals (expected, args_paths.size () == 1 && args_paths[0 ].empty () ? js->value .get <std::string>() : js->value .dump ());
174174}
175175static void test_with_args (const std::string & input, const std::string & expected, bool parse_as_partial = true , bool is_partial = true ) {
176176 common_chat_msg_parser builder (input, parse_as_partial, {});
177- auto js = builder.try_consume_json_with_dumped_args ({{" args" }});
177+ auto js = builder.try_consume_json_with_dumped_args ({{" args" }}, {} );
178178 assert_equals (true , js.has_value ());
179179 assert_equals (is_partial, js->is_partial );
180180 assert_equals (expected, js->value .dump ());
181181}
182182
183183static void test_json_with_dumped_args_no_args () {
184184 // Normal JSON, nothing to heal, nothing to dump
185- test (" {\" name\" : \" python\" }" , false , {}, " {\" name\" :\" python\" }" );
185+ test (" {\" name\" : \" python\" }" , false , {}, {}, " {\" name\" :\" python\" }" );
186186 // Full json is args
187- test (" {\" name\" : \" python\" }" , false , {{}}, " {\" name\" :\" python\" }" );
187+ test (" {\" name\" : \" python\" }" , false , {{}}, {}, " {\" name\" :\" python\" }" );
188188
189189 // If the arguments are further down, don't heal partial content.
190190 for (const auto & src : barely_healable_jsons) {
191- test (src, true , {{" arguments" }}, " {}" );
191+ test (src, true , {{" arguments" }}, {}, " {}" );
192192 }
193193 // But heal content that isn't partial.
194- test (" {\" name\" : \" python\" " , true , {{" arguments" }}, " {\" name\" :\" python\" }" );
194+ test (" {\" name\" : \" python\" " , true , {{" arguments" }}, {}, " {\" name\" :\" python\" }" );
195195}
196196
197197static void test_json_with_dumped_args () {
198+
199+ // Partial content.
200+ test (" {\" content\" : \" t" , true , {}, {{" content" }}, " {\" content\" :\" t\" }" );
201+ test (" {\" content\" : \" " , true , {}, {{" content" }}, " {\" content\" :\"\" }" );
202+ test (" {\" content\" : " , true , {}, {{" content" }}, " {}" );
203+
198204 // If the entire JSON is the arguments, healing it them dumping it produces the same output as the input (just reformatted).
199- test (" {\" name\" : \" python" , true , {{}}, " {\" name\" :\" python" );
205+ test (" {\" name\" : \" python" , true , {{}}, {}, " {\" name\" :\" python" );
200206 for (const auto & src : barely_healable_jsons) {
201- test (src, true , {{}}, src);
207+ test (src, true , {{}}, {}, src);
202208 }
203209
204210 // Full JSON w/ args
0 commit comments