/
feature_file.dart
56 lines (50 loc) · 1.61 KB
/
feature_file.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'package:bdd_widget_test/src/bdd_line.dart';
import 'package:bdd_widget_test/src/feature_generator.dart';
import 'package:bdd_widget_test/src/generator_options.dart';
import 'package:bdd_widget_test/src/step_file.dart';
class FeatureFile {
FeatureFile({
required this.featureDir,
required this.package,
required String input,
this.isIntegrationTest = false,
this.existingSteps = const <String, String>{},
this.generatorOptions = const GeneratorOptions(),
}) : _lines = _prepareLines(
input.split('\n').map((line) => line.trim()).map(BddLine.new),
) {
_stepFiles = _lines
.where((line) => line.type == LineType.step)
.map(
(e) => StepFile.create(
featureDir,
package,
e.value,
existingSteps,
generatorOptions,
),
)
.toList();
}
late List<StepFile> _stepFiles;
final String featureDir;
final String package;
final bool isIntegrationTest;
final List<BddLine> _lines;
final Map<String, String> existingSteps;
final GeneratorOptions generatorOptions;
String get dartContent => generateFeatureDart(
_lines,
getStepFiles(),
generatorOptions.testMethodName,
isIntegrationTest,
);
List<StepFile> getStepFiles() => _stepFiles;
static List<BddLine> _prepareLines(Iterable<BddLine> input) {
final headers = input.takeWhile((value) => value.type == LineType.unknown);
final lines = input
.skip(headers.length)
.where((value) => value.type != LineType.unknown);
return [...headers, ...lines];
}
}