Open
Description
I've been looking at how cucumber-expressions could be adopted in Behat.
One feature of our existing two pattern syntaxes (regex and turnip) is that they can name the arguments.
e.g.
@When /^I eat (?<count>[0-9]+) (?<fruit>.*)$/
@When I eat :count :fruit
This allows Behat to match arguments based on name as well as position, letting users transpose the argument order if necessary.
That can be useful if multiple patterns are attached to one step, something allowed in Behat:
/**
* @When I eat :count :fruit
* @When :count of the :fruit are eaten
* @When I don't eat any :fruit
*/
public function myStepDef(string $fruit, int $count=0): void
The new feature would be for Cucumber Expressions to capture argument names:
- Define a syntax for adding names to expressions (e.g.
{fruit:string}
) - Retain that name in the generated regex as a named group
- Attach the name to the matched Argument value objects that the parser outputs (with an accessor method)
Then it would be up to the Cucumber implementation to either use the names for matching to the step definition, or to ignore them and use the order directly as currently happens.
Metadata
Metadata
Assignees
Labels
No labels