Skip to content

Two defwhen that both matches #88

@edisonywh

Description

@edisonywh

So we came across an issue where we have two defwhen, and both their regex matches on with the feature we are writing.

Reproduce

Specifically we have something like this:

Example text

selection 1 is marked as won

Case 1

defwhen ~r/^selection (?<index>\d+) is (marked as )?(?<result_name>pending|won|lost|voided|pushed|cashed out|win-push)$/,

Case 2

defwhen ~r/^selection (?<cname>[^ ]+) is (marked as )?(?<result_name>pending|won|lost|voided|pushed|cashed out|win-push)$/,

The defwhens are written in this exact order, case 1 first then case 2.

So we actually intend it to match the first case, hence \d+, but for some reason the example text matches the second case instead. We can confirm that if we comment out the second clause, Cabbage matches the first case just fine.

For our solution, we have updated our second case clause's regex to be more specific instead, and it works:

^selection (?<cname>\D\w+) is (marked as )?(<result_name>pending|won|lost|voided|pushed|cashed out|win-push)$

Question

But we're just wondering, when there are two cases that can both match a feature, which one would Cabbage pick? Is the current behaviour expected, and is it documented somewhere? I would've thought the order of defwhen matters, but it looks like it isn't?

To add, we're not entirely sure if this is always 100% reproducible, because our tests are usually green too, so it could be intermittent?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions