@@ -45,3 +45,65 @@ func TestAppendRune(t *testing.T) {
4545 t .Errorf ("Actual %q, Expected: %q" , result , expected )
4646 }
4747}
48+
49+ func TestToStringEmptyBuilder (t * testing.T ) {
50+ sb := StringBuilder {}
51+
52+ if result := sb .ToString (); result != "" {
53+ t .Errorf ("String should be empty but was: %q" , result )
54+ }
55+ }
56+
57+ func TestNewFromString (t * testing.T ) {
58+ const expected string = "Hello"
59+
60+ sb := NewFromString (expected )
61+
62+ if result := sb .ToString (); result != expected {
63+ t .Errorf ("Actual %q, Expected: %q" , result , expected )
64+ }
65+ }
66+
67+ func TestRemovePartOfString (t * testing.T ) {
68+ sb := NewFromString ("Hello" )
69+
70+ if err := sb .Remove (3 , 2 ); err != nil {
71+ t .Errorf ("Remove threw an error: %v" , err )
72+ }
73+
74+ if result := sb .ToString (); result != "Hel" {
75+ t .Errorf ("Actual %q, Expected: %q" , result , "Hel" )
76+ }
77+ }
78+
79+ func TestRemoveWhenStartIndexOutOfBounds (t * testing.T ) {
80+ sb := NewFromString ("Hello" )
81+
82+ if err := sb .Remove (100 , 1 ); err == nil {
83+ t .Error ("Should throw error but did not" )
84+ }
85+ }
86+
87+ func TestRemoveWhenStartIndexNegative (t * testing.T ) {
88+ sb := NewFromString ("Hello" )
89+
90+ if err := sb .Remove (- 1 , 1 ); err == nil {
91+ t .Error ("Should throw error but did not" )
92+ }
93+ }
94+
95+ func TestRemoveWhenLengthNegative (t * testing.T ) {
96+ sb := NewFromString ("Hello" )
97+
98+ if err := sb .Remove (1 , - 1 ); err == nil {
99+ t .Error ("Should throw error but did not" )
100+ }
101+ }
102+
103+ func TestRemoveWhenEndIndexOutOfBounds (t * testing.T ) {
104+ sb := NewFromString ("Hello" )
105+
106+ if err := sb .Remove (4 , 4 ); err == nil {
107+ t .Error ("Should throw error but did not" )
108+ }
109+ }
0 commit comments