@@ -119,8 +119,10 @@ public function test_str_after(): void
119119 $ this ->assertTrue (str ('hannah ' )->after ('xxxx ' )->equals ('hannah ' ));
120120 $ this ->assertTrue (str ('hannah ' )->after ('' )->equals ('hannah ' ));
121121 $ this ->assertTrue (str ('han0nah ' )->after ('0 ' )->equals ('nah ' ));
122- $ this ->assertTrue (str ('han0nah ' )->after (0 )->equals ('nah ' ));
123- $ this ->assertTrue (str ('han2nah ' )->after (2 )->equals ('nah ' ));
122+ $ this ->assertTrue (str ('han2nah ' )->after ('2 ' )->equals ('nah ' ));
123+ $ this ->
assertTrue (
str (
'@[email protected] ' )->
after ([
'@ ' ,
'. ' ])->
equals (
'[email protected] ' ));
124+ $ this ->
assertTrue (
str (
'[email protected] ' )->
after ([
'@ ' ,
'. ' ])->
equals (
'bar.com ' ));
125+ $ this ->assertTrue (str ('foobar.com ' )->after (['@ ' , '. ' ])->equals ('com ' ));
124126 }
125127
126128 public function test_str_after_last (): void
@@ -132,9 +134,9 @@ public function test_str_after_last(): void
132134 $ this ->assertTrue (str ('yvette ' )->afterLast ('xxxx ' )->equals ('yvette ' ));
133135 $ this ->assertTrue (str ('yvette ' )->afterLast ('' )->equals ('yvette ' ));
134136 $ this ->assertTrue (str ('yv0et0te ' )->afterLast ('0 ' )->equals ('te ' ));
135- $ this ->assertTrue (str ('yv0et0te ' )->afterLast (0 )->equals ('te ' ));
136- $ this ->assertTrue (str ('yv2et2te ' )->afterLast (2 )->equals ('te ' ));
137+ $ this ->assertTrue (str ('yv2et2te ' )->afterLast ('2 ' )->equals ('te ' ));
137138 $ this ->assertTrue (str ('----foo ' )->afterLast ('--- ' )->equals ('foo ' ));
139+ $ this ->
assertTrue (
str (
'@[email protected] ' )->
afterLast ([
'@ ' ,
'. ' ])->
equals (
'com ' ));
138140 }
139141
140142 public function test_str_between (): void
@@ -150,7 +152,7 @@ public function test_str_between(): void
150152 $ this ->assertTrue (str ('[a]ab[b] ' )->between ('[ ' , '] ' )->equals ('a]ab[b ' ));
151153 $ this ->assertTrue (str ('foofoobar ' )->between ('foo ' , 'bar ' )->equals ('foo ' ));
152154 $ this ->assertTrue (str ('foobarbar ' )->between ('foo ' , 'bar ' )->equals ('bar ' ));
153- $ this ->assertTrue (str ('12345 ' )->between (1 , 5 )->equals ('234 ' ));
155+ $ this ->assertTrue (str ('12345 ' )->between (' 1 ' , ' 5 ' )->equals ('234 ' ));
154156 $ this ->assertTrue (str ('123456789 ' )->between ('123 ' , '6789 ' )->equals ('45 ' ));
155157 $ this ->assertTrue (str ('nothing ' )->between ('foo ' , 'bar ' )->equals ('nothing ' ));
156158 }
@@ -163,14 +165,15 @@ public function test_str_before(): void
163165 $ this ->assertTrue (str ('hannah ' )->before ('xxxx ' )->equals ('hannah ' ));
164166 $ this ->assertTrue (str ('hannah ' )->before ('' )->equals ('hannah ' ));
165167 $ this ->assertTrue (str ('han0nah ' )->before ('0 ' )->equals ('han ' ));
166- $ this ->assertTrue (str ('han0nah ' )->before (0 )->equals ('han ' ));
167- $ this ->assertTrue (str ('han2nah ' )->before (2 )->equals ('han ' ));
168+ $ this ->assertTrue (str ('han2nah ' )->before ('2 ' )->equals ('han ' ));
168169 $ this ->assertTrue (str ('' )->before ('' )->equals ('' ));
169170 $ this ->assertTrue (str ('' )->before ('a ' )->equals ('' ));
170171 $ this ->assertTrue (str ('a ' )->before ('a ' )->equals ('' ));
171172 $ this ->
assertTrue (
str (
'[email protected] ' )->
before (
'@ ' )->
equals (
'foo ' ));
172173 $ this ->assertTrue (str ('foo@@bar.com ' )->before ('@ ' )->equals ('foo ' ));
173174 $ this ->
assertTrue (
str (
'@[email protected] ' )->
before (
'@ ' )->
equals (
'' ));
175+ $ this ->
assertTrue (
str (
'[email protected] ' )->
before ([
'@ ' ,
'. ' ])->
equals (
'foo ' ));
176+ $ this ->
assertTrue (
str (
'@[email protected] ' )->
before ([
'@ ' ,
'. ' ])->
equals (
'' ));
174177 }
175178
176179 public function test_str_before_last (): void
@@ -182,12 +185,13 @@ public function test_str_before_last(): void
182185 $ this ->assertTrue (str ('yvette ' )->beforeLast ('xxxx ' )->equals ('yvette ' ));
183186 $ this ->assertTrue (str ('yvette ' )->beforeLast ('' )->equals ('yvette ' ));
184187 $ this ->assertTrue (str ('yv0et0te ' )->beforeLast ('0 ' )->equals ('yv0et ' ));
185- $ this ->assertTrue (str ('yv0et0te ' )->beforeLast (0 )->equals ('yv0et ' ));
186- $ this ->assertTrue (str ('yv2et2te ' )->beforeLast (2 )->equals ('yv2et ' ));
188+ $ this ->assertTrue (str ('yv2et2te ' )->beforeLast ('2 ' )->equals ('yv2et ' ));
187189 $ this ->assertTrue (str ('' )->beforeLast ('test ' )->equals ('' ));
188190 $ this ->assertTrue (str ('yvette ' )->beforeLast ('yvette ' )->equals ('' ));
189191 $ this ->assertTrue (str ('tempest framework ' )->beforeLast (' ' )->equals ('tempest ' ));
190192 $ this ->assertTrue (str ("yvette \tyv0et0te " )->beforeLast ("\t" )->equals ('yvette ' ));
193+ $ this ->assertTrue (str ('This is Tempest. ' )->beforeLast ([' ' , '. ' ])->equals ('This is Tempest ' ));
194+ $ this ->assertTrue (str ('This is Tempest ' )->beforeLast ([' ' , '. ' ])->equals ('This is ' ));
191195 }
192196
193197 public function test_starts_with (): void
@@ -201,4 +205,59 @@ public function test_ends_with(): void
201205 $ this ->assertTrue (str ('abc ' )->endsWith ('c ' ));
202206 $ this ->assertFalse (str ('abc ' )->endsWith ('a ' ));
203207 }
208+
209+ public function test_replace (): void
210+ {
211+ $ this ->assertTrue (str ('foo bar ' )->replace ('bar ' , 'baz ' )->equals ('foo baz ' ));
212+ $ this ->assertTrue (str ('jon doe ' )->replace (['jon ' , 'jane ' ], 'luke ' )->equals ('luke doe ' ));
213+ $ this ->assertTrue (str ('jon doe ' )->replace (['jon ' , 'jane ' , 'doe ' ], ['Jon ' , 'Jane ' , 'Doe ' ])->equals ('Jon Doe ' ));
214+ $ this ->assertTrue (str ('jon doe ' )->replace (['jon ' , 'jane ' , 'doe ' ], '<censored> ' )->equals ('<censored> <censored> ' ));
215+ }
216+
217+ public function test_replace_last (): void
218+ {
219+ $ this ->assertTrue (str ('foobar foobar ' )->replaceLast ('bar ' , 'qux ' )->equals ('foobar fooqux ' ));
220+ $ this ->assertTrue (str ('foo/bar? foo/bar? ' )->replaceLast ('bar? ' , 'qux? ' )->equals ('foo/bar? foo/qux? ' ));
221+ $ this ->assertTrue (str ('foobar foobar ' )->replaceLast ('bar ' , '' )->equals ('foobar foo ' ));
222+ $ this ->assertTrue (str ('foobar foobar ' )->replaceLast ('xxx ' , 'yyy ' )->equals ('foobar foobar ' ));
223+ $ this ->assertTrue (str ('foobar foobar ' )->replaceLast ('' , 'yyy ' )->equals ('foobar foobar ' ));
224+ $ this ->assertTrue (str ('Malmö Jönköping ' )->replaceLast ('ö ' , 'xxx ' )->equals ('Malmö Jönkxxxping ' ));
225+ $ this ->assertTrue (str ('Malmö Jönköping ' )->replaceLast ('' , 'yyy ' )->equals ('Malmö Jönköping ' ));
226+ }
227+
228+ public function test_replace_first (): void
229+ {
230+ $ this ->assertTrue (str ('foobar foobar ' )->replaceFirst ('bar ' , 'qux ' )->equals ('fooqux foobar ' ));
231+ $ this ->assertTrue (str ('foo/bar? foo/bar? ' )->replaceFirst ('bar? ' , 'qux? ' )->equals ('foo/qux? foo/bar? ' ));
232+ $ this ->assertTrue (str ('foobar foobar ' )->replaceFirst ('bar ' , '' )->equals ('foo foobar ' ));
233+ $ this ->assertTrue (str ('foobar foobar ' )->replaceFirst ('xxx ' , 'yyy ' )->equals ('foobar foobar ' ));
234+ $ this ->assertTrue (str ('foobar foobar ' )->replaceFirst ('' , 'yyy ' )->equals ('foobar foobar ' ));
235+ $ this ->assertTrue (str ('Jönköping Malmö ' )->replaceFirst ('ö ' , 'xxx ' )->equals ('Jxxxnköping Malmö ' ));
236+ $ this ->assertTrue (str ('Jönköping Malmö ' )->replaceFirst ('' , 'yyy ' )->equals ('Jönköping Malmö ' ));
237+
238+ }
239+
240+ public function test_replace_end (): void
241+ {
242+ $ this ->assertTrue (str ('foobar fooqux ' )->replaceEnd ('bar ' , 'qux ' )->equals ('foobar fooqux ' ));
243+ $ this ->assertTrue (str ('foo/bar? foo/qux? ' )->replaceEnd ('bar? ' , 'qux? ' )->equals ('foo/bar? foo/qux? ' ));
244+ $ this ->assertTrue (str ('foobar foo ' )->replaceEnd ('bar ' , '' )->equals ('foobar foo ' ));
245+ $ this ->assertTrue (str ('foobar foobar ' )->replaceEnd ('xxx ' , 'yyy ' )->equals ('foobar foobar ' ));
246+ $ this ->assertTrue (str ('foobar foobar ' )->replaceEnd ('' , 'yyy ' )->equals ('foobar foobar ' ));
247+ $ this ->assertTrue (str ('fooxxx foobar ' )->replaceEnd ('xxx ' , 'yyy ' )->equals ('fooxxx foobar ' ));
248+ $ this ->assertTrue (str ('Malmö Jönköping ' )->replaceEnd ('ö ' , 'xxx ' )->equals ('Malmö Jönköping ' ));
249+ $ this ->assertTrue (str ('Malmö Jönköping ' )->replaceEnd ('öping ' , 'yyy ' )->equals ('Malmö Jönkyyy ' ));
250+ }
251+
252+ public function test_append (): void
253+ {
254+ $ this ->assertTrue (str ('foo ' )->append ('bar ' )->equals ('foobar ' ));
255+ $ this ->assertTrue (str ('foo ' )->append ('bar ' , 'baz ' )->equals ('foobarbaz ' ));
256+ }
257+
258+ public function test_prepend (): void
259+ {
260+ $ this ->assertTrue (str ('bar ' )->prepend ('foo ' )->equals ('foobar ' ));
261+ $ this ->assertTrue (str ('baz ' )->prepend ('bar ' , 'foo ' )->equals ('barfoobaz ' ));
262+ }
204263}
0 commit comments