Skip to content

Add tests for postfix expression variants#137

Open
leynos wants to merge 9 commits into
mainfrom
codex/add-tests-for-new-expr-variants
Open

Add tests for postfix expression variants#137
leynos wants to merge 9 commits into
mainfrom
codex/add-tests-for-new-expr-variants

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Sep 5, 2025

Summary

  • add integration tests for method calls, field accesses, bit slices and tuple indexes
  • cover postfix expression parsing errors in unit tests

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_68bb2bea809883228cc487aaf5723eec

Summary by Sourcery

Add comprehensive unit and integration tests for postfix expression variants to improve parsing coverage and error reporting.

Tests:

  • Add unit tests for parsing method calls, field accesses, bit slices, and tuple indexing in expressions.
  • Add unit tests to verify error reporting and delimiter handling for various malformed postfix expressions.
  • Add integration tests in a new file to cover postfix expression parsing through the public API and error scenarios.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 5, 2025

Reviewer's Guide

Introduces comprehensive unit and integration tests for postfix expression parsing, adding new rstest cases in the parser tests and a dedicated integration test file to cover method calls, field accesses, bit slices, tuple indexing, and related error scenarios.

File-Level Changes

Change Details Files
Add postfix expression unit tests
  • Introduce parses_postfix_expressions rstest covering method calls, field accesses, bit slices, and tuple indexes
  • Add postfix_expression_errors rstest covering missing tokens, delimiter errors, and invalid expressions
src/parser/tests/expression.rs
Create integration tests for postfix expressions
  • Add new tests/expression_postfix.rs with rstest cases using public parse_expression API
  • Cover parsing success for various postfix variants and corresponding error assertions
tests/expression_postfix.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 5, 2025

Summary by CodeRabbit

  • New Features

    • None.
  • Bug Fixes

    • None.
  • Tests

    • Added comprehensive tests for postfix expressions, including method calls, field access, bit slices, tuple indices, chaining, and error paths.
    • Expanded error coverage and clarified error categorisation (delimiter vs parse) across expression tests.
    • Standardised expected diagnostics to human-readable token names (e.g., “left/right paren”, “identifier”, “number”, “pipe”).
  • Chores

    • Improved test utilities to normalise token names in error messages, ensuring consistent and robust assertions.
    • Reorganised and named error cases for clearer test intent.

Walkthrough

Move postfix success cases into a new integration test file, add parameterised postfix error tests, normalise token names in test utilities, and expose two public test helpers (assert_delimiter_error, assert_parse_error). Update many tests to expect human-readable token labels instead of internal token identifiers.

Changes

Cohort / File(s) Summary of changes
Test utilities (public additions + normalisation)
src/test_util.rs
Add pub fn assert_delimiter_error(...) and pub fn assert_parse_error(...). Introduce normalise_tokens helper and update ErrorPattern::contains_message to normalise rendered and pattern messages to use human-readable token names.
Unit tests — reorganised postfix & additional error cases
src/parser/tests/expression.rs
Rework parses_expressions error cases into named scenarios and add postfix_expression_errors parameterised tests that call the public parse_expression API and assert delimiter vs parse errors (using the new helpers). Update imports to include the new test helpers.
New integration tests — postfix successes
tests/expression_postfix.rs
Add rstest-based integration tests that parse postfix forms via parse_expression and assert produced Expr ASTs: method_call, field_access, bit_slice, tuple_index, multi_arg_call, chained_postfix. Include an error-path test for an unclosed call.
Tests — token name expectations normalised
src/parser/tests/functions.rs, src/parser/tests/imports.rs, src/parser/tests/indexes.rs, src/parser/tests/relations.rs, tests/expression_compound.rs, tests/expression_entry.rs, tests/expression_prefix.rs, tests/expression_var_and_call.rs, tests/function_errors.rs, tests/function_errors.rs
Update many assertions to expect human-readable token labels (e.g., "left paren", "right paren", "identifier", "pipe", "number") instead of internal token codes like T_LPAREN, T_RPAREN, T_IDENT, etc. No parser logic changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Brackets, dots and commas sing,
Tests align to one clear string.
Helpers rise to flag the place,
Human names now mark the trace.
Parsers rest while errors bring the spring.

Prompt: Run the updated test suite; focus review on test-normalisation logic and the two new public test helpers. 
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-tests-for-new-expr-variants

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

sourcery-ai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@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: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between df227bc and a30a177.

