Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two defwhen that both matches #88

Open
edisonywh opened this issue Aug 18, 2020 · 0 comments
Open

Two defwhen that both matches #88

edisonywh opened this issue Aug 18, 2020 · 0 comments

Comments

@edisonywh
Copy link

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?

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

No branches or pull requests

1 participant