Skip to content
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

Simplify test-lexer.cpp: #39

Merged
merged 83 commits into from
Oct 1, 2024

Conversation

SharafMohamed
Copy link
Contributor

@SharafMohamed SharafMohamed commented Sep 13, 2024

  • Use more using declarations.
  • Use a different Schema object per test.
  • Prettify complex test strings.

References

  • PR depends on PR#38.

Description

  • Use using to condense code.
  • Use a different Schema object in each test to make it clear there is no interaction b/w the tests.
  • Indent long strings to make it clear which brackets match.

Validation performed

  • Examples and unit-tests run successfully.

SharafMohamed and others added 30 commits September 11, 2024 20:07
… tag to matching_variable_id; Use full names for vars (r->rule); Clarify if states are NFA or DFA
…for clairty that nothing is shared b/w tests
…iteral arguments; Use const& for non-literals; Use auto where possible; Use uint32_t over int for ids; replace begin() and end() with cbegin() and cend()
coderabbitai[bot]

This comment was marked as off-topic.

@SharafMohamed SharafMohamed marked this pull request as draft September 26, 2024 17:11
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@y-scope y-scope deleted a comment from coderabbitai bot Sep 30, 2024
@SharafMohamed SharafMohamed marked this pull request as ready for review September 30, 2024 14:30
Copy link

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces modifications to the tests/test-lexer.cpp file, enhancing the structure and clarity of test cases for the Schema class. It includes necessary header files and using directives to simplify the code. The schema object is instantiated in each test case, and a new test for the serialization of a regex AST with named capture groups is added, validating the serialized output.

Changes

File Change Summary
tests/test-lexer.cpp Enhanced test structure, added necessary includes, instantiated schema in each test, and added a new test for regex AST serialization with named capture groups.

Possibly related PRs

Suggested reviewers

  • LinZhihao-723

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 98525ae and 5788431.

📒 Files selected for processing (1)
  • tests/test-lexer.cpp (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test-lexer.cpp

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SharafMohamed
Copy link
Contributor Author

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 30, 2024

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
tests/test-lexer.cpp (3)

Line range hint 1-3: LGTM! Consider using fully qualified names instead of using directives.

The addition of necessary includes and using directives improves code readability. However, in larger codebases, using directives might lead to name conflicts.

Consider using fully qualified names (e.g., std::string) instead of using directives to prevent potential name conflicts in the future.

Also applies to: 12-13


31-33: LGTM! Consider using REQUIRE_NOTHROW more effectively.

The changes improve test isolation and code clarity. The use of a new Schema object and a const variable for the name are good practices.

Consider modifying the REQUIRE_NOTHROW statement to directly check the type:

REQUIRE_NOTHROW(dynamic_cast<RegexASTCatByte&>(*schema_var_ast.m_regex_ptr));

This change would make the test more concise and directly assert the expected type.

Also applies to: 40-41, 43-43


96-103: LGTM! Comprehensive test for complex regex serialization.

The new test case effectively validates the serialization of a complex regex AST with named capture groups. This addition improves the overall test coverage of the Schema class.

Consider breaking down the long regex pattern string for better readability:

schema.add_variable(
    "capture",
    "Z|("
    "A(?<letter>("
        "(?<letter1>(a)|(b))|"
        "(?<letter2>(c)|(d))"
    "))"
    "B(?<containerID>\\d+)"
    "C)",
    -1
);

This change would make the regex pattern easier to understand and maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c410af4 and 7da5bec.

📒 Files selected for processing (1)
  • tests/test-lexer.cpp (4 hunks)
🔇 Additional comments (2)
tests/test-lexer.cpp (2)

25-26: LGTM! Improved readability.

The split of the RegexASTOrByte type alias across two lines with proper alignment enhances code readability.


47-47: LGTM! Improved test isolation and readability.

The creation of a new Schema object for this test case ensures proper isolation. The simplified dynamic cast improves code readability while maintaining the thorough testing of the AST structure.

Also applies to: 56-56

Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

lgtm!
For PR title, how about

Simplify test-lexer.cpp:
- Use more `using` declarations.
- Use a different `Schema` object per test.
- Prettify complex test strings.

Notice that the bullet points will be added to the PR description

@SharafMohamed SharafMohamed changed the title Refactor test-lexer.cpp. Simplify test-lexer.cpp: - Use more using declarations. - Use a different Schema object per test. - Prettify complex test strings. Sep 30, 2024
@LinZhihao-723 LinZhihao-723 changed the title Simplify test-lexer.cpp: - Use more using declarations. - Use a different Schema object per test. - Prettify complex test strings. Simplify test-lexer.cpp: - Use more using declarations. Sep 30, 2024
@LinZhihao-723 LinZhihao-723 changed the title Simplify test-lexer.cpp: - Use more using declarations. Simplify test-lexer.cpp: Sep 30, 2024
@LinZhihao-723 LinZhihao-723 merged commit a092206 into y-scope:main Oct 1, 2024
7 checks passed
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.

2 participants