📒 Files selected for processing (2)
  • src/parser/tests/expression.rs (2 hunks)
  • tests/expression_postfix.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Keep any single Rust source file under 400 lines; split long switches/dispatch tables and move large test data to external files
Disallow Clippy warnings; do not silence lints except as a last resort
Any lint suppressions must be tightly scoped and include a clear reason; prefer expect over allow
Fix warnings emitted during tests in code instead of silencing them
Extract helper functions when functions are too long; group parameters into structs when they are too many
If returning a large error, consider using Arc to reduce returned data
Write unit and behavioural tests for new functionality and run before/after changes
Prefer immutable data; avoid unnecessary mut bindings
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate functions for conditional criteria with more than two branches
Prefer .expect() over .unwrap()
Use concat!() for long string literals rather than escaping newlines with a backslash

Files:

  • tests/expression_postfix.rs
  • src/parser/tests/expression.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • tests/expression_postfix.rs
  • src/parser/tests/expression.rs
tests/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup and prefer #[rstest(...)] parameterised cases over duplicated tests
Prefer mockall for mocks/stubs

Files:

  • tests/expression_postfix.rs
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Every module must begin with a module-level //! comment explaining purpose and utility
Document public APIs with /// Rustdoc comments so cargo doc can generate docs

Files:

  • src/parser/tests/expression.rs
🔇 Additional comments (3)
src/parser/tests/expression.rs (1)

6-8: Imports wired correctly for new assertions and postfix builders.

The added helpers are used below and align with existing test utilities.

tests/expression_postfix.rs (2)

1-5: Good: module-level docs explain purpose and scope.


6-13: Imports are minimal and correctly scoped for integration tests.

Comment thread src/parser/tests/expression.rs Outdated
Comment thread tests/expression_postfix.rs
Comment thread tests/expression_postfix.rs
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Sep 7, 2025

@coderabbitai Have the following now been resolved?

  • There’s duplication of the same postfix tests in both the unit tests and the new integration file—consider consolidating or clearly separating them to avoid overlapping coverage.
  • Add a chained-postfix test (e.g., foo.bar().baz[1]) to verify the parser correctly handles multiple postfix operators in sequence.
  • Include a multi-argument method call case with more than one argument to ensure comma-separated argument lists are parsed correctly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos Let me check the current status of those three issues:

1. Duplication between unit tests and integration tests:
Looking at the test files, there is indeed some overlap. Both files test basic postfix expressions like method calls and field access, but they serve different purposes:

  • Unit tests in src/parser/tests/expression.rs focus on the parser internals
  • Integration tests in tests/expression_postfix.rs test via the public API

While there's some conceptual overlap, the tests use different approaches and APIs, so this isn't problematic duplication.

2. Chained-postfix test (e.g., foo.bar().baz[1]):
Not resolved - I don't see any tests for chained postfix operations in either file. The current tests only cover single postfix operations.

3. Multi-argument method call case:
Not resolved - The current method call test only uses single arguments: "foo.bar(x)" with vec![var("x")]. There are no tests with multiple arguments like foo.bar(x, y).

Status Summary:

  • ✅ Test organization is acceptable (not truly duplicated)
  • ❌ Chained postfix tests are missing
  • ❌ Multi-argument method call tests are missing

You still need to add tests for chained postfix expressions and multi-argument method calls to fully address the original feedback.

  (\   /)
 ( ._. )
o_(")(")

thinking hard about test coverage


🏁 Script executed:

#!/bin/bash
# First, let's examine the unit test file for postfix expressions
echo "=== Unit tests in src/parser/tests/expression.rs ==="
cat src/parser/tests/expression.rs | grep -A 50 -B 5 "postfix"

echo -e "\n=== Integration tests in tests/expression_postfix.rs ==="
cat tests/expression_postfix.rs

echo -e "\n=== Searching for chained postfix expressions ==="
rg -n "\..*\(" src/parser/tests/expression.rs tests/expression_postfix.rs || echo "No chained postfix expressions found"

echo -e "\n=== Searching for multi-argument method calls ==="
rg -n -C3 "\w+\.\w+\([^)]*,[^)]*\)" src/parser/tests/expression.rs tests/expression_postfix.rs || echo "No multi-argument method calls found"

echo -e "\n=== Looking for any method calls with multiple arguments in test expectations ==="
rg -n -C3 "method_call.*vec!\[.*,.*\]" src/parser/tests/expression.rs tests/expression_postfix.rs || echo "No multi-argument method call expectations found"

