@@ -32,20 +32,16 @@ describe("sliceUtf16Safe", () => {
3232 expect ( sliceUtf16Safe ( emoji , 0 ) ) . toBe ( emoji ) ;
3333 } ) ;
3434
35- it ( "avoids splitting surrogate pair at start" , ( ) => {
36- // 👨 is a surrogate pair (U+1F468)
35+ it ( "returns empty string when slicing middle of surrogate pair" , ( ) => {
3736 const input = "👨👩" ;
38- // Slice at middle of surrogate pair should adjust
39- const result = sliceUtf16Safe ( input , 1 , 3 ) ;
40- // Should not return dangling surrogate
41- expect ( result . length ) . toBeGreaterThanOrEqual ( 0 ) ;
37+ // Slicing at position 1-3 hits middle of surrogate pairs
38+ expect ( sliceUtf16Safe ( input , 1 , 3 ) ) . toBe ( "" ) ;
4239 } ) ;
4340
44- it ( "avoids splitting surrogate pair at end " , ( ) => {
41+ it ( "returns empty string when slicing at start of surrogate pair " , ( ) => {
4542 const input = "👨👩" ;
46- const result = sliceUtf16Safe ( input , 0 , 1 ) ;
47- // Should not return dangling surrogate
48- expect ( result . length ) . toBeGreaterThanOrEqual ( 0 ) ;
43+ // Slicing at position 0-1 would cut surrogate pair, adjust to 0
44+ expect ( sliceUtf16Safe ( input , 0 , 1 ) ) . toBe ( "" ) ;
4945 } ) ;
5046
5147 it ( "handles empty string" , ( ) => {
@@ -85,10 +81,8 @@ describe("truncateUtf16Safe", () => {
8581 expect ( result . length ) . toBeLessThanOrEqual ( emoji . length ) ;
8682 } ) ;
8783
88- it ( "avoids splitting surrogate pair" , ( ) => {
84+ it ( "returns empty string when truncating at surrogate pair boundary " , ( ) => {
8985 const input = "👨👩" ;
90- const result = truncateUtf16Safe ( input , 1 ) ;
91- // Should not return dangling surrogate
92- expect ( result . length ) . toBeGreaterThanOrEqual ( 0 ) ;
86+ expect ( truncateUtf16Safe ( input , 1 ) ) . toBe ( "" ) ;
9387 } ) ;
9488} ) ;
0 commit comments