diff --git a/example/test/songs.feature b/example/test/songs.feature index b47c28c..2a007ba 100644 --- a/example/test/songs.feature +++ b/example/test/songs.feature @@ -1,7 +1,7 @@ Feature: Songs Scenario: Available songs - Given the following songs + Given the following {'Good'} songs | 'artist' | 'title' | | 'The Beatles' | 'Let It Be' | | 'Camel' | 'Slow yourself down' | diff --git a/example/test/songs_test.dart b/example/test/songs_test.dart index f0aea3f..4c853d7 100644 --- a/example/test/songs_test.dart +++ b/example/test/songs_test.dart @@ -12,6 +12,7 @@ void main() { testWidgets('''Available songs''', (tester) async { await theFollowingSongs( tester, + 'Good', const bdd.DataTable([ ['artist', 'title'], ['The Beatles', 'Let It Be'], diff --git a/example/test/step/the_following_songs.dart b/example/test/step/the_following_songs.dart index 1f85dfb..29a390c 100644 --- a/example/test/step/the_following_songs.dart +++ b/example/test/step/the_following_songs.dart @@ -1,7 +1,8 @@ import 'package:bdd_widget_test/data_table.dart' as bdd; import 'package:flutter_test/flutter_test.dart'; -/// Usage: the following songs -Future theFollowingSongs(WidgetTester tester, bdd.DataTable dataTable) async { +/// Usage: the following {'Good'} songs +Future theFollowingSongs( + WidgetTester tester, String param1, bdd.DataTable dataTable) async { throw UnimplementedError(); } diff --git a/lib/src/step/generic_step.dart b/lib/src/step/generic_step.dart index df2f61f..852a3b4 100644 --- a/lib/src/step/generic_step.dart +++ b/lib/src/step/generic_step.dart @@ -31,25 +31,16 @@ Future $methodName($testerType $customTesterName${_getMethodParameters(raw '''; String _getMethodParameters(String stepLine, bool hadDataTable) { - if (hadDataTable) { - return ', bdd.DataTable dataTable'; - } - final params = parseRawStepLine(stepLine).skip(1); - if (params.isNotEmpty) { - return params - .mapIndexed( - (index, p) => ', ${_getGenericParameterType(p)} param${index + 1}', - ) - .join(); - } - final examples = examplesRegExp.allMatches(stepLine); - if (examples.isNotEmpty) { - return examples.map((p) => ', dynamic ${p.group(1)}').join(); - } - return ''; + return [ + ...params.mapIndexed( + (index, p) => ', ${_getGenericParameterType(p)} param${index + 1}', + ), + ...examples.map((p) => ', dynamic ${p.group(1)}'), + if (hasDataTable) ', bdd.DataTable dataTable', + ].join(); } String _getGenericParameterType(String parameter) { diff --git a/test/data_tables_test.dart b/test/data_tables_test.dart index 3cf3a58..0f4260c 100644 --- a/test/data_tables_test.dart +++ b/test/data_tables_test.dart @@ -1,4 +1,5 @@ import 'package:bdd_widget_test/src/feature_file.dart'; +import 'package:bdd_widget_test/src/step_file.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -435,4 +436,53 @@ void main() { expect(feature.dartContent, expectedFeatureDart); }); + test('Data table with parameters', () { + const featureFile = ''' +Feature: Testing feature + Scenario: Testing scenario + Given the following {'Good'} songs + | artist | title | + | 'The Beatles' | 'Let It Be' | + | 'Camel' | 'Slow yourself down' | +'''; + + const expectedFeatureDart = ''' +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_import, directives_ordering + +import 'package:bdd_widget_test/data_table.dart' as bdd; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import './step/the_following_songs.dart'; + +void main() { + group(\'\'\'Testing feature\'\'\', () { + testWidgets(\'\'\'Testing scenario\'\'\', (tester) async { + await theFollowingSongs(tester, 'Good', const bdd.DataTable([[artist, title], ['The Beatles', 'Let It Be'], ['Camel', 'Slow yourself down']])); + }); + }); +} +'''; + const expectedStep = ''' +import 'package:bdd_widget_test/data_table.dart' as bdd; +import 'package:flutter_test/flutter_test.dart'; + +/// Usage: the following {'Good'} songs +Future theFollowingSongs(WidgetTester tester, String param1, bdd.DataTable dataTable) async { + throw UnimplementedError(); +} +'''; + + final feature = FeatureFile( + featureDir: 'test.feature', + package: 'test', + input: featureFile, + ); + expect(feature.dartContent, expectedFeatureDart); + expect( + (feature.getStepFiles().first as NewStepFile).dartContent, + expectedStep, + ); + }); }