8000 hongbo/test bytes using regex by bobzhang · Pull Request #2418 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hongbo/test bytes using regex #2418

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 2 commits into
base: main
Choose a base branch
from
Open

Conversation

bobzhang
Copy link
Contributor
@bobzhang bobzhang commented Jul 7, 2025
  • test: Add regex matching test for string pattern
  • fix(regex): update regex match syntax for clarity and correctness

Copy link
Potential syntax error in regex pattern matching

Category
Correctness
Code Snippet
match "hell123o" using regex {
["hell[0-9]+" as x, .. rest] => {
guard x is "hell123" && rest is "o" else { fail("Regex match failed") }
}
Recommendation
Verify the regex syntax is correct for MoonBit. Consider using a more standard regex pattern syntax like /hell[0-9]+/ or ensure the string literal regex format is properly supported by the language
Reasoning
The regex pattern syntax using string literals in array-like destructuring is unusual and may not be valid. Most languages use delimited regex patterns or dedicated regex constructors.

Inconsistent formatting style with existing codebase

Category
Maintainability
Code Snippet
content=(
#|b"\xe4\xbd\xa0\xe5\xa5\xbd\x75\x74\x66\x38\xe4\xbd\xa0\xe5\xa5\xbd"
),
Recommendation
Keep the original formatting style without parentheses around content parameter to maintain consistency with the existing codebase pattern
Reasoning
The changes add parentheses around multiline content parameters, but this creates inconsistency if other parts of the codebase use the original format. Style changes should be applied consistently across the entire codebase.

Missing error handling for regex compilation

Category
Correctness
Code Snippet
test "using regex" {
match "hell123o" using regex {
["hell[0-9]+" as x, .. rest] => {
Recommendation
Add error handling for potential regex compilation failures and consider testing edge cases like invalid patterns or non-matching strings
Reasoning
The test doesn't handle cases where the regex might fail to compile or match. Robust regex tests should cover both positive and negative cases.

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.

1 participant
0