Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #114111 - allaboutevemirolive:add-test-case-string, r…
…=Mark-Simulacrum Improve test case for experimental API remove_matches ## Add Test Cases for `remove_matches` Function ### Motivation After reading the discussion in [this GitHub thread](#71780), I'm trying to redesign the current API to use less memory when working with `String` and to make it simpler. I've discovered that some test cases are very helpful in ensuring that the new API behaves as intended. I'm still in the process of redesigning the current API, and these test cases have proven to be very useful. ### Testing The current test has been tested with the command `./x test --stage 0 library/alloc`. ### Overview This pull request adds several new test cases for the `remove_matches` function to make sure it works correctly in different situations. The `remove_matches` function is used to get rid of all instances of a specific pattern from a given text. These test cases thoroughly check how the function behaves in various scenarios. ### Test Cases 1. **Single Pattern Occurrence** (`test_single_pattern_occurrence`): - Description: Tests the removal of a single pattern occurrence from the text. - Input: Text: "abc", Pattern: 'b' - Expected Output: "ac" 2. **Repeat Test Single Pattern Occurrence** (`repeat_test_single_pattern_occurrence`): - Description: Repeats the previous test case to ensure consecutive removal of the same pattern. - Input: Text: "ac", Pattern: 'b' - Expected Output: "ac" 3. **Single Character Pattern** (`test_single_character_pattern`): - Description: Tests the removal of a single character pattern. - Input: Text: "abcb", Pattern: 'b' - Expected Output: "ac" 4. **Pattern with Special Characters** (`test_pattern_with_special_characters`): - Description: Tests the removal of a pattern containing special characters. - Input: Text: "ศไทย中华Việt Nam; foobarศ", Pattern: 'ศ' - Expected Output: "ไทย中华Việt Nam; foobar" 5. **Pattern Empty Text and Pattern** (`test_pattern_empty_text_and_pattern`): - Description: Tests the removal of an empty pattern from an empty text. - Input: Text: "", Pattern: "" - Expected Output: "" 6. **Pattern Empty Text** (`test_pattern_empty_text`): - Description: Tests the removal of a pattern from an empty text. - Input: Text: "", Pattern: "something" - Expected Output: "" 7. **Empty Pattern** (`test_empty_pattern`): - Description: Tests the behavior of removing an empty pattern from the text. - Input: Text: "Testing with empty pattern.", Pattern: "" - Expected Output: "Testing with empty pattern." 8. **Multiple Consecutive Patterns 1** (`test_multiple_consecutive_patterns_1`): - Description: Tests the removal of multiple consecutive occurrences of a pattern. - Input: Text: "aaaaa", Pattern: 'a' - Expected Output: "" 9. **Multiple Consecutive Patterns 2** (`test_multiple_consecutive_patterns_2`): - Description: Tests the removal of a longer pattern that occurs consecutively. - Input: Text: "Hello **world****today!**", Pattern: "**" - Expected Output: "Hello worldtoday!" 10. **Case Insensitive Pattern** (`test_case_insensitive_pattern`): - Description: Tests the removal of a case-insensitive pattern from the text. - Input: Text: "CASE ** SeNsItIvE ** PaTtErN.", Pattern: "sEnSiTiVe" - Expected Output: "CASE ** SeNsItIvE ** PaTtErN."
- Loading branch information