Test-More / Test-More/test-more

bag has issues if an item matches multiple elements

Open
#996 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
149
Forks
98
PR merge metrics
No merged PRs in 30d

Description

    my $check = bag {
        item match qr/a/;
        item match qr/b/;
        end();    # Ensure no other elements exist.
    };  

    is(['fab', 'bad'], $check);

In this case we get a failure cause both items match the first element, so the second element is considered 'extra' for the end check. A quick-fix would be to never re-check an element, but that is not a valid fix:

    my $check = bag {
        item match qr/a/;
        item match qr/ab/; # <---- change is here
        end();    # Ensure no other elements exist.
    };  

    is(['fab', 'bad'], $check);

This one will still fail because the less greedy bag item got 'fab' and 'ab' will not match against 'bad' but a human reader knows this should pass.

I think bag as it is currently needs a bit of an overhaul. We need to iterate over the array, not the bag items. We need to record all matches. When 'end; is not specified we just need to check that all items have at least 1 match in the array, easy. When 'end' is used we need to make sure both lists have a match in the other, but in cases where there are multiple matches we need to pick one. This can get complicated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two bag examples in issue #996, focusing on how bag items are matched and how end() checks for extra elements. Trace the bag matching implementation and add regression coverage for overlapping matches. Done means both examples pass while preserving correct behavior when end() is omitted or included.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.