Length of output: 4498


@leynos I need to correct my previous assessment! Looking at the actual test files, all three issues have been resolved:

1. Duplication between unit tests and integration tests:
Resolved - There's actually no problematic duplication. The unit tests in src/parser/tests/expression.rs focus on error cases for postfix expressions, while the integration tests in tests/expression_postfix.rs focus on success cases. This is a proper separation of concerns.

2. Chained-postfix test:
Resolved - Line 17 in tests/expression_postfix.rs includes:

#[case("foo.bar().baz[1,0]", bit_slice(field_access(method_call(var("foo"), "bar", vec![]), "baz"), lit_num("1"), lit_num("0")))]

This tests foo.bar().baz[1,0] which chains a method call, field access, and bit slice.

3. Multi-argument method call:
Resolved - Line 16 in tests/expression_postfix.rs includes:

#[case("foo.bar(1, 2)", method_call(var("foo"), "bar", vec![lit_num("1"), lit_num("2")]))]

This tests a method call with two arguments.

All three issues have been successfully addressed in this PR!

  (\   /)
 ( ^.^ )
o_(")(")

happy with comprehensive test coverage

Copy link
Copy Markdown
Contributor

@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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a30a177 and 9b272e9.

📒 Files selected for processing (2)
  • src/parser/tests/expression.rs (2 hunks)
  • tests/expression_postfix.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Keep any single Rust source file under 400 lines; split long switches/dispatch tables and move large test data to external files
Disallow Clippy warnings; do not silence lints except as a last resort
Any lint suppressions must be tightly scoped and include a clear reason; prefer expect over allow
Fix warnings emitted during tests in code instead of silencing them
Extract helper functions when functions are too long; group parameters into structs when they are too many
If returning a large error, consider using Arc to reduce returned data
Write unit and behavioural tests for new functionality and run before/after changes
Prefer immutable data; avoid unnecessary mut bindings
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate functions for conditional criteria with more than two branches
Prefer .expect() over .unwrap()
Use concat!() for long string literals rather than escaping newlines with a backslash

Files:

  • tests/expression_postfix.rs
  • src/parser/tests/expression.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • tests/expression_postfix.rs
  • src/parser/tests/expression.rs
tests/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup and prefer #[rstest(...)] parameterised cases over duplicated tests
Prefer mockall for mocks/stubs

Files:

  • tests/expression_postfix.rs
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Every module must begin with a module-level //! comment explaining purpose and utility
Document public APIs with /// Rustdoc comments so cargo doc can generate docs

Files:

  • src/parser/tests/expression.rs
🧬 Code graph analysis (2)
tests/expression_postfix.rs (2)
src/parser/expression/pratt.rs (1)
  • parse_expression (29-47)
src/test_util.rs (6)
  • bit_slice (126-132)
  • field_access (107-113)
  • lit_num (50-52)
  • method_call (96-103)
  • tuple_index (117-122)
  • var (70-73)
src/parser/tests/expression.rs (2)
src/test_util.rs (2)
  • assert_delimiter_error (291-303)
  • assert_parse_error (206-221)
src/parser/expression/pratt.rs (1)
  • parse_expression (29-47)
🔇 Additional comments (4)
src/parser/tests/expression.rs (1)

6-8: Imports align with new error assertions; LGTM.

tests/expression_postfix.rs (3)

1-5: Good module-level docs; LGTM.


6-10: Imports match usage; LGTM.


18-21: Assertion style is clear; LGTM.

Comment thread src/parser/tests/expression.rs
Comment thread tests/expression_postfix.rs Outdated
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Startup script timed out after 1200 seconds
About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Repository owner deleted a comment from coderabbitai Bot Sep 7, 2025
codescene-delta-analysis[bot]

This comment was marked as outdated.

Repository owner deleted a comment from coderabbitai Bot Sep 7, 2025
Repository owner deleted a comment from chatgpt-codex-connector Bot Sep 7, 2025
Repository owner deleted a comment from coderabbitai Bot Sep 7, 2025
Repository owner deleted a comment from chatgpt-codex-connector Bot Sep 7, 2025
codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dce8aa and d3a8b15.

📒 Files selected for processing (1)
  • src/parser/tests/expression.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Keep any single Rust source file under 400 lines; split long switches/dispatch tables and move large test data to external files
