@@ -124,6 +124,19 @@ func TestRemoveWhenLengthZero(t *testing.T) {
124124 }
125125}
126126
127+ func TestRemoveInTheMiddle (t * testing.T ) {
128+ const expected string = "Hlo World"
129+ sb := NewStringBuilderFromString ("Hello World" )
130+
131+ if err := sb .Remove (1 , 2 ); err != nil {
132+ t .Errorf ("Remove threw an error: %v" , err )
133+ }
134+
135+ if result := sb .ToString (); result != expected {
136+ t .Errorf ("Actual %q, Expected: %q" , result , expected )
137+ }
138+ }
139+
127140func TestInsertAtIndex (t * testing.T ) {
128141 const expected string = "Hello my dear and beautiful World"
129142 sb := NewStringBuilderFromString ("Hello World" )
@@ -259,6 +272,41 @@ func TestFindAll(t *testing.T) {
259272 }
260273}
261274
275+ func TestReplaceRune (t * testing.T ) {
276+ s := NewStringBuilderFromString ("Hello" )
277+
278+ s .ReplaceRune ('l' , 'm' )
279+
280+ if got := s .ToString (); got != "Hemmo" {
281+ t .Errorf ("StringBuilder.ReplaceRune() = %v, want %v" , got , "Hemmo" )
282+ }
283+ }
284+
285+ func TestReplace (t * testing.T ) {
286+ tests := []struct {
287+ name string
288+ input string
289+ oldValue string
290+ newvalue string
291+ want string
292+ }{
293+ {"Replace Hello with Hallo" , "Hello World" , "Hello" , "Hallo" , "Hallo World" },
294+ {"Replace Hello with Ha" , "Hello World" , "Hello" , "Ha" , "Ha World" },
295+ {"Replace Hello with Hallöchen" , "Hello World" , "Hello" , "Hallochen" , "Hallochen World" },
296+ }
297+ for _ , tt := range tests {
298+ t .Run (tt .name , func (t * testing.T ) {
299+ s := NewStringBuilderFromString (tt .input )
300+
301+ s .Replace (tt .oldValue , tt .newvalue )
302+
303+ if got := s .ToString (); got != tt .want {
304+ t .Errorf ("StringBuilder.FindLast() = %v, want %v" , got , tt .want )
305+ }
306+ })
307+ }
308+ }
309+
262310func slicesEqual (a []int , b []int ) bool {
263311 if len (a ) != len (b ) {
264312 return false
0 commit comments