flutter_gherkin
flutter_gherkin copied to clipboard
Can't use ^ in RegExp because of keywords
Coming from Ruby I got used to this notation When(/^I do something$/) which is pure regexp. It's great because $ helps with avoiding similar but-not-really steps to be misused:
For example 'When I do one thing' and 'When I do on thing differently', there is big chance that scenario step of smaller step gets matched to step def of bigger step because of firstWhere. But hopefully $ works ok with RegExp as pattern and RegExp('I do one thing differently$') is performing as expected. However, ^ part can't be used because pattern gets matched with keyword thus:
RegExp(r'^When I do something$') - works
RegExp(r'^I do something$') - doesn't
And in all examples it's suggested that we don't dupe keywords in strings of pattern. Also, if step in scenario uses not When but, say, And it will fail. And steps shouldn't really care about keywords, they are for business people.
Not really sure this issue is really important, but nevertheless it exists.
Interesting I guess it is trying to match the step on the whole line where it really should ignore the keyword in the line
@vrnvorona is this still an issue
Will check tomorrow as well with #182
No, same issue.
Issue is around here
lib/src/flutter/runners/gherkin_integration_test_runner.dart:332
The (s) => s.expression.isMatch(name) compares RegExp with full String, while it should strip keyword before doing so.
For example: expression here is "^I set birthday '"['"]$" and parsed name is "And I set birthday "1998-12-31""
then it won't match.
Maybe simple solution would be to load LanguageService for set language (currently in integration i think this parameter does nothing) and before matching strip keywords from beginning of name?