@@ -6,23 +6,44 @@ import (
66)
77
88func TestAppend (t * testing.T ) {
9- const expected string = "Hello World"
10- sb := StringBuilder {}
9+ tests := []struct {
10+ want string
11+ }{
12+ {"Hello World" },
13+ {"Hallöchen" },
14+ }
15+ for _ , tt := range tests {
16+ t .Run (tt .want , func (t * testing.T ) {
17+ s := & StringBuilder {}
1118
12- sb .Append (expected )
19+ s .Append (tt . want )
1320
14- if result := sb .ToString (); result != expected {
15- t .Errorf ("Actual %q, Expected: %q" , result , expected )
21+ if got := s .ToString (); got != tt .want {
22+ t .Errorf ("StringBuilder.Append() = %v, want %v" , got , tt .want )
23+ }
24+ })
1625 }
1726}
1827
1928func TestLen (t * testing.T ) {
20- sb := StringBuilder {}
29+ tests := []struct {
30+ name string
31+ input string
32+ want int
33+ }{
34+ {"English word" , "Hello" , 5 },
35+ {"Word with Umlaut" , "Hallöchen" , 9 },
36+ }
37+ for _ , tt := range tests {
38+ t .Run (tt .name , func (t * testing.T ) {
39+ s := & StringBuilder {}
2140
22- sb .Append ("1234" )
41+ s .Append (tt . input )
2342
24- if len := sb .Len (); len != 4 {
25- t .Errorf ("Actual %q, Expected: %q" , len , 4 )
43+ if got := s .Len (); got != tt .want {
44+ t .Errorf ("StringBuilder.Append() = %v, want %v" , got , tt .want )
45+ }
46+ })
2647 }
2748}
2849
@@ -58,7 +79,7 @@ func TestToStringEmptyBuilder(t *testing.T) {
5879}
5980
6081func TestNewFromString (t * testing.T ) {
61- const expected string = "Hello "
82+ const expected string = "Hellöchen "
6283
6384 sb := NewStringBuilderFromString (expected )
6485
@@ -298,6 +319,7 @@ func TestReplace(t *testing.T) {
298319 {"Replace Hello with Hallochen" , "Hello World" , "Hello" , "Hallochen" , "Hallochen World" },
299320 {"Replace Hello with Hallöchen" , "Hello World" , "Hello" , "Hallöchen" , "Hallöchen World" },
300321 {"Replace ö with ä" , "äö" , "ö" , "ä" , "ää" },
322+ {"Replace with same word" , "Hello" , "llo" , "llo" , "Hello" },
301323 }
302324 for _ , tt := range tests {
303325 t .Run (tt .name , func (t * testing.T ) {
0 commit comments