Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Unit Test groups are incorrect for C# Expressions

Open bburgess19 opened this issue 2 years ago • 2 comments

Bug Description

When using a C# expression with the pattern whitespace and explicit capture flags on, the unit test doesn't correctly report the groups that participated in the match. In my expression, there are two named capture groups that have the same name: "Qty" and "UM." When using the test to check the result of the group "UnitPrice," the test reports, "Group 7 [UnitPrice] no longer exists in the pattern or did not participate in the match." When looking inside the duplicate group "Qty," inside of the test explorer, it reports the unit price's value.

Reproduction steps

I made my expression public for analysis here https://regex101.com/r/kYuxbz/1. The error can be reproduced using the last test in the list.

Expected Outcome

I would expect all of the groups to be captured in one group, even if there is a duplicate named group.

Browser

Safari 15.4

OS

Mac OS Monterey 12.3

bburgess19 avatar Apr 19 '22 15:04 bburgess19

It may have something to do with the group IDs/group name mapping for the dropdown.

Given the particular string in Unit Test File name: 23712901. Foreign currency—unit price and value go to three decimal places (last one), it should have 5 capture groups, and therefore capture group 4 is really unitPrice but the dropdown selection of the unit test offers something different.

If one manually selects Group 4 from the unit test dropdown, then the unit test will succeed in starts with 0.080.

image

working-name avatar Apr 20 '22 19:04 working-name

That's very interesting. I'll use that workaround for now. Thank you!

bburgess19 avatar Apr 21 '22 17:04 bburgess19

The URL you posted seems to be deleted.

firasdib avatar Aug 07 '22 11:08 firasdib

I'm fairly sure this will be related to https://github.com/firasdib/Regex101/issues/1861 which is now fixed.

firasdib avatar Aug 09 '22 19:08 firasdib