@@ -6,23 +6,44 @@ import (
6
6
)
7
7
8
8
func 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 {}
11
18
12
- sb .Append (expected )
19
+ s .Append (tt . want )
13
20
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
+ })
16
25
}
17
26
}
18
27
19
28
func 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 {}
21
40
22
- sb .Append ("1234" )
41
+ s .Append (tt . input )
23
42
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
+ })
26
47
}
27
48
}
28
49
@@ -58,7 +79,7 @@ func TestToStringEmptyBuilder(t *testing.T) {
58
79
}
59
80
60
81
func TestNewFromString (t * testing.T ) {
61
- const expected string = "Hello "
82
+ const expected string = "Hellöchen "
62
83
63
84
sb := NewStringBuilderFromString (expected )
64
85
@@ -298,6 +319,7 @@ func TestReplace(t *testing.T) {
298
319
{"Replace Hello with Hallochen" , "Hello World" , "Hello" , "Hallochen" , "Hallochen World" },
299
320
{"Replace Hello with Hallöchen" , "Hello World" , "Hello" , "Hallöchen" , "Hallöchen World" },
300
321
{"Replace ö with ä" , "äö" , "ö" , "ä" , "ää" },
322
+ {"Replace with same word" , "Hello" , "llo" , "llo" , "Hello" },
301
323
}
302
324
for _ , tt := range tests {
303
325
t .Run (tt .name , func (t * testing.T ) {
0 commit comments