Skip to content

🧪 Add tests for Range contains and overlaps#126

Open
bashandbone wants to merge 6 commits intomainfrom
test-improvements-types-range-10248173612806926714
Open

🧪 Add tests for Range contains and overlaps#126
bashandbone wants to merge 6 commits intomainfrom
test-improvements-types-range-10248173612806926714

Conversation

@bashandbone
Copy link
Contributor

@bashandbone bashandbone commented Mar 22, 2026

🎯 What: The testing gap for Range::contains and Range::overlaps has been addressed.
📊 Coverage: Tests now cover edge cases like exactly at start, exactly at end, completely inside, completely outside, overlapping starts, overlapping ends, abutting ranges and non-overlapping ranges.
Result: Test coverage for the types module improved, ensuring Range boundary conditions and overlaps are securely evaluated going forward. Additionally removed an unused variable warning in crates/language/src/lib.rs.


PR created automatically by Jules for task 10248173612806926714 started by @bashandbone

Summary by Sourcery

Add comprehensive tests for Range boundary behavior and overlaps and clean up an unused variable warning in language support detection.

Bug Fixes:

  • Resolve an unused variable warning when matching extensionless filenames in the language detection helper.

Tests:

  • Add unit tests for Range::contains covering before, at boundaries, inside, and after the range.
  • Add unit tests for Range::overlaps covering non-overlapping, abutting, partially overlapping, and fully contained ranges.

…ices/src/types.rs`

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 22, 2026 20:41
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 22, 2026

Reviewer's Guide

Adds focused unit tests for Range::contains and Range::overlaps covering a variety of boundary and overlap scenarios, and fixes an unused variable warning in language path extension handling by actually using the filename binding.

Class diagram for Range and Position with contains and overlaps

classDiagram
    class Position {
        +usize line
        +usize byte_column
        +usize byte_offset
        +new(line usize, byte_column usize, byte_offset usize) Position
    }

    class Range {
        +Position start
        +Position end
        +new(start Position, end Position) Range
        +contains(position Position) bool
        +overlaps(other Range) bool
    }

    Range *-- Position
Loading

Flow diagram for Range overlaps evaluation

flowchart TD
    A[Start overlaps] --> B[Given self and other ranges]
    B --> C{self.start <= other.end?}
    C -- No --> D[Return false]
    C -- Yes --> E{other.start <= self.end?}
    E -- No --> D[Return false]
    E -- Yes --> F[Return true]
    D --> G[End]
    F --> G[End]
Loading

File-Level Changes

Change Details Files
Add unit tests for Range::contains and Range::overlaps to validate boundary and overlap semantics across multiple scenarios.
  • Introduce a test module guarded by #[cfg(test)] for the Range type in the services types module.
  • Add a feature-gated helper constructor for Position that adapts to ast-grep-backend versus non-ast-grep-backend field naming conventions.
  • Create test_range_contains to cover positions before, exactly at start, inside, exactly at end, and after a Range.
  • Create test_range_overlaps to cover non-overlapping, abutting, overlapping start, fully contained, overlapping end, and post-range scenarios, asserting symmetry of overlaps.
crates/services/src/types.rs
Resolve unused variable warning in language support detection by using the file_name binding in extensionless and special-filename handling.
  • Rename the local filename binding from _file_name to file_name so it is no longer treated as intentionally unused.
  • Update checks against BASH_EXTS and LANG_RELATIONSHIPS_WITH_NO_EXTENSION to use the new file_name binding.
crates/language/src/lib.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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The test_range_contains and test_range_overlaps functions are quite verbose and repetitive; consider using a table-driven style (e.g., a list of cases with description, input ranges, and expected result) to make the tests more compact and easier to extend.
  • You already introduced a pos helper; adding a small range helper (e.g., fn range(s: (..), e: (..)) -> Range) could further reduce duplication and improve readability in the overlap tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `test_range_contains` and `test_range_overlaps` functions are quite verbose and repetitive; consider using a table-driven style (e.g., a list of cases with description, input ranges, and expected result) to make the tests more compact and easier to extend.
- You already introduced a `pos` helper; adding a small `range` helper (e.g., `fn range(s: (..), e: (..)) -> Range`) could further reduce duplication and improve readability in the overlap tests.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds missing unit tests for Range::contains and Range::overlaps (including boundary/abut cases) and removes an unused-variable warning in language extension detection.

Changes:

  • Added comprehensive Range unit tests for contains and overlaps edge conditions.
  • Adjusted from_extension to use the filename binding (removing an unused variable warning).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/services/src/types.rs Adds test module covering Range containment/overlap boundary cases.
crates/language/src/lib.rs Renames _file_name to file_name and updates comparisons to use it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
// 2. Ending exactly at start (overlap)
let abut_before = Range::new(pos(1, 0, 10), pos(2, 5, 25));
assert!(base.overlaps(&abut_before));
assert!(abut_before.overlaps(&base));
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

The comments say abutting at the boundary is an overlap; that documents an inclusive overlap definition. If the public semantics are intended to be half-open ([start, end)) or treat abutting as non-overlapping, these tests will lock in the wrong contract. Please align the test expectations/comments with the intended Range semantics (and consider a short doc comment on Range::overlaps/Range::contains clarifying inclusivity).

Copilot uses AI. Check for mistakes.
Comment on lines +705 to +708
// 6. Starting exactly at end (overlap)
let abut_after = Range::new(pos(4, 10, 55), pos(5, 0, 65));
assert!(base.overlaps(&abut_after));
assert!(abut_after.overlaps(&base));
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

The comments say abutting at the boundary is an overlap; that documents an inclusive overlap definition. If the public semantics are intended to be half-open ([start, end)) or treat abutting as non-overlapping, these tests will lock in the wrong contract. Please align the test expectations/comments with the intended Range semantics (and consider a short doc comment on Range::overlaps/Range::contains clarifying inclusivity).

Copilot uses AI. Check for mistakes.
google-labs-jules bot and others added 5 commits March 22, 2026 21:17
Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
…aScript structs in crates/ast-engine

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
…tructs

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
…tructs

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
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