@@ -150,6 +150,155 @@ public function testWhenContainsAll()
150
150
}));
151
151
}
152
152
153
+ public function testWhenEndsWith ()
154
+ {
155
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('tony stark ' )->whenEndsWith ('ark ' , function ($ stringable ) {
156
+ return $ stringable ->title ();
157
+ }, function ($ stringable ) {
158
+ return $ stringable ->studly ();
159
+ }));
160
+
161
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('tony stark ' )->whenEndsWith (['kra ' , 'ark ' ], function ($ stringable ) {
162
+ return $ stringable ->title ();
163
+ }, function ($ stringable ) {
164
+ return $ stringable ->studly ();
165
+ }));
166
+
167
+ $ this ->assertSame ('tony stark ' , (string ) $ this ->stringable ('tony stark ' )->whenEndsWith (['xxx ' ], function ($ stringable ) {
168
+ return $ stringable ->title ();
169
+ }));
170
+
171
+ $ this ->assertSame ('TonyStark ' , (string ) $ this ->stringable ('tony stark ' )->whenEndsWith (['tony ' , 'xxx ' ], function ($ stringable ) {
172
+ return $ stringable ->title ();
173
+ }, function ($ stringable ) {
174
+ return $ stringable ->studly ();
175
+ }));
176
+ }
177
+
178
+ public function testWhenExactly ()
179
+ {
180
+ $ this ->assertSame ('Nailed it...! ' , (string ) $ this ->stringable ('Tony Stark ' )->whenExactly ('Tony Stark ' , function ($ stringable ) {
181
+ return 'Nailed it...! ' ;
182
+ }, function ($ stringable ) {
183
+ return 'Swing and a miss...! ' ;
184
+ }));
185
+
186
+ $ this ->assertSame ('Swing and a miss...! ' , (string ) $ this ->stringable ('Tony Stark ' )->whenExactly ('Iron Man ' , function ($ stringable ) {
187
+ return 'Nailed it...! ' ;
188
+ }, function ($ stringable ) {
189
+ return 'Swing and a miss...! ' ;
190
+ }));
191
+
192
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('Tony Stark ' )->whenExactly ('Iron Man ' , function ($ stringable ) {
193
+ return 'Nailed it...! ' ;
194
+ }));
195
+ }
196
+
197
+ public function testWhenIs ()
198
+ {
199
+ $ this ->assertSame ('Winner: / ' , (string ) $ this ->stringable ('/ ' )->whenIs ('/ ' , function ($ stringable ) {
200
+ return $ stringable ->prepend ('Winner: ' );
201
+ }, function ($ stringable ) {
202
+ return 'Try again ' ;
203
+ }));
204
+
205
+ $ this ->assertSame ('/ ' , (string ) $ this ->stringable ('/ ' )->whenIs (' / ' , function ($ stringable ) {
206
+ return $ stringable ->prepend ('Winner: ' );
207
+ }));
208
+
209
+ $ this ->assertSame ('Try again ' , (string ) $ this ->stringable ('/ ' )->whenIs (' / ' , function ($ stringable ) {
210
+ return $ stringable ->prepend ('Winner: ' );
211
+ }, function ($ stringable ) {
212
+ return 'Try again ' ;
213
+ }));
214
+
215
+ $ this ->assertSame ('Winner: foo/bar/baz ' , (string ) $ this ->stringable ('foo/bar/baz ' )->whenIs ('foo/* ' , function ($ stringable ) {
216
+ return $ stringable ->prepend ('Winner: ' );
217
+ }));
218
+ }
219
+
220
+ public function testWhenIsAscii ()
221
+ {
222
+ $ this ->assertSame ('Ascii: A ' , (string ) $ this ->stringable ('A ' )->whenIsAscii (function ($ stringable ) {
223
+ return $ stringable ->prepend ('Ascii: ' );
224
+ }, function ($ stringable ) {
225
+ return $ stringable ->prepend ('Not Ascii: ' );
226
+ }));
227
+
228
+ $ this ->assertSame ('ù ' , (string ) $ this ->stringable ('ù ' )->whenIsAscii (function ($ stringable ) {
229
+ return $ stringable ->prepend ('Ascii: ' );
230
+ }));
231
+
232
+ $ this ->assertSame ('Not Ascii: ù ' , (string ) $ this ->stringable ('ù ' )->whenIsAscii (function ($ stringable ) {
233
+ return $ stringable ->prepend ('Ascii: ' );
234
+ }, function ($ stringable ) {
235
+ return $ stringable ->prepend ('Not Ascii: ' );
236
+ }));
237
+ }
238
+
239
+ public function testWhenIsUuid ()
240
+ {
241
+ $ this ->assertSame ('Uuid: 2cdc7039-65a6-4ac7-8e5d-d554a98e7b15 ' , (string ) $ this ->stringable ('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15 ' )->whenIsUuid (function ($ stringable ) {
242
+ return $ stringable ->prepend ('Uuid: ' );
243
+ }, function ($ stringable ) {
244
+ return $ stringable ->prepend ('Not Uuid: ' );
245
+ }));
246
+
247
+ $ this ->assertSame ('2cdc7039-65a6-4ac7-8e5d-d554a98 ' , (string ) $ this ->stringable ('2cdc7039-65a6-4ac7-8e5d-d554a98 ' )->whenIsUuid (function ($ stringable ) {
248
+ return $ stringable ->prepend ('Uuid: ' );
249
+ }));
250
+
251
+ $ this ->assertSame ('Not Uuid: 2cdc7039-65a6-4ac7-8e5d-d554a98 ' , (string ) $ this ->stringable ('2cdc7039-65a6-4ac7-8e5d-d554a98 ' )->whenIsUuid (function ($ stringable ) {
252
+ return $ stringable ->prepend ('Uuid: ' );
253
+ }, function ($ stringable ) {
254
+ return $ stringable ->prepend ('Not Uuid: ' );
255
+ }));
256
+ }
257
+
258
+ public function testWhenTest ()
259
+ {
260
+ $ this ->assertSame ('Winner: foo bar ' , (string ) $ this ->stringable ('foo bar ' )->whenTest ('/bar/ ' , function ($ stringable ) {
261
+ return $ stringable ->prepend ('Winner: ' );
262
+ }, function ($ stringable ) {
263
+ return 'Try again ' ;
264
+ }));
265
+
266
+ $ this ->assertSame ('Try again ' , (string ) $ this ->stringable ('foo bar ' )->whenTest ('/link/ ' , function ($ stringable ) {
267
+ return $ stringable ->prepend ('Winner: ' );
268
+ }, function ($ stringable ) {
269
+ return 'Try again ' ;
270
+ }));
271
+
272
+ $ this ->assertSame ('foo bar ' , (string ) $ this ->stringable ('foo bar ' )->whenTest ('/link/ ' , function ($ stringable ) {
273
+ return $ stringable ->prepend ('Winner: ' );
274
+ }));
275
+ }
276
+
277
+ public function testWhenStartsWith ()
278
+ {
279
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('tony stark ' )->whenStartsWith ('ton ' , function ($ stringable ) {
280
+ return $ stringable ->title ();
281
+ }, function ($ stringable ) {
282
+ return $ stringable ->studly ();
283
+ }));
284
+
285
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('tony stark ' )->whenStartsWith (['ton ' , 'not ' ], function ($ stringable ) {
286
+ return $ stringable ->title ();
287
+ }, function ($ stringable ) {
288
+ return $ stringable ->studly ();
289
+ }));
290
+
291
+ $ this ->assertSame ('tony stark ' , (string ) $ this ->stringable ('tony stark ' )->whenStartsWith (['xxx ' ], function ($ stringable ) {
292
+ return $ stringable ->title ();
293
+ }));
294
+
295
+ $ this ->assertSame ('Tony Stark ' , (string ) $ this ->stringable ('tony stark ' )->whenStartsWith (['tony ' , 'xxx ' ], function ($ stringable ) {
296
+ return $ stringable ->title ();
297
+ }, function ($ stringable ) {
298
+ return $ stringable ->studly ();
299
+ }));
300
+ }
301
+
153
302
public function testWhenEmpty ()
154
303
{
155
304
tap ($ this ->stringable (), function ($ stringable ) {
0 commit comments