Skip to content

Commit

Permalink
Merge pull request #74 from olexale/bugfix/comments_fix
Browse files Browse the repository at this point in the history
Fix #73
  • Loading branch information
olexale authored Mar 27, 2024
2 parents 4b86c26 + bfefe90 commit 5dab948
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/feature_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class FeatureFile {
).toList(growable: false);

final headers = lines
.where((value) => value.type == LineType.unknown)
.takeWhile((value) => value.type != LineType.feature)
.where((value) => value.type == LineType.unknown)
.foldIndexed(
// this removes empty line dupicates
<BddLine>[],
Expand Down
87 changes: 87 additions & 0 deletions test/comment_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'package:bdd_widget_test/src/feature_file.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('Comments above features copy-paste into the target file', () {
const featureFile = '''
// This is a comment
Feature: Testing feature
Scenario: Testing scenario
Given the app is running
''';

const expectedFeatureDart = '''
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unused_import, directives_ordering
// This is a comment
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import './step/the_app_is_running.dart';
void main() {
group(\'\'\'Testing feature\'\'\', () {
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {
await theAppIsRunning(tester);
});
});
}
''';

final feature = FeatureFile(
featureDir: 'test.feature',
package: 'test',
input: featureFile,
);
expect(feature.dartContent, expectedFeatureDart);
});

test('Comments after first feature are ignored', () {
const featureFile = '''
Feature: Testing feature
This is a comment
Scenario: Testing scenario
Given the app is running
This is another comment
Feature: Testing feature 2
This is a comment
Scenario: Testing scenario
Given the app is running
This is a comment too
''';

const expectedFeatureDart = '''
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unused_import, directives_ordering
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import './step/the_app_is_running.dart';
void main() {
group(\'\'\'Testing feature\'\'\', () {
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {
await theAppIsRunning(tester);
});
});
group(\'\'\'Testing feature 2\'\'\', () {
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {
await theAppIsRunning(tester);
});
});
}
''';

final feature = FeatureFile(
featureDir: 'test.feature',
package: 'test',
input: featureFile,
);
expect(feature.dartContent, expectedFeatureDart);
});
}
1 change: 1 addition & 0 deletions test/tags_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void main() {
const featureFile = '''
@integration
import 'package:my_package/my_package.dart';
@slow
Feature: Testing feature
Scenario: Testing scenario
Expand Down

0 comments on commit 5dab948

Please sign in to comment.