flutter_gherkin icon indicating copy to clipboard operation
flutter_gherkin copied to clipboard

Can't use ^ in RegExp because of keywords

Open vrnvorona opened this issue 4 years ago • 4 comments

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.

vrnvorona avatar Oct 08 '21 09:10 vrnvorona

Interesting I guess it is trying to match the step on the whole line where it really should ignore the keyword in the line

jonsamwell avatar Oct 27 '21 08:10 jonsamwell

@vrnvorona is this still an issue

jonsamwell avatar Jul 25 '22 07:07 jonsamwell

Will check tomorrow as well with #182

vrnvorona avatar Jul 25 '22 09:07 vrnvorona

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?

vrnvorona avatar Jul 27 '22 07:07 vrnvorona