Skip to content

fix(string): split and then join should be identity #2020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peter-jerry-ye
Copy link
Collaborator

Fixes #2019

Copy link

peter-jerry-ye-code-review bot commented Apr 28, 2025

Simplified split logic removes edge case handling for empty views

Category
Correctness
Code Snippet
string/methods.mbt:664-670

  • if view.is_empty() {
  • IterContinue
  • } else {
  • yield_(view)
  • }
  • yield_(view)
    Recommendation
    The change is correct. Empty views should be included in split results for consistency.
    Reasoning
    The original code was inconsistent with common string splitting behavior. Including empty views makes the function behave more predictably, especially for cases with trailing separators or empty input strings.
Test cases should be grouped by behavior type

Category
Maintainability
Code Snippet
string/string_test.mbt:424-430, 512-518 (duplicated test blocks)
Recommendation
Consolidate duplicate test blocks and group related test cases together:

test "split empty string behavior" {
  inspect!("".split(""), content="[]")
  inspect!("".split("x"), content=#|[""])
}

Reasoning
The test file contains identical test blocks. Grouping related test cases improves readability and makes the test intentions clearer.

New split/join identity test improves behavior documentation

Category
Maintainability
Code Snippet
string/string_test.mbt:740-758
Recommendation
Add more test cases with other common separators (e.g., newlines, tabs) and document the expected invariant:

///| Split and join operations should preserve the original string
///| for any valid separator.
test "split and join should be identity" {
**Reasoning**
The new test suite is valuable as it documents an important invariant of the split/join operations. Adding more test cases and documentation would make the expected behavior even clearer.

</details>

@coveralls
Copy link
Collaborator

coveralls commented Apr 28, 2025

Pull Request Test Coverage Report for Build 6526

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 92.734%

Totals Coverage Status
Change from base Build 6521: -0.002%
Covered Lines: 6126
Relevant Lines: 6606

💛 - Coveralls

@tonyfettes tonyfettes force-pushed the zihang/fix-string-split branch from a75fb52 to 469a6d9 Compare April 29, 2025 09:29
Copy link
Contributor

@tonyfettes tonyfettes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String::split has inconsistent behavior w.r.t. Python and JavaScript
3 participants