-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Consider example:
Feature: Syntax highlighting
Scenario: Parameter should be highlighted as it is a cucumber expression
Given step with a cucumber expression "text"
Scenario: Step with alternating text should be resolved
Given step with alternating text
Scenario: Step with alternating text and parameter should be resolved
Given step with alternating text and parameter "text"[Binding]
public class SyntaxHighlightingSteps
{
[Given("step with a cucumber expression {string}")]
public void GivenStepWithACucumberExpressionString(string _)
{ }
[Given("step with alternating text/string")]
public void GivenStepWithAlternatingTextString()
{ }
[Given("step with alternating text/string and parameter {string}")]
public void GivenStepWithAlternatingTextStringAndParameterString(string _)
{ }
}The step in the second scenario is (incorrectly) highlighted as not found.
Attempt to research the root cause:
It seems that the trouble is caused by this line in the code:
var expression = new CucumberExpression(pattern, DefaultParameterTypeRegistry);
if (expression.ParameterTypes.Length > 0)
// Convert Cucumber expression to regex pattern
finalPattern = expression.Regex.ToString();Check for parameters presence is currently the only heuristics to detect if a sentence is a Cucumber Expression or a regex - while Cucumber Expressions also support optionals and alternatives.
@Socolin @dominik-niebuhr how could the heuristics be improved? ๐ค I tried to remove the check, but that completely broke recognition of regex bindings.
In our current project we don't have any regex bindings, but I can imagine that there is a ton of projects in the wild that have never heard about the Cucumber Expressions (and that would not like to migrate). I am currently thinking about possible options:
- Still try to implement custom code for detecting regex expressions - seems to be extremely hard to cover all possible cases.
- Introduce a setting in
reqnroll.json(disabled by default) to switch regex completely off.
In your eyes, are Cucumber Expressions the way to go? Should it become an officially recommended way of writing the sentences in the future?
The problem is that the optionals and alternatives are valid for both regex and Cucumber Expressions - although with different meaning. Would it make sense to have a parameter in reqnroll.json to disable regex completely and to treat all sentences as Cucumber Expressions? Basically, in our current project we stick to them from the very beginning - we don't have any regex steps.
Of course, that is a really big change. What is your view on that? Are Cucumber Expressions the way to go in the future? Should there be another syntax for steps
PS: the issue is not reproducible in Visual Studio. Trying to check the code now - a config stepDefinitionSkeletonStyle looks really interesting ๐
