| 46 | } |
| 47 | |
| 48 | static void test_reasoning() { |
| 49 | { |
| 50 | common_chat_msg_parser builder("<tnk>Cogito</tnk>Ergo sum", /* is_partial= */ false, { |
| 51 | /* .format = */ COMMON_CHAT_FORMAT_CONTENT_ONLY, |
| 52 | /* .reasoning_format = */ COMMON_REASONING_FORMAT_NONE, |
| 53 | /* .reasoning_in_content = */ false, |
| 54 | /* .thinking_forced_open = */ false, |
| 55 | }); |
| 56 | assert_equals(false, builder.try_parse_reasoning("<tnk>", "</tnk>")); |
| 57 | assert_equals("<tnk>Cogito</tnk>Ergo sum", builder.consume_rest()); |
| 58 | } |
| 59 | { |
| 60 | common_chat_msg_parser builder("<tnk>Cogito</tnk>Ergo sum", /* is_partial= */ false, { |
| 61 | /* .format = */ COMMON_CHAT_FORMAT_CONTENT_ONLY, |
| 62 | /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK, |
| 63 | /* .reasoning_in_content = */ false, |
| 64 | /* .thinking_forced_open = */ false, |
| 65 | }); |
| 66 | assert_equals(true, builder.try_parse_reasoning("<tnk>", "</tnk>")); |
| 67 | assert_equals(std::string("Cogito"), builder.result().reasoning_content); |
| 68 | assert_equals("Ergo sum", builder.consume_rest()); |
| 69 | } |
| 70 | { |
| 71 | common_chat_msg_parser builder("Cogito</tnk>Ergo sum", /* is_partial= */ false, { |
| 72 | /* .format = */ COMMON_CHAT_FORMAT_CONTENT_ONLY, |
| 73 | /* .reasoning_format = */ COMMON_REASONING_FORMAT_NONE, |
| 74 | /* .reasoning_in_content = */ false, |
| 75 | /* .thinking_forced_open = */ false, |
| 76 | }); |
| 77 | assert_equals(false, builder.try_parse_reasoning("<tnk>", "</tnk>")); |
| 78 | assert_equals("Cogito</tnk>Ergo sum", builder.consume_rest()); |
| 79 | } |
| 80 | { |
| 81 | common_chat_msg_parser builder("Cogito</tnk>Ergo sum", /* is_partial= */ false, { |
| 82 | /* .format = */ COMMON_CHAT_FORMAT_CONTENT_ONLY, |
| 83 | /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK, |
| 84 | /* .reasoning_in_content = */ false, |
| 85 | /* .thinking_forced_open = */ true, |
| 86 | }); |
| 87 | assert_equals(true, builder.try_parse_reasoning("<tnk>", "</tnk>")); |
| 88 | assert_equals(std::string("Cogito"), builder.result().reasoning_content); |
| 89 | assert_equals("Ergo sum", builder.consume_rest()); |
| 90 | } |
| 91 | { |
| 92 | common_chat_msg_parser builder("Cogito</tnk>Ergo sum", /* is_partial= */ false, { |
| 93 | /* .format = */ COMMON_CHAT_FORMAT_CONTENT_ONLY, |
| 94 | /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK, |
| 95 | /* .reasoning_in_content = */ true, |
| 96 | /* .thinking_forced_open = */ true, |
| 97 | }); |
| 98 | assert_equals(true, builder.try_parse_reasoning("<tnk>", "</tnk>")); |
| 99 | assert_equals("<think>Cogito</think>", builder.result().content); |
| 100 | assert_equals("Ergo sum", builder.consume_rest()); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void test_regex() { |
| 105 | auto test_throws = [](const std::string & input, const std::string & regex, const std::string & expected_exception_pattern = "") { |
no test coverage detected