-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
SpecFlow step definitions with parametrized cucumber expressions are not recognized #63
Comments
I think I can resolve this one @aslakhellesoy . When I added c-sharp support originally, I wasn't aware that it could support cucumber expressions syntax. |
The language service scans the file system for glue code and extracts regular expressions and cucumber expressions from source code (using tree-sitter). The extracted expressions are then used to build autocomplete, go to step definition and syntax highlighting. The language service uses the JavaScript implementation of Cucumber Expressions to parse expressions, regardless of what programming language source code it was extracted from. The Cucumber Expressions parser will throw an exception when it parses an expression that uses a parameter type that hasn't been defined. Because of this, the language service will first extract all parameter types from the source code, and then try to parse all the Cucumber Expressions. I've discovered that this poses a challenge with SpecFlow source code because of the way parameter types are defined. Consider this Step Definition: [When("the client specifies {DateTime} at {TimeSpan} as delivery time")]
public void WhenTheClientSpecifiesDateAtTimeAsDeliveryTime(DateTime deliveryDate, TimeSpan deliveryTime)
{
} The Cucumber Expression uses two custom parameter types, With Java syntax, the @ParameterType(name = "DateTime", value = "\\d{4}-\\d{2}-\\d{2}")
public DateTime convertDateTime(String date) {
return DateTime.parse(date)
} The name of the parameter type is extracted from the ParameterType(
name: 'DateTime',
regexp: /\d{4}-\d{2}-\d{2}/,
transformer: ->(s) { DateTime.parse(s) }
) With SpecFlow however, it's different. The .NET implementation does not implement
SpecFlow has a similar concept to parameter types - step argument transformations. Here is how they work: [StepArgumentTransformation("today")]
public DateTime ConvertToday()
{
return DateTime.Today;
}
[StepArgumentTransformation("tomorrow")]
public DateTime ConvertTomorrow()
{
return DateTime.Today.AddDays(1);
}
[StepArgumentTransformation("(.*) days later")]
public DateTime ConvertDaysLater(int days)
{
return DateTime.Today.AddDays(days);
} At first glance, they look similar to the parameter type definitions in Java and Ruby shown above. There are some differences though: First off, they don't have an explicit name, but they have a type (the return type of the method). They also have something similar to a parameter type's regexp - the expression in the With SpecFlow, it's the type (
This would match the following Gherkin steps in SpecFlow:
In the JavaScript implementation of Cucumber Expressions (which is used in the language server), this becomes a challenge. How do we define the This is what I have in mind to make this possible:
For the example above, this would become (in TypeScript): const parameterType = new ParameterType(
'DateTime', // The name
[/tomorrow/, /today/, /(.*) days later/],
...
) This way the language server would match Gherkin steps in the same way as SpecFlow. I'd welcome your feedback on this @gasparnagy @SabotageAndi @Issafalcon |
This sounds like a perfectly sensible approach to me @aslakhellesoy . Not being as familiar as yourself with this codebase, it sounds like, from your description, that this will work across step definitions in all languages. One thing to note is the |
@aslakhellesoy Thx for the improvements. I have some notes/feedback.
|
The comprehensiveness of @gasparnagy 's reply compared to mine does a good job of highlighting the difference of one who writes the software, and one who simply consumes it 😂 I think I'll defer to @gasparnagy in this case! |
I have simple step definitions, like:
or
but the related steps are displayed as undefined. The ones without parameter work...
The text was updated successfully, but these errors were encountered: