Skip to content
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

fix: condition to incorporate * in regEx to match step-syntax #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/gherkin/syntax/regex_matched_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ abstract class RegExMatchedGherkinSyntax<TRunnable extends Runnable>
pattern(dialect).hasMatch(line);

static String getMultiDialectRegexPattern(Iterable<String> dialectVariants) =>
dialectVariants.map((s) => s.trim()).where((s) => s != '*').join('|');
dialectVariants.map((s) => s.trim().replaceAll('*', '\\*')).join('|');
}
57 changes: 57 additions & 0 deletions test/gherkin/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,62 @@ void main() {
expect(feature.scenarios.elementAt(1).tags.length, 1);
expect(feature.scenarios.elementAt(1).tags.first.tags.first, '@skip');
});

test('parses steps with asterisk(*)', () async {
final parser = GherkinParser();
final featureContents = '''
Feature: Asterisk example
Scenario: All done
Given I am out shopping
And I have eggs
And I have milk
And I have butter
When I check my list
Then I don't need anything

Scenario: All done more elegantly
Given I am out shopping
* I have eggs
* I have milk
* I have butter
When I check my list
Then I don't need anything
''';
final featureFile = await parser.parseFeatureFile(
featureContents,
'',
ReporterMock(),
LanguageServiceMock(),
);
expect(featureFile, isNot(null));
expect(featureFile.language, equals('en'));
expect(featureFile.features.length, 1);

final feature = featureFile.features.elementAt(0);
expect(feature.name, 'Asterisk example');
expect(feature.scenarios.length, 2);

final scenario = featureFile.features.elementAt(0).scenarios.elementAt(0);
expect(scenario.name, 'All done');

final steps = scenario.steps;
expect(steps.elementAt(0).name, 'Given I am out shopping');
expect(steps.elementAt(1).name, 'And I have eggs');
expect(steps.elementAt(2).name, 'And I have milk');
expect(steps.elementAt(3).name, 'And I have butter');
expect(steps.elementAt(4).name, 'When I check my list');
expect(steps.elementAt(5).name, 'Then I don\'t need anything');

final scenario2 =
featureFile.features.elementAt(0).scenarios.elementAt(1);
expect(scenario2.name, 'All done more elegantly');

expect(scenario2.steps.elementAt(0).name, 'Given I am out shopping');
expect(scenario2.steps.elementAt(1).name, '* I have eggs');
expect(scenario2.steps.elementAt(2).name, '* I have milk');
expect(scenario2.steps.elementAt(3).name, '* I have butter');
expect(scenario2.steps.elementAt(4).name, 'When I check my list');
expect(scenario2.steps.elementAt(5).name, 'Then I don\'t need anything');
});
});
}
10 changes: 10 additions & 0 deletions test/gherkin/syntax/step_syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ void main() {
true);
});

test('matches * correctly', () {
final syntax = StepSyntax();
expect(
syntax.isMatch(
'* something',
EnDialectMock(),
),
true);
});

test('matches but correctly', () {
final syntax = StepSyntax();
expect(
Expand Down
10 changes: 5 additions & 5 deletions test/mocks/en_dialect_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class EnDialectMock extends GherkinDialect {
scenario = ['Scenario'];
scenarioOutline = ['Scenario Outline'];
examples = ['Scenarios', 'Examples'];
given = ['Given'];
when = ['When'];
then = ['Then'];
and = ['And'];
but = ['But'];
given = ['Given', '*'];
when = ['When', '*'];
then = ['Then', '*'];
and = ['And', '*'];
but = ['But', '*'];

stepKeywords = (<String>[
...given,
Expand Down