@@ -798,7 +798,6 @@ def test_utf8_replacement_character_handling():
798798 assert True , "Replacement character handling passed"
799799
800800
801- @pytest .mark .skip (reason = "Skipping UTF-8 2-byte sequence test" )
802801def test_utf8_2byte_sequence_complete_coverage ():
803802 """
804803 Comprehensive test for 2-byte UTF-8 sequence handling in ddbc_bindings.h lines 473-488.
@@ -838,7 +837,10 @@ def test_utf8_2byte_sequence_complete_coverage():
838837 print (f" { test_bytes .hex ()} : { binary } ({ desc } ) -> Exception occurred" )
839838 # Any error handling is acceptable for invalid sequences
840839
841- print (" ✓ All invalid continuation bytes handled\n " )
840+ try :
841+ print (" ✓ All invalid continuation bytes handled\n " )
842+ except UnicodeEncodeError :
843+ print (" All invalid continuation bytes handled\n " )
842844
843845 # TEST 2: Lines 481-484 - Valid decoding path
844846 # Condition: cp >= 0x80 (after continuation byte validated)
@@ -853,7 +855,10 @@ def test_utf8_2byte_sequence_complete_coverage():
853855 for test_bytes , expected_char , codepoint , desc in valid_2byte :
854856 # Test decoding
855857 result = test_bytes .decode ("utf-8" )
856- print (f" { test_bytes .hex ()} : U+{ codepoint :04X} -> { repr (result )} ({ desc } )" )
858+ try :
859+ print (f" { test_bytes .hex ()} : U+{ codepoint :04X} -> { repr (result )} ({ desc } )" )
860+ except UnicodeEncodeError :
861+ print (f" { test_bytes .hex ()} : U+{ codepoint :04X} -> <result> ({ desc } )" )
857862 assert result == expected_char , f"Should decode to { expected_char !r} "
858863 assert "\ufffd " not in result , f"Should NOT contain U+FFFD for valid sequence"
859864
@@ -863,7 +868,10 @@ def test_utf8_2byte_sequence_complete_coverage():
863868 binary_result == test_bytes
864869 ), f"Binary({ expected_char !r} ) should encode to { test_bytes .hex ()} "
865870
866- print (" ✓ All valid 2-byte sequences correctly decoded\n " )
871+ try :
872+ print (" ✓ All valid 2-byte sequences correctly decoded\n " )
873+ except UnicodeEncodeError :
874+ print (" All valid 2-byte sequences correctly decoded\n " )
867875
868876 # TEST 3: Lines 486-487 - Overlong encoding rejection
869877 # Condition: cp < 0x80 (overlong encoding)
@@ -893,7 +901,10 @@ def test_utf8_2byte_sequence_complete_coverage():
893901 f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> Exception occurred"
894902 )
895903
896- print (" ✓ All overlong 2-byte encodings handled\n " )
904+ try :
905+ print (" ✓ All overlong 2-byte encodings handled\n " )
906+ except UnicodeEncodeError :
907+ print (" All overlong 2-byte encodings handled\n " )
897908
898909 # TEST 4: Edge cases and boundaries
899910 print ("TEST 4: Boundary testing" )
@@ -915,7 +926,10 @@ def test_utf8_2byte_sequence_complete_coverage():
915926 print (f" 2-byte max: { two_byte_max .hex ()} -> U+07FF: { repr (result_3 )} " )
916927 assert ord (result_3 ) == 0x7FF
917928
918- print (" ✓ Boundary cases handled correctly\n " )
929+ try :
930+ print (" ✓ Boundary cases handled correctly\n " )
931+ except UnicodeEncodeError :
932+ print (" Boundary cases handled correctly\n " )
919933
920934 # TEST 5: Bit pattern validation details
921935 print ("TEST 5: Detailed bit pattern analysis" )
@@ -939,7 +953,10 @@ def test_utf8_2byte_sequence_complete_coverage():
939953 assert (byte_val & 0xC0 ) == masked , f"Bit masking incorrect for 0x{ byte_val :02X} "
940954 assert ((byte_val & 0xC0 ) == 0x80 ) == valid , f"Validation incorrect for 0x{ byte_val :02X} "
941955
942- print (" ✓ Bit pattern validation correct\n " )
956+ try :
957+ print (" ✓ Bit pattern validation correct\n " )
958+ except UnicodeEncodeError :
959+ print (" Bit pattern validation correct\n " )
943960
944961 print ("=== All 2-byte UTF-8 sequence tests passed ===" )
945962 assert True , "Complete 2-byte sequence coverage validated"
@@ -1054,7 +1071,10 @@ def test_utf8_3byte_sequence_complete_coverage():
10541071 binary_result == test_bytes
10551072 ), f"Binary({ expected_char !r} ) should encode to { test_bytes .hex ()} "
10561073
1057- print (" ✓ All valid 3-byte sequences correctly decoded\n " )
1074+ try :
1075+ print (" ✓ All valid 3-byte sequences correctly decoded\n " )
1076+ except UnicodeEncodeError :
1077+ print (" All valid 3-byte sequences correctly decoded\n " )
10581078
10591079 # TEST 3: Lines 499-502 - Surrogate range rejection
10601080 # Condition: cp < 0xD800 || cp > 0xDFFF (must be FALSE to reject)
@@ -1084,7 +1104,10 @@ def test_utf8_3byte_sequence_complete_coverage():
10841104 # Python may not allow creating surrogate characters directly
10851105 pass
10861106
1087- print (" ✓ All surrogate encodings correctly rejected\n " )
1107+ try :
1108+ print (" ✓ All surrogate encodings correctly rejected\n " )
1109+ except UnicodeEncodeError :
1110+ print (" All surrogate encodings correctly rejected\n " )
10881111
10891112 # TEST 4: Lines 504-505 - Overlong encoding rejection
10901113 # Condition: cp < 0x800 (overlong encoding)
@@ -1115,7 +1138,10 @@ def test_utf8_3byte_sequence_complete_coverage():
11151138 f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> Exception occurred"
11161139 )
11171140
1118- print (" ✓ All overlong 3-byte encodings handled\n " )
1141+ try :
1142+ print (" ✓ All overlong 3-byte encodings handled\n " )
1143+ except UnicodeEncodeError :
1144+ print (" All overlong 3-byte encodings handled\n " )
11191145
11201146 # TEST 5: Boundary testing
11211147 print ("TEST 5: Boundary testing" )
@@ -1148,7 +1174,10 @@ def test_utf8_3byte_sequence_complete_coverage():
11481174 print (f" 3-byte max: { three_byte_max .hex ()} -> U+FFFF: { repr (result_max )} " )
11491175 assert ord (result_max ) == 0xFFFF
11501176
1151- print (" ✓ Boundary cases handled correctly\n " )
1177+ try :
1178+ print (" ✓ Boundary cases handled correctly\n " )
1179+ except UnicodeEncodeError :
1180+ print (" Boundary cases handled correctly\n " )
11521181
11531182 # TEST 6: Bit pattern validation for continuation bytes
11541183 print ("TEST 6: Continuation byte bit pattern validation" )
@@ -1319,7 +1348,10 @@ def test_utf8_4byte_sequence_complete_coverage():
13191348 binary_result == test_bytes
13201349 ), f"Binary({ expected_char !r} ) should encode to { test_bytes .hex ()} "
13211350
1322- print (" ✓ All valid 4-byte sequences correctly decoded\n " )
1351+ try :
1352+ print (" ✓ All valid 4-byte sequences correctly decoded\n " )
1353+ except UnicodeEncodeError :
1354+ print (" All valid 4-byte sequences correctly decoded\n " )
13231355
13241356 # TEST 3: Lines 524-525 - Overlong encoding rejection
13251357 # Condition: cp < 0x10000 (overlong encoding)
@@ -1350,7 +1382,10 @@ def test_utf8_4byte_sequence_complete_coverage():
13501382 f" { test_bytes .hex ()} : Overlong encoding of U+{ codepoint :04X} ({ desc } ) -> Exception occurred"
13511383 )
13521384
1353- print (" ✓ All overlong 4-byte encodings handled\n " )
1385+ try :
1386+ print (" ✓ All overlong 4-byte encodings handled\n " )
1387+ except UnicodeEncodeError :
1388+ print (" All overlong 4-byte encodings handled\n " )
13541389
13551390 # TEST 4: Lines 524-525 - Out of range rejection
13561391 # Condition: cp > 0x10FFFF (beyond maximum Unicode)
@@ -1368,7 +1403,10 @@ def test_utf8_4byte_sequence_complete_coverage():
13681403 # Should be rejected (behavior may vary by platform)
13691404 assert len (result ) > 0 , f"Should produce some output for out-of-range U+{ codepoint :06X} "
13701405
1371- print (" ✓ All out-of-range sequences correctly rejected\n " )
1406+ try :
1407+ print (" ✓ All out-of-range sequences correctly rejected\n " )
1408+ except UnicodeEncodeError :
1409+ print (" All out-of-range sequences correctly rejected\n " )
13721410
13731411 # TEST 5: Lines 528-529 - Invalid sequence fallback
13741412 print ("TEST 5: Invalid sequence fallback (lines 528-529)" )
@@ -1393,7 +1431,10 @@ def test_utf8_4byte_sequence_complete_coverage():
13931431 except Exception as e :
13941432 print (f" { test_bytes .hex ()} : { desc } -> Exception occurred" )
13951433
1396- print (" ✓ Invalid sequences handled\n " )
1434+ try :
1435+ print (" ✓ Invalid sequences handled\n " )
1436+ except UnicodeEncodeError :
1437+ print (" Invalid sequences handled\n " )
13971438
13981439 # TEST 6: Boundary testing
13991440 print ("TEST 6: Boundary testing" )
@@ -1421,7 +1462,10 @@ def test_utf8_4byte_sequence_complete_coverage():
14211462 # Beyond max may be handled differently on different platforms
14221463 assert len (result_beyond ) > 0 , "Should produce some output for beyond-max sequence"
14231464
1424- print (" ✓ Boundary cases handled correctly\n " )
1465+ try :
1466+ print (" ✓ Boundary cases handled correctly\n " )
1467+ except UnicodeEncodeError :
1468+ print (" Boundary cases handled correctly\n " )
14251469
14261470 # TEST 7: Bit pattern validation for continuation bytes
14271471 print ("TEST 7: Continuation byte bit pattern validation" )
0 commit comments