@@ -368,29 +368,73 @@ fn remove_bad() {
368
368
369
369
#[ test]
370
370
fn test_remove_matches ( ) {
371
+ // test_single_pattern_occurrence
371
372
let mut s = "abc" . to_string ( ) ;
372
-
373
373
s. remove_matches ( 'b' ) ;
374
374
assert_eq ! ( s, "ac" ) ;
375
+ // repeat_test_single_pattern_occurrence
375
376
s. remove_matches ( 'b' ) ;
376
377
assert_eq ! ( s, "ac" ) ;
377
378
379
+ // test_single_character_pattern
378
380
let mut s = "abcb" . to_string ( ) ;
379
-
380
381
s. remove_matches ( 'b' ) ;
381
382
assert_eq ! ( s, "ac" ) ;
382
383
384
+ // test_pattern_with_special_characters
383
385
let mut s = "ศไทย中华Việt Nam; foobarศ" . to_string ( ) ;
384
386
s. remove_matches ( 'ศ' ) ;
385
387
assert_eq ! ( s, "ไทย中华Việt Nam; foobar" ) ;
386
388
389
+ // test_pattern_empty_text_and_pattern
387
390
let mut s = "" . to_string ( ) ;
388
391
s. remove_matches ( "" ) ;
389
392
assert_eq ! ( s, "" ) ;
390
393
394
+ // test_pattern_empty_text
395
+ let mut s = "" . to_string ( ) ;
396
+ s. remove_matches ( "something" ) ;
397
+ assert_eq ! ( s, "" ) ;
398
+
399
+ // test_empty_pattern
400
+ let mut s = "Testing with empty pattern." . to_string ( ) ;
401
+ s. remove_matches ( "" ) ;
402
+ assert_eq ! ( s, "Testing with empty pattern." ) ;
403
+
404
+ // test_multiple_consecutive_patterns_1
391
405
let mut s = "aaaaa" . to_string ( ) ;
392
406
s. remove_matches ( 'a' ) ;
393
407
assert_eq ! ( s, "" ) ;
408
+
409
+ // test_multiple_consecutive_patterns_2
410
+ let mut s = "Hello **world****today!**" . to_string ( ) ;
411
+ s. remove_matches ( "**" ) ;
412
+ assert_eq ! ( s, "Hello worldtoday!" ) ;
413
+
414
+ // test_case_insensitive_pattern
415
+ let mut s = "CASE ** SeNsItIvE ** PaTtErN." . to_string ( ) ;
416
+ s. remove_matches ( "sEnSiTiVe" ) ;
417
+ assert_eq ! ( s, "CASE ** SeNsItIvE ** PaTtErN." ) ;
418
+
419
+ // test_pattern_with_digits
420
+ let mut s = "123 ** 456 ** 789" . to_string ( ) ;
421
+ s. remove_matches ( "**" ) ;
422
+ assert_eq ! ( s, "123 456 789" ) ;
423
+
424
+ // test_pattern_occurs_after_empty_string
425
+ let mut s = "abc X defXghi" . to_string ( ) ;
426
+ s. remove_matches ( "X" ) ;
427
+ assert_eq ! ( s, "abc defghi" ) ;
428
+
429
+ // test_large_pattern
430
+ let mut s = "aaaXbbbXcccXdddXeee" . to_string ( ) ;
431
+ s. remove_matches ( "X" ) ;
432
+ assert_eq ! ( s, "aaabbbcccdddeee" ) ;
433
+
434
+ // test_pattern_at_multiple_positions
435
+ let mut s = "Pattern ** found ** multiple ** times ** in ** text." . to_string ( ) ;
436
+ s. remove_matches ( "**" ) ;
437
+ assert_eq ! ( s, "Pattern found multiple times in text." ) ;
394
438
}
395
439
396
440
#[ test]
0 commit comments