Repository navigation
Description
At the moment we explicitly disallow using any kind of regular expression extensions using format (?...), but it would be a good idea to support iniline flags. For more details about regexp extensions and inline flags see the regular expression syntax.
Probably the only flag that's actually relevant for us is case-insensitivity i.e. (?i), but we can easily accept them all. Why case-insensitivity is important is illustrate by the following example.
Assume we have the following keyword that allows selecting an animal so that animals are limited to cat, dog and cow.
from robot.api.deco import keyword
@keyword('Select ${animal:cat|dog|cow}')
def select(animal):
print(animal)Let's then have the following tests using this keywod.
*** Test Cases ***
Works fine
Select dog
Works but causes deprecation warning
Select DogAs the test case names already illustrate, the first one using one of the listed animals exactly works fine. The second test where one of the animals is used with a different case also passes, but there's the following deprecation warning:
Embedded argument 'animal' got value 'Dog' that does not match custom pattern 'cat|dog|cow'. The argument is still accepted, but this behavior will change in Robot Framework 8.0.
The deprecation warning is caused by #4069. It was added because we want to start validating that arguments match also when they are given as variables, and it hadn't occurred to me earlier that there's a similar situation also if there's a case-insensitive match. The reason there's the warning in this particular case is that:
- The initial keyword matching is case-insensitive and thus both
dogandDogmatch. This check is done before variables are resolved. - After variables are resolved, there's a separate check that arguments match custom patterns. In this check
Dogdoesn't match anymore.
I think custom pattern matching being case-sensitive is fine, but there should be an option to make explicitly make it case-insensitive. A natural syntax with regexps is using inline flags as in the example below, but at the moment that doesn't work.
@keyword('Select ${animal:(?i)cat|dog|cow}')
def select(animal):
print(animal)I believe it's important to do this before RF 8.0 where #4069 is planned to be implemented.
Activity
pekkaklarck commentedon Oct 18, 2024
This issue is a spinoff from #5231 that contains a generic keyword that is supposed to match multiple keywords and that could be created like this:
and used like
The above works, but it requires the used keyword name to be example
Keyword 1orKeyword 2. Using it case-insensitively likekeyword 1causes the same deprecation warning as in the description. Prefixing the pattern with the(?i)flag would be a natural way to make the match case-insensitive.Embedded args: Support inline flags with custom regexps