Skip to content

Commit c59645d

Browse files
committed
Reformat code
1 parent 9e8e2f2 commit c59645d

19 files changed

Lines changed: 326 additions & 273 deletions

lib/bdd_widget_test.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import 'package:yaml/yaml.dart';
3232
///
3333
/// Returns a [FeatureBuilder] instance configured with the specified options.
3434
Builder featureBuilder(BuilderOptions options) => FeatureBuilder(
35-
GeneratorOptions.fromMap(options.config),
36-
);
35+
GeneratorOptions.fromMap(options.config),
36+
);
3737

3838
/// A code generator builder that transforms BDD feature files into Dart test files.
3939
///
@@ -139,7 +139,7 @@ class FeatureBuilder implements Builder {
139139
final featureDir = p.dirname(inputId.path);
140140
final isIntegrationTest =
141141
inputId.pathSegments.contains('integration_test') &&
142-
_hasIntegrationTestDevDependency();
142+
_hasIntegrationTestDevDependency();
143143

144144
final feature = FeatureFile(
145145
featureDir: featureDir,
@@ -159,9 +159,8 @@ class FeatureBuilder implements Builder {
159159
);
160160

161161
final steps = feature.getStepFiles().whereType<NewStepFile>().map(
162-
(e) =>
163-
_createFileRecursively(e.filename, formatDartCode(e.dartContent)),
164-
);
162+
(e) => _createFileRecursively(e.filename, formatDartCode(e.dartContent)),
163+
);
165164
await Future.wait(steps);
166165

167166
final hookFile = feature.hookFile;
@@ -171,12 +170,14 @@ class FeatureBuilder implements Builder {
171170
}
172171

173172
Future<GeneratorOptions> _prepareOptions() async {
174-
final fileOptions = fs.file('bdd_options.yaml').existsSync()
175-
? readFromUri(Uri.file('bdd_options.yaml'))
176-
: null;
177-
final mergedOptions = fileOptions != null
178-
? merge(generatorOptions, fileOptions)
179-
: generatorOptions;
173+
final fileOptions =
174+
fs.file('bdd_options.yaml').existsSync()
175+
? readFromUri(Uri.file('bdd_options.yaml'))
176+
: null;
177+
final mergedOptions =
178+
fileOptions != null
179+
? merge(generatorOptions, fileOptions)
180+
: generatorOptions;
180181
final options = await flattenOptions(mergedOptions);
181182
return options;
182183
}

lib/src/bdd_line.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class BddLine {
22
BddLine(this.rawLine)
3-
: type = _lineTypeFromString(rawLine),
4-
value = _removeLinePrefix(rawLine);
3+
: type = _lineTypeFromString(rawLine),
4+
value = _removeLinePrefix(rawLine);
55

66
BddLine.fromValue(this.type, this.value) : rawLine = '';
77
BddLine.fromRawValue(this.type, this.rawLine)
8-
: value = _removeLinePrefix(rawLine);
8+
: value = _removeLinePrefix(rawLine);
99

1010
final String rawLine;
1111
final String value;

lib/src/data_table_parser.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:bdd_widget_test/src/scenario_generator.dart';
44

55
bool hasBddDataTable(List<BddLine> lines) {
66
for (var index = 0; index < lines.length; index++) {
7-
final isStep = lines[index].type == LineType.step ||
7+
final isStep =
8+
lines[index].type == LineType.step ||
89
lines[index].type == LineType.dataTableStep;
910
final isNextLineTable = isTable(lines: lines, index: index + 1);
1011
final isExamplesFormatted = hasExamplesFormat(bddLine: lines[index]);
@@ -17,13 +18,15 @@ bool hasBddDataTable(List<BddLine> lines) {
1718

1819
Iterable<BddLine> replaceDataTables(List<BddLine> lines) sync* {
1920
for (var index = 0; index < lines.length; index++) {
20-
final isStep = lines[index].type == LineType.step ||
21+
final isStep =
22+
lines[index].type == LineType.step ||
2123
lines[index].type == LineType.dataTableStep;
2224
final isNextLineTable = isTable(lines: lines, index: index + 1);
2325
if (isStep && isNextLineTable) {
24-
final table = !hasExamplesFormat(bddLine: lines[index])
25-
? _createCucumberDataTable(lines: lines, index: index)
26-
: _createDataTableFromExamples(lines: lines, index: index);
26+
final table =
27+
!hasExamplesFormat(bddLine: lines[index])
28+
? _createCucumberDataTable(lines: lines, index: index)
29+
: _createDataTableFromExamples(lines: lines, index: index);
2730
yield* table;
2831
// skip the parsed table
2932
while (isTable(lines: lines, index: index + 1)) {
@@ -38,8 +41,7 @@ Iterable<BddLine> replaceDataTables(List<BddLine> lines) sync* {
3841
bool isTable({
3942
required List<BddLine> lines,
4043
required int index,
41-
}) =>
42-
index < lines.length && lines[index].type == LineType.examples;
44+
}) => index < lines.length && lines[index].type == LineType.examples;
4345

4446
bool hasExamplesFormat({required BddLine bddLine}) =>
4547
examplesRegExp.firstMatch(bddLine.rawLine) != null;
@@ -75,8 +77,8 @@ Iterable<BddLine> _createDataTableFromExamples({
7577
final dataTable = [lines[index]];
7678
do {
7779
dataTable.add(lines[++index]);
78-
} while (
79-
index + 1 < lines.length && lines[index + 1].type == LineType.examples);
80+
} while (index + 1 < lines.length &&
81+
lines[index + 1].type == LineType.examples);
8082
final data = generateScenariosFromScenarioOutline([
8183
// pretend to be an Example section to re-use some logic
8284
BddLine.fromValue(LineType.exampleTitle, ''),

lib/src/existing_steps.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ Map<String, String> getExistingStepSubfolders(
2020
if (!steps.existsSync()) {
2121
return {};
2222
}
23-
return steps.listSync(recursive: true).asMap().map(
23+
return steps
24+
.listSync(recursive: true)
25+
.asMap()
26+
.map(
2427
(_, step) => MapEntry<String, String>(
2528
p.basename(step.path),
2629
p.dirname(

lib/src/feature_file.dart

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ class FeatureFile {
1818
this.includeIntegrationTestBinding = false,
1919
this.existingSteps = const <String, String>{},
2020
this.generatorOptions = const GeneratorOptions(),
21-
}) : _lines = _prepareLines(
22-
input.split('\n').map((line) => line.trim()).map(BddLine.new),
23-
),
24-
hookFile = generatorOptions.addHooks
25-
? HookFile.create(
26-
featureDir: featureDir,
27-
package: package,
28-
generatorOptions: generatorOptions,
29-
)
30-
: null {
21+
}) : _lines = _prepareLines(
22+
input.split('\n').map((line) => line.trim()).map(BddLine.new),
23+
),
24+
hookFile =
25+
generatorOptions.addHooks
26+
? HookFile.create(
27+
featureDir: featureDir,
28+
package: package,
29+
generatorOptions: generatorOptions,
30+
)
31+
: null {
3132
_testerType = parseCustomTagFromFeatureTagLine(
3233
_lines,
3334
generatorOptions.testerType,
@@ -40,23 +41,25 @@ class FeatureFile {
4041
testerNameTag,
4142
);
4243

43-
_stepFiles = _lines
44-
.where(
45-
(line) =>
46-
line.type == LineType.step || line.type == LineType.dataTableStep,
47-
)
48-
.map(
49-
(bddLine) => StepFile.create(
50-
featureDir,
51-
package,
52-
bddLine,
53-
existingSteps,
54-
generatorOptions,
55-
_testerType,
56-
_testerName,
57-
),
58-
)
59-
.toList();
44+
_stepFiles =
45+
_lines
46+
.where(
47+
(line) =>
48+
line.type == LineType.step ||
49+
line.type == LineType.dataTableStep,
50+
)
51+
.map(
52+
(bddLine) => StepFile.create(
53+
featureDir,
54+
package,
55+
bddLine,
56+
existingSteps,
57+
generatorOptions,
58+
_testerType,
59+
_testerName,
60+
),
61+
)
62+
.toList();
6063
}
6164

6265
late List<StepFile> _stepFiles;
@@ -75,52 +78,57 @@ class FeatureFile {
7578
final HookFile? hookFile;
7679

7780
String get dartContent => generateFeatureDart(
78-
_lines,
79-
getStepFiles(),
80-
generatorOptions.testMethodName,
81-
_testerType,
82-
_testerName,
83-
includeIntegrationTestBinding,
84-
includeIntegrationTestImport,
85-
hookFile,
86-
generatorOptions,
87-
);
81+
_lines,
82+
getStepFiles(),
83+
generatorOptions.testMethodName,
84+
_testerType,
85+
_testerName,
86+
includeIntegrationTestBinding,
87+
includeIntegrationTestImport,
88+
hookFile,
89+
generatorOptions,
90+
);
8891

8992
List<StepFile> getStepFiles() => _stepFiles;
9093

9194
static List<BddLine> _prepareLines(Iterable<BddLine> input) {
92-
final lines = input.mapIndexed(
93-
(index, bddLine) {
94-
final isStep = bddLine.type == LineType.step;
95-
final hasExamplesFormat = data_table_parser.hasExamplesFormat(
96-
bddLine: bddLine,
97-
);
98-
final isNextTable = data_table_parser.isTable(
99-
lines: input.toList(),
100-
index: index + 1,
101-
);
102-
if (isStep && !hasExamplesFormat && isNextTable) {
103-
return BddLine.fromRawValue(LineType.dataTableStep, bddLine.rawLine);
104-
} else {
105-
return bddLine;
106-
}
107-
},
108-
).toList(growable: false);
95+
final lines = input
96+
.mapIndexed(
97+
(index, bddLine) {
98+
final isStep = bddLine.type == LineType.step;
99+
final hasExamplesFormat = data_table_parser.hasExamplesFormat(
100+
bddLine: bddLine,
101+
);
102+
final isNextTable = data_table_parser.isTable(
103+
lines: input.toList(),
104+
index: index + 1,
105+
);
106+
if (isStep && !hasExamplesFormat && isNextTable) {
107+
return BddLine.fromRawValue(
108+
LineType.dataTableStep,
109+
bddLine.rawLine,
110+
);
111+
} else {
112+
return bddLine;
113+
}
114+
},
115+
)
116+
.toList(growable: false);
109117

110118
final headers = lines
111119
.takeWhile((value) => value.type != LineType.feature)
112120
.where((value) => value.type == LineType.unknown)
113121
.foldIndexed(
114-
// this removes empty line dupicates
115-
<BddLine>[],
116-
(index, headers, line) => [
117-
...headers,
118-
if (index == 0 && line.rawLine != '\n' && line.rawLine.isNotEmpty)
119-
line
120-
else if (headers.isNotEmpty && headers.last.rawLine != line.rawLine)
121-
line,
122-
],
123-
);
122+
// this removes empty line dupicates
123+
<BddLine>[],
124+
(index, headers, line) => [
125+
...headers,
126+
if (index == 0 && line.rawLine != '\n' && line.rawLine.isNotEmpty)
127+
line
128+
else if (headers.isNotEmpty && headers.last.rawLine != line.rawLine)
129+
line,
130+
],
131+
);
124132
final steps = lines.where((value) => value.type != LineType.unknown);
125133
return [...headers, ...steps];
126134
}

0 commit comments

Comments
 (0)