Disallow Clippy warnings; do not silence lints except as a last resort
Any lint suppressions must be tightly scoped and include a clear reason; prefer expect over allow
Fix warnings emitted during tests in code instead of silencing them
Extract helper functions when functions are too long; group parameters into structs when they are too many
If returning a large error, consider using Arc to reduce returned data
Write unit and behavioural tests for new functionality and run before/after changes
Prefer immutable data; avoid unnecessary mut bindings
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate functions for conditional criteria with more than two branches
Prefer .expect() over .unwrap()
Use concat!() for long string literals rather than escaping newlines with a backslash

Files:

  • src/parser/tests/expression.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • src/parser/tests/expression.rs
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Every module must begin with a module-level //! comment explaining purpose and utility
Document public APIs with /// Rustdoc comments so cargo doc can generate docs

Files:

  • src/parser/tests/expression.rs
🧬 Code graph analysis (1)
src/parser/tests/expression.rs (2)
src/test_util.rs (2)
  • assert_delimiter_error (291-303)
  • assert_parse_error (206-221)
src/parser/expression/pratt.rs (1)
  • parse_expression (29-47)
🔍 Remote MCP

Here’s additional context surfaced from the PR diffs that should inform your review:

  1. In src/parser/tests/expression.rs, the existing postfix‐expression success cases (method calls, field access, bit slices, tuple indexing) and their helper imports have been removed from the main parses_expressions test. The file now only imports the error‐checking utilities assert_delimiter_error and assert_parse_error—and the new postfix_expression_errors rstest covers precisely four error scenarios (missing identifier after ., missing comma in a bit slice, unclosed brackets, etc.) with exact start/end positions and distinguishes unclosed‐delimiter errors from generic parse errors .

  2. A new integration test file tests/expression_postfix.rs exercises the public parse_expression API for all success cases in one place. It parametrizes tests for:

    • Single‐argument method calls, field accesses, bit slices, tuple indexing
    • A multi‐argument call ("foo.bar(1, 2)")
    • A chained postfix expression combining method call, field access, and bit slice ("foo.bar().baz[1,0]")
      and verifies the exact AST is produced via the method_call, field_access, bit_slice, and tuple_index constructors from test_util .
🔇 Additional comments (1)
src/parser/tests/expression.rs (1)

6-7: LGTM: scope imports to actual test usage

Imports align with usages in this module; no dead items. Keep as is.

Comment thread src/parser/tests/expression.rs
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

leynos and others added 3 commits September 8, 2025 07:29
@leynos leynos force-pushed the codex/add-tests-for-new-expr-variants branch from 2bb5065 to 68fb44b Compare September 8, 2025 07:13
Copy link
Copy Markdown
Contributor

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
tests/expression_var_and_call.rs (1)

8-9: Use assert_unclosed_delimiter_error for unclosed cases

Tighten error classification to the dedicated helper.

Apply:

-use ddlint::test_util::{assert_delimiter_error, assert_parse_error, call, lit_num, var};
+use ddlint::test_util::{
+    assert_delimiter_error, assert_parse_error, assert_unclosed_delimiter_error, call, lit_num, var,
+};
-    match kind {
-        "unclosed" | "mismatch" => assert_delimiter_error(&errors, msg, start, end),
-        _ => assert_parse_error(&errors, msg, start, end),
-    }
+    match kind {
+        "unclosed" => assert_unclosed_delimiter_error(&errors, msg, start, end),
+        "mismatch" => assert_delimiter_error(&errors, msg, start, end),
+        _ => assert_parse_error(&errors, msg, start, end),
+    }

Also applies to: 35-38

tests/expression_compound.rs (1)

8-11: Route unclosed delimiter assertions to the dedicated helper

Strengthen intent and future‑proof classification.

Apply:

-use ddlint::test_util::{
-    assert_delimiter_error, assert_parse_error, closure, field, lit_num, struct_expr, tuple, var,
-};
+use ddlint::test_util::{
+    assert_delimiter_error, assert_parse_error, assert_unclosed_delimiter_error, closure, field,
+    lit_num, struct_expr, tuple, var,
+};
-    if unclosed {
-        assert_delimiter_error(&errors, msg, start, end);
-    } else {
-        assert_parse_error(&errors, msg, start, end);
-    }
+    if unclosed {
+        assert_unclosed_delimiter_error(&errors, msg, start, end);
+    } else {
+        assert_parse_error(&errors, msg, start, end);
+    }

Also applies to: 56-60

src/test_util.rs (2)

274-281: Tighten delimiter kind detection

Avoid over‑matching delimiter mismatches as “Custom”.

Apply:

-            Self::Mismatch => {
-                matches!(reason, SimpleReason::Unexpected | SimpleReason::Custom(_))
-            }
+            Self::Mismatch => matches!(reason, SimpleReason::Unexpected),

112-119: Fix incorrect doc comment for call_expr

The comment advertises a struct literal but the function builds Expr::Call.

Apply:

-/// Construct a struct literal [`Expr::Struct`].
+/// Construct a call expression [`Expr::Call`].
 pub fn call_expr(callee: Expr, args: Vec<Expr>) -> Expr {
src/parser/tests/expression.rs (1)

105-113: Name remaining rstest cases for consistency and clearer failures.

Label these cases to match the style above.

Apply:

-#[case::bit_slice_missing_comma("e[1 0]", 1)]
-#[case::bit_slice_missing_rbracket("e[1,0", 1)]
-#[case::bit_slice_missing_lhs("e[,0]", 1)]
-#[case::bit_slice_missing_rhs("e[1,]", 1)]
-#[case::bit_slice_extra_comma("e[1,,0]", 1)]
-#[case::tuple_index_missing_digits("t.", 1)]
-#[case::tuple_index_negative("t.-1", 1)]
-#[case::tuple_index_plus("t.+1", 1)]
-#[case::tuple_index_double_dot("t..0", 1)]
+#[case::bit_slice_missing_comma("e[1 0]", 1)]
+#[case::bit_slice_missing_rbracket("e[1,0", 1)]
+#[case::bit_slice_missing_lhs("e[,0]", 1)]
+#[case::bit_slice_missing_rhs("e[1,]", 1)]
+#[case::bit_slice_extra_comma("e[1,,0]", 1)]
+#[case::tuple_index_missing_digits("t.", 1)]
+#[case::tuple_index_negative("t.-1", 1)]
+#[case::tuple_index_plus("t.+1)", 1)]
+#[case::tuple_index_double_dot("t..0", 1)]
♻️ Duplicate comments (1)
tests/expression_postfix.rs (1)

14-21: Resolve prior feedback: name rstest cases and add multi-arg/chained tests — good.

Cases are labelled (method_call, field_access, bit_slice, tuple_index, multi_arg_call, chained_postfix) and cover the requested scenarios.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b31d510 and 68fb44b.

📒 Files selected for processing (12)
  • src/parser/tests/expression.rs (3 hunks)
  • src/parser/tests/functions.rs (1 hunks)
  • src/parser/tests/imports.rs (1 hunks)
  • src/parser/tests/indexes.rs (1 hunks)
  • src/parser/tests/relations.rs (1 hunks)
  • src/test_util.rs (1 hunks)
  • tests/expression_compound.rs (1 hunks)
  • tests/expression_entry.rs (1 hunks)
  • tests/expression_postfix.rs (1 hunks)
  • tests/expression_prefix.rs (1 hunks)
  • tests/expression_var_and_call.rs (1 hunks)
  • tests/function_errors.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Keep any single Rust source file under 400 lines; split long switches/dispatch tables and move large test data to external files
Disallow Clippy warnings; do not silence lints except as a last resort
Any lint suppressions must be tightly scoped and include a clear reason; prefer expect over allow
Fix warnings emitted during tests in code instead of silencing them
Extract helper functions when functions are too long; group parameters into structs when they are too many
If returning a large error, consider using Arc to reduce returned data
Write unit and behavioural tests for new functionality and run before/after changes
Prefer immutable data; avoid unnecessary mut bindings
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate functions for conditional criteria with more than two branches
Prefer .expect() over .unwrap()
Use concat!() for long string literals rather than escaping newlines with a backslash

Files:

  • tests/expression_compound.rs
  • tests/expression_var_and_call.rs
  • src/parser/tests/relations.rs
  • src/parser/tests/imports.rs
  • src/parser/tests/functions.rs
  • src/parser/tests/indexes.rs
  • tests/expression_prefix.rs
  • tests/function_errors.rs
  • src/test_util.rs
  • tests/expression_entry.rs
  • src/parser/tests/expression.rs
  • tests/expression_postfix.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • tests/expression_compound.rs
  • tests/expression_var_and_call.rs
  • src/parser/tests/relations.rs
  • src/parser/tests/imports.rs
  • src/parser/tests/functions.rs
  • src/parser/tests/indexes.rs
  • tests/expression_prefix.rs
  • tests/function_errors.rs
  • src/test_util.rs
  • tests/expression_entry.rs
  • src/parser/tests/expression.rs
  • tests/expression_postfix.rs
tests/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup and prefer #[rstest(...)] parameterised cases over duplicated tests
Prefer mockall for mocks/stubs

Files:

  • tests/expression_compound.rs
  • tests/expression_var_and_call.rs
  • tests/expression_prefix.rs
  • tests/function_errors.rs
  • tests/expression_entry.rs
  • tests/expression_postfix.rs
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Every module must begin with a module-level //! comment explaining purpose and utility
Document public APIs with /// Rustdoc comments so cargo doc can generate docs

Files:

  • src/parser/tests/relations.rs
  • src/parser/tests/imports.rs
  • src/parser/tests/functions.rs
  • src/parser/tests/indexes.rs
  • src/test_util.rs
  • src/parser/tests/expression.rs
🧬 Code graph analysis (6)
src/parser/tests/relations.rs (1)
src/test_util.rs (1)
  • assert_delimiter_error (316-328)
src/parser/tests/imports.rs (1)
src/test_util.rs (1)
  • assert_parse_error (231-246)
src/parser/tests/functions.rs (1)
src/test_util.rs (1)
  • assert_parse_error (231-246)
src/parser/tests/indexes.rs (1)
src/test_util.rs (1)
  • assert_delimiter_error (316-328)
src/parser/tests/expression.rs (3)
src/test_util.rs (2)
  • assert_delimiter_error (316-328)
  • assert_parse_error (231-246)
tests/expression_postfix.rs (1)
  • postfix_expression_errors (28-43)
src/parser/expression/pratt.rs (1)
  • parse_expression (29-47)
tests/expression_postfix.rs (2)
src/parser/expression/pratt.rs (1)
  • parse_expression (29-47)
src/test_util.rs (8)
  • assert_delimiter_error (316-328)
  • assert_parse_error (231-246)
  • bit_slice (151-157)
  • field_access (132-138)
  • lit_num (75-77)
  • method_call (121-128)
  • tuple_index (142-147)
  • var (95-98)
🔍 Remote MCP

Here’s additional context surfaced from the PR diffs that should inform your review:

  1. In src/parser/tests/expression.rs, the existing postfix‐expression success cases (method calls, field access, bit slices, tuple indexing) and their helper imports have been removed from the main parses_expressions test. The file now only imports the error‐checking utilities assert_delimiter_error and assert_parse_error—and the new postfix_expression_errors rstest covers precisely four error scenarios (missing identifier after ., missing comma in a bit slice, unclosed brackets, etc.) with exact start/end positions and distinguishes unclosed‐delimiter errors from generic parse errors .

  2. A new integration test file tests/expression_postfix.rs exercises the public parse_expression API for all success cases in one place. It parametrizes tests for:

    • Single‐argument method calls, field accesses, bit slices, tuple indexing
    • A multi‐argument call ("foo.bar(1, 2)")
    • A chained postfix expression combining method call, field access, and bit slice ("foo.bar().baz[1,0]")
      and verifies the exact AST is produced via the method_call, field_access, bit_slice, and tuple_index constructors from test_util .
🔇 Additional comments (16)
tests/expression_var_and_call.rs (1)

24-24: Switch to human‑readable token — LGTM

Aligns with token normalisation across the suite.

src/parser/tests/indexes.rs (1)

71-71: Readable delimiter label — LGTM

“right paren” improves diagnostics without changing semantics.

tests/expression_compound.rs (1)

44-44: Readable token text — LGTM

“expected pipe” is consistent with the new normalisation.

tests/expression_prefix.rs (1)

35-35: Readable token text — LGTM

Matches the suite’s human‑friendly diagnostics.

tests/function_errors.rs (1)

11-12: Normalised delimiter names — LGTM

Both cases now use “left/right paren” as intended.

src/parser/tests/functions.rs (2)

107-107: Normalise expected token — LGTM

Switch to “left paren” aligns with test utilities.


112-113: Normalise expected tokens — LGTM

“right brace/right paren” expectations read better and match helpers.

src/test_util.rs (1)

57-63: Normalise before matching — LGTM

Ensures pattern and rendered message compare in the same domain.

src/parser/tests/relations.rs (1)

91-91: Readable delimiter label — LGTM

Keeps tests aligned with human‑friendly diagnostics.

src/parser/tests/imports.rs (2)

33-33: Adopt human-readable token names in error assertions — good change.

Switch to "identifier" aligns with normalised tokens in test utilities and de-brittles tests from internal enums.


1-57: Run the script below to search for any lingering internal token names in test assertions across the repository:

#!/bin/bash
set -euo pipefail
echo "Searching for T_* token assertions in .rs files:"
rg -n --type=rust --ignore-dir target -e 'T_IDENT\b' -e 'expected T_[A-Z_]+' -e 'unexpected token:\s*T_[A-Z_]+' .
tests/expression_entry.rs (1)

36-36: Match error to normalised token label — good.

Update to "unexpected token: number" is consistent with parser error rendering and test helper normalisation.

src/parser/tests/expression.rs (3)

6-8: Import delimiter vs parse error helpers — good.

Assert the correct error class when delimiters are unclosed; this reduces false positives in failure diagnostics.


95-104: Name rstest cases — good improvement.

Label error scenarios to produce clearer failure output.


120-140: Differentiate delimiter errors from generic parse errors — good.

Assert delimiter mismatches via assert_delimiter_error when unclosed is true; assert_parse_error otherwise.

tests/expression_postfix.rs (1)

26-43: Assert delimiter error for unclosed call — good.

Use assert_delimiter_error with precise span (8, 8) and message, matching the public API behaviour.

Comment thread src/test_util.rs
Comment on lines +36 to +54
/// Replace internal token names with human-readable forms.
fn normalise_tokens(s: &str) -> String {
[
("T_LPAREN", "left paren"),
("T_RPAREN", "right paren"),
("T_LBRACKET", "left bracket"),
("T_RBRACKET", "right bracket"),
("T_LBRACE", "left brace"),
("T_RBRACE", "right brace"),
("T_COMMA", "comma"),
("T_SEMI", "semicolon"),
("T_PIPE", "pipe"),
("T_IDENT", "identifier"),
("T_NUMBER", "number"),
]
.into_iter()
.fold(s.to_string(), |acc, (raw, human)| acc.replace(raw, human))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Speed up token normalisation and widen coverage (optional)

Avoid rebuilding mappings per call and extend coverage to common punctuation.

Add a module‑level constant and reuse it:

-fn normalise_tokens(s: &str) -> String {
-    [
-        ("T_LPAREN", "left paren"),
-        ("T_RPAREN", "right paren"),
-        ("T_LBRACKET", "left bracket"),
-        ("T_RBRACKET", "right bracket"),
-        ("T_LBRACE", "left brace"),
-        ("T_RBRACE", "right brace"),
-        ("T_COMMA", "comma"),
-        ("T_SEMI", "semicolon"),
-        ("T_PIPE", "pipe"),
-        ("T_IDENT", "identifier"),
-        ("T_NUMBER", "number"),
-    ]
-    .into_iter()
-    .fold(s.to_string(), |acc, (raw, human)| acc.replace(raw, human))
-}
+fn normalise_tokens(s: &str) -> String {
+    TOKEN_MAP
+        .iter()
+        .fold(s.to_string(), |acc, (raw, human)| acc.replace(raw, human))
+}

Add near the top of the module:

const TOKEN_MAP: [(&str, &str); 12] = [
    ("T_LPAREN", "left paren"),
    ("T_RPAREN", "right paren"),
    ("T_LBRACKET", "left bracket"),
    ("T_RBRACKET", "right bracket"),
    ("T_LBRACE", "left brace"),
    ("T_RBRACE", "right brace"),
    ("T_COMMA", "comma"),
    ("T_SEMI", "semicolon"),
    ("T_PIPE", "pipe"),
    ("T_IDENT", "identifier"),
    ("T_NUMBER", "number"),
    ("T_DOT", "dot"),
    ("T_COLON", "colon"),
];
🤖 Prompt for AI Agents
In src/test_util.rs around lines 36 to 54, normalise_tokens currently rebuilds
the token mapping on every call and misses a couple common punctuation tokens;
create a module-level constant (e.g., TOKEN_MAP) with the full list of mappings
including T_DOT and T_COLON, then refactor normalise_tokens to iterate over that
constant instead of constructing the array inline so the mapping is allocated
once and coverage is widened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant