Skip to content

Commit adb36cb

Browse files
Improve test case for experimental API remove_matches in library/alloc/tests/string.rs
1 parent fb7e6d0 commit adb36cb

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

Diff for: library/alloc/tests/string.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -368,29 +368,73 @@ fn remove_bad() {
368368

369369
#[test]
370370
fn test_remove_matches() {
371+
// test_single_pattern_occurrence
371372
let mut s = "abc".to_string();
372-
373373
s.remove_matches('b');
374374
assert_eq!(s, "ac");
375+
// repeat_test_single_pattern_occurrence
375376
s.remove_matches('b');
376377
assert_eq!(s, "ac");
377378

379+
// test_single_character_pattern
378380
let mut s = "abcb".to_string();
379-
380381
s.remove_matches('b');
381382
assert_eq!(s, "ac");
382383

384+
// test_pattern_with_special_characters
383385
let mut s = "ศไทย中华Việt Nam; foobarศ".to_string();
384386
s.remove_matches('ศ');
385387
assert_eq!(s, "ไทย中华Việt Nam; foobar");
386388

389+
// test_pattern_empty_text_and_pattern
387390
let mut s = "".to_string();
388391
s.remove_matches("");
389392
assert_eq!(s, "");
390393

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
391405
let mut s = "aaaaa".to_string();
392406
s.remove_matches('a');
393407
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.");
394438
}
395439

396440
#[test]

0 commit comments

Comments
 (0)