@@ -2237,6 +2237,40 @@ void test_xml_tool_call_parsing() {
22372237 std::cout << " ✅ XML tool call parsing works correctly!" << std::endl;
22382238}
22392239
2240+ // Test whitespace preservation in qwen3 content extraction
2241+ void test_qwen3_whitespace_preservation () {
2242+ std::cout << " \n 🧹 Testing Qwen3 Whitespace Preservation Fix:" << std::endl;
2243+
2244+ // Test case with PEP 8 style: 2 empty lines between functions
2245+ const std::string pep8_content = R"( def celsius_to_fahrenheit(celsius):
2246+ return celsius * 9/5 + 32
2247+
2248+
2249+ def fahrenheit_to_celsius(fahrenheit):
2250+ return (fahrenheit - 32) * 5/9)" ;
2251+
2252+ std::cout << " 🎯 Testing PEP 8 compliance (2 empty lines between functions)..." << std::endl;
2253+ std::cout << " Original content has: 2 empty lines between functions" << std::endl;
2254+
2255+ // Test the qwen3 content extraction directly
2256+ std::string result = qwen3::extract_content_during_parsing (pep8_content, false );
2257+
2258+ // Check if the double newlines are preserved (should have \n\n\n for 2 empty lines)
2259+ bool has_double_empty_lines = result.find (" \n\n\n " ) != std::string::npos;
2260+
2261+ std::cout << " Result content: '" << result << " '" << std::endl;
2262+ std::cout << " Has 2 empty lines preserved: " << (has_double_empty_lines ? " YES" : " NO" ) << std::endl;
2263+
2264+ test_assert (has_double_empty_lines, " Qwen3: PEP 8 double empty lines preserved" );
2265+
2266+ // Additional test: ensure no excessive trimming
2267+ test_assert (!result.empty (), " Qwen3: Content not empty after processing" );
2268+ test_assert (result.find (" celsius_to_fahrenheit" ) != std::string::npos, " Qwen3: Function content preserved" );
2269+ test_assert (result.find (" fahrenheit_to_celsius" ) != std::string::npos, " Qwen3: Second function preserved" );
2270+
2271+ std::cout << " ✅ Qwen3 whitespace preservation working correctly!" << std::endl;
2272+ }
2273+
22402274// Test the streaming tool calls fix implementation
22412275void test_streaming_tool_calls_fix () {
22422276 std::cout << " \n === Streaming Tool Calls Fix Validation ===" << std::endl;
@@ -2797,6 +2831,7 @@ int main() {
27972831 test_content_cleaning ();
27982832 test_contamination_reproduction (); // Added this test
27992833 test_mixed_formats ();
2834+ test_qwen3_whitespace_preservation (); // Test whitespace fix
28002835
28012836 std::cout << " \n 🌍 Unicode & International Tests:" << std::endl;
28022837 test_unicode_support ();
0 commit comments