@@ -60,9 +60,8 @@ public void Insert_EmptyValue_ReturnsOriginal()
6060 [ Fact ]
6161 public void Insert_IntoEmptyString_WorksCorrectly ( )
6262 {
63- var empty = pool . Allocate ( "" ) ;
64- // Since pool.Allocate("") returns PooledString.Empty, we need to allocate through the pool directly
65- var result = pool . Allocate ( "Hello" ) ;
63+ var empty = pool . CreateEmptyString ( ) ;
64+ var result = empty . Insert ( 0 , "Hello" ) ;
6665
6766 Assert . Equal ( "Hello" , result . ToString ( ) ) ;
6867 }
@@ -80,11 +79,38 @@ public void Insert_InvalidPosition_ThrowsArgumentOutOfRangeException(int positio
8079 [ Fact ]
8180 public void Insert_IntoEmptyStringInvalidPosition_ThrowsArgumentOutOfRangeException ( )
8281 {
83- var empty = PooledString . Empty ;
82+ var empty = pool . CreateEmptyString ( ) ;
8483
8584 Assert . Throws < ArgumentOutOfRangeException > ( ( ) => empty . Insert ( 1 , "test" ) ) ;
8685 }
8786
87+ [ Fact ]
88+ public void Insert_IntoAllocatedEmptyString_WorksCorrectly ( )
89+ {
90+ var empty = pool . Allocate ( "" ) ;
91+ var result = empty . Insert ( 0 , "World" ) ;
92+
93+ Assert . Equal ( "World" , result . ToString ( ) ) ;
94+ }
95+
96+ [ Fact ]
97+ public void Insert_AppendToString_WorksCorrectly ( )
98+ {
99+ var str = pool . Allocate ( "Hello" ) ;
100+ var result = str . Insert ( str . Length , " World" ) ;
101+
102+ Assert . Equal ( "Hello World" , result . ToString ( ) ) ;
103+ }
104+
105+ [ Fact ]
106+ public void Insert_AppendToEmptyString_WorksCorrectly ( )
107+ {
108+ var empty = pool . CreateEmptyString ( ) ;
109+ var result = empty . Insert ( empty . Length , "Appended" ) ;
110+
111+ Assert . Equal ( "Appended" , result . ToString ( ) ) ;
112+ }
113+
88114 #endregion
89115
90116 #region Replace Tests
@@ -172,6 +198,7 @@ public void Replace_EntireString_WorksCorrectly()
172198
173199 #endregion
174200
201+
175202 #region Search Operations Tests
176203
177204 [ Fact ]
@@ -203,7 +230,7 @@ public void IndexOf_EmptyString_ReturnsZero()
203230 [ Fact ]
204231 public void IndexOf_InEmptyString_ReturnsCorrectly ( )
205232 {
206- var empty = PooledString . Empty ;
233+ var empty = pool . CreateEmptyString ( ) ;
207234
208235 Assert . Equal ( 0 , empty . IndexOf ( "" ) ) ;
209236 Assert . Equal ( - 1 , empty . IndexOf ( "test" ) ) ;
@@ -303,7 +330,7 @@ public void EndsWith_Incorrect_ReturnsFalse()
303330 [ Fact ]
304331 public void StringOperations_WithEmptyString_WorkCorrectly ( )
305332 {
306- var empty = PooledString . Empty ;
333+ var empty = pool . CreateEmptyString ( ) ;
307334
308335 Assert . True ( empty . Contains ( "" ) ) ;
309336 Assert . True ( empty . StartsWith ( "" ) ) ;
@@ -382,7 +409,7 @@ public void AsSpan_ValidString_ReturnsCorrectSpan()
382409 [ Fact ]
383410 public void AsSpan_EmptyString_ReturnsEmptySpan ( )
384411 {
385- var empty = PooledString . Empty ;
412+ var empty = pool . CreateEmptyString ( ) ;
386413 var span = empty . AsSpan ( ) ;
387414
388415 Assert . True ( span . IsEmpty ) ;
@@ -425,8 +452,9 @@ public void Equals_DifferentContent_ReturnsFalse()
425452 [ Fact ]
426453 public void Equals_EmptyStrings_ReturnsTrue ( )
427454 {
428- var empty1 = PooledString . Empty ;
429- var empty2 = PooledString . Empty ;
455+ using var pool = new UnmanagedStringPool ( 1024 ) ;
456+ var empty1 = pool . CreateEmptyString ( ) ;
457+ var empty2 = pool . CreateEmptyString ( ) ;
430458
431459 Assert . True ( empty1 . Equals ( empty2 ) ) ;
432460 Assert . True ( empty1 == empty2 ) ;
@@ -435,7 +463,7 @@ public void Equals_EmptyStrings_ReturnsTrue()
435463 [ Fact ]
436464 public void Equals_EmptyWithAllocated_WorksCorrectly ( )
437465 {
438- var empty = PooledString . Empty ;
466+ var empty = pool . CreateEmptyString ( ) ;
439467 var emptyAllocated = pool . Allocate ( "" ) ;
440468 var nonEmpty = pool . Allocate ( "Hello" ) ;
441469
@@ -501,7 +529,7 @@ public void GetHashCode_RandomStrings_MostHaveDifferentHashes()
501529 [ Fact ]
502530 public void GetHashCode_EmptyString_ReturnsZero ( )
503531 {
504- var empty = PooledString . Empty ;
532+ var empty = pool . CreateEmptyString ( ) ;
505533
506534 Assert . Equal ( 0 , empty . GetHashCode ( ) ) ;
507535 }
@@ -639,7 +667,7 @@ public void Length_CorrectlyReturnsStringLength()
639667 [ Fact ]
640668 public void Length_EmptyString_ReturnsZero ( )
641669 {
642- var empty = PooledString . Empty ;
670+ var empty = pool . CreateEmptyString ( ) ;
643671 var emptyAllocated = pool . Allocate ( "" ) ;
644672
645673 Assert . Equal ( 0 , empty . Length ) ;
@@ -649,7 +677,7 @@ public void Length_EmptyString_ReturnsZero()
649677 [ Fact ]
650678 public void IsEmpty_EmptyString_ReturnsTrue ( )
651679 {
652- var empty = PooledString . Empty ;
680+ var empty = pool . CreateEmptyString ( ) ;
653681 var emptyAllocated = pool . Allocate ( "" ) ;
654682
655683 Assert . True ( empty . IsEmpty ) ;
@@ -679,7 +707,7 @@ public void ToString_ValidString_ReturnsCorrectString()
679707 [ Fact ]
680708 public void ToString_EmptyString_ReturnsEmptyString ( )
681709 {
682- var empty = PooledString . Empty ;
710+ var empty = pool . CreateEmptyString ( ) ;
683711
684712 Assert . Equal ( "" , empty . ToString ( ) ) ;
685713 }
0 commit comments