Add tests for postfix expression variants#137
Conversation
Reviewer's GuideIntroduces 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary by CodeRabbit
WalkthroughMove 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 ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Comment |
There was a problem hiding this comment.
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.
📒 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.rssrc/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
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless 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
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor 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
mockablecrate are the preferred option.- If mockable cannot be used, env mutations in tests ...
Files:
tests/expression_postfix.rssrc/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.
|
@coderabbitai Have the following now been resolved?
|
|
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:
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., 3. Multi-argument method call case: Status Summary:
You still need to add tests for chained postfix expressions and multi-argument method calls to fully address the original feedback. thinking hard about test coverage 🏁 Script executed: 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: 2. Chained-postfix test: #[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 3. Multi-argument method call: #[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! happy with comprehensive test coverage |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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.rssrc/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
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless 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
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor 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
mockablecrate are the preferred option.- If mockable cannot be used, env mutations in tests ...
Files:
tests/expression_postfix.rssrc/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.
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. About Codex in GitHubYour 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". |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless 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
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor 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
mockablecrate 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:
-
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 mainparses_expressionstest. The file now only imports the error‐checking utilitiesassert_delimiter_errorandassert_parse_error—and the newpostfix_expression_errorsrstest 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 . -
A new integration test file
tests/expression_postfix.rsexercises the publicparse_expressionAPI 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 themethod_call,field_access,bit_slice, andtuple_indexconstructors fromtest_util.
🔇 Additional comments (1)
src/parser/tests/expression.rs (1)
6-7: LGTM: scope imports to actual test usageImports align with usages in this module; no dead items. Keep as is.
Breaks long import line into multiple lines to improve code style and maintainability
2bb5065 to
68fb44b
Compare
There was a problem hiding this comment.
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 casesTighten 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 helperStrengthen 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 detectionAvoid 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_exprThe 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
📒 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.rstests/expression_var_and_call.rssrc/parser/tests/relations.rssrc/parser/tests/imports.rssrc/parser/tests/functions.rssrc/parser/tests/indexes.rstests/expression_prefix.rstests/function_errors.rssrc/test_util.rstests/expression_entry.rssrc/parser/tests/expression.rstests/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
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless 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
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor 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
mockablecrate are the preferred option.- If mockable cannot be used, env mutations in tests ...
Files:
tests/expression_compound.rstests/expression_var_and_call.rssrc/parser/tests/relations.rssrc/parser/tests/imports.rssrc/parser/tests/functions.rssrc/parser/tests/indexes.rstests/expression_prefix.rstests/function_errors.rssrc/test_util.rstests/expression_entry.rssrc/parser/tests/expression.rstests/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.rstests/expression_var_and_call.rstests/expression_prefix.rstests/function_errors.rstests/expression_entry.rstests/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.rssrc/parser/tests/imports.rssrc/parser/tests/functions.rssrc/parser/tests/indexes.rssrc/test_util.rssrc/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:
-
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 mainparses_expressionstest. The file now only imports the error‐checking utilitiesassert_delimiter_errorandassert_parse_error—and the newpostfix_expression_errorsrstest 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 . -
A new integration test file
tests/expression_postfix.rsexercises the publicparse_expressionAPI 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 themethod_call,field_access,bit_slice, andtuple_indexconstructors fromtest_util.
🔇 Additional comments (16)
tests/expression_var_and_call.rs (1)
24-24: Switch to human‑readable token — LGTMAligns 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 — LGTMMatches the suite’s human‑friendly diagnostics.
tests/function_errors.rs (1)
11-12: Normalised delimiter names — LGTMBoth cases now use “left/right paren” as intended.
src/parser/tests/functions.rs (2)
107-107: Normalise expected token — LGTMSwitch 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 — LGTMEnsures pattern and rendered message compare in the same domain.
src/parser/tests/relations.rs (1)
91-91: Readable delimiter label — LGTMKeeps 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.
| /// 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)) | ||
| } | ||
|
|
There was a problem hiding this comment.
🧹 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.
Summary
Testing
make fmtmake lintmake testhttps://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: