Skip to content

Commit de94c7a

Browse files
authored
Merge pull request #111 from tide-khushal/bugfix/variables_in_datatable_appended_with_curly_braces
Fix: Remove Extra Curly Braces from Data Table Variables in Scenario Outlines
2 parents 6716458 + 60448de commit de94c7a

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

lib/src/scenario_generator.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,18 @@ Iterable<BddLine> _processScenarioLines(
120120
for (final line in lines.skip(1)) {
121121
yield BddLine.fromValue(
122122
line.type,
123-
_replacePlaceholders(line.value, examples),
123+
_replacePlaceholders(
124+
line.value, line.type == LineType.dataTableStep, examples),
124125
);
125126
}
126127
}
127128

128-
String _replacePlaceholders(String line, Map<String, String> example) {
129+
String _replacePlaceholders(
130+
String line, bool isDataTableStep, Map<String, String> example) {
129131
var replaced = line;
130132
for (final e in example.keys) {
131-
replaced = replaced.replaceAll('<$e>', '{${example[e]}}');
133+
final value = isDataTableStep ? '${example[e]}' : '{${example[e]}}';
134+
replaced = replaced.replaceAll('<$e>', value);
132135
}
133136
return replaced;
134137
}

test/data_tables_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,55 @@ Future<void> theFollowingSongs(WidgetTester tester, String param1, bdd.DataTable
485485
expectedStep,
486486
);
487487
});
488+
489+
test('Scenario Outline with data table variables', () {
490+
const featureFile = '''
491+
Feature: Testing feature
492+
Scenario Outline: Add and remove buttons work together
493+
Given the app is running
494+
When I tap add icon <times> times
495+
Then I see result
496+
| 'counter' | 'color' |
497+
| <counter> | <color> |
498+
Examples:
499+
| times | counter | color |
500+
| 20 | '20' | 'blue' |
501+
| 25 | '25' | 'green' |
502+
''';
503+
504+
const expectedFeatureDart = '''
505+
// GENERATED CODE - DO NOT MODIFY BY HAND
506+
// ignore_for_file: type=lint, type=warning
507+
508+
import 'package:bdd_widget_test/data_table.dart' as bdd;
509+
import 'package:flutter/material.dart';
510+
import 'package:flutter_test/flutter_test.dart';
511+
512+
import './step/the_app_is_running.dart';
513+
import './step/i_tap_add_icon_times.dart';
514+
import './step/i_see_result.dart';
515+
516+
void main() {
517+
group(\'\'\'Testing feature\'\'\', () {
518+
testWidgets(\'\'\'Outline: Add and remove buttons work together (20, '20', 'blue')\'\'\', (tester) async {
519+
await theAppIsRunning(tester);
520+
await iTapAddIconTimes(tester, 20);
521+
await iSeeResult(tester, const bdd.DataTable([['counter', 'color'], ['20', 'blue']]));
522+
});
523+
testWidgets(\'\'\'Outline: Add and remove buttons work together (25, '25', 'green')\'\'\', (tester) async {
524+
await theAppIsRunning(tester);
525+
await iTapAddIconTimes(tester, 25);
526+
await iSeeResult(tester, const bdd.DataTable([['counter', 'color'], ['25', 'green']]));
527+
});
528+
});
529+
}
530+
''';
531+
532+
final feature = FeatureFile(
533+
featureDir: 'test.feature',
534+
package: 'test',
535+
input: featureFile,
536+
);
537+
expect(feature.dartContent, expectedFeatureDart);
538+
});
488539
}

0 commit comments

Comments
 (0)