8000 internal: use md parser to extract test from .mbt.md by Young-Flash · Pull Request #817 · moonbitlang/moon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

internal: use md parser to extract test from .mbt.md #817

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

Merged
merged 2 commits into from
May 20, 2025
Merged

Conversation

Young-Flash
Copy link
Collaborator

No description provided.

Copy link
peter-jerry-ye-code-review bot commented May 20, 2025
Redundant default constructor pattern

Category
Maintainability
Code Snippet
pub struct DocTestExtractor {}

impl DocTestExtractor {
pub fn new(is_md_test: bool) -> Self { ... }
Recommendation
Since DocTestExtractor no longer needs any fields, consider making the extraction methods static or using a pure function approach
Reasoning
The empty struct with Default implementation adds unnecessary boilerplate. The functionality could be simplified by making the methods static or using pure functions since there's no state to maintain.

Multiple string allocations in Markdown code block extraction

Category
Performance
Code Snippet
current_code.push_str(&current_indent);
current_code.push_str(&text);
Recommendation
Pre-allocate the string buffer and/or use a string builder pattern for better performance
Reasoning
Multiple string concatenations in a loop can lead to repeated memory allocations. Pre-allocating or using a string builder pattern would be more efficient for larger documents.

Potential line counting error in Markdown code blocks

Category
Correctness
Code Snippet
let current_line = content[..range.start].chars().filter(|c| *c == '\n').count() + 1
Recommendation
Consider using a more robust line counting mechanism that handles all line ending types (\r\n, \n)
Reasoning
The current line counting implementation might not correctly handle different line endings, especially in Windows environments. This could lead to incorrect line numbers in error messages.

@Young-Flash Young-Flash enabled auto-merge (squash) May 20, 2025 07:09
@Young-Flash Young-Flash merged commit fad2523 into main May 20, 2025
13 checks passed
@Young-Flash Young-Flash deleted the use_md_parser branch May 20, 2025 07:15
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