Skip to content

Commit

Permalink
🎨 Split run and expect
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Jun 18, 2024
1 parent 182f4fc commit e708ebf
Showing 1 changed file with 88 additions and 28 deletions.
116 changes: 88 additions & 28 deletions packages/core/test/gen_test_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,128 @@ import 'package:test/test.dart';

Future<void> clearTestResults() async {}

/// Assets
Future<void> expectedAssetsGen(
String pubspec, String generated, String fact) async {
await FlutterGenerator(File(pubspec), assetsName: p.basename(generated))
.build();
Future<List<String>> runAssetsGen(
String pubspec,
String generated,
String fact,
) async {
await FlutterGenerator(
File(pubspec),
assetsName: p.basename(generated),
).build();

final pubspecFile = File(pubspec);
final config = loadPubspecConfig(pubspecFile);
final formatter = DartFormatter(
pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n');
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);

final actual = generateAssets(
AssetsGenConfig.fromConfig(pubspecFile, config), formatter);
final expected =
formatter.format(File(fact).readAsStringSync().replaceAll('\r\n', '\n'));
AssetsGenConfig.fromConfig(pubspecFile, config),
formatter,
);
final expected = formatter.format(
File(fact).readAsStringSync().replaceAll('\r\n', '\n'),
);
return [actual, expected];
}

/// Assets
Future<void> expectedAssetsGen(
String pubspec,
String generated,
String fact,
) async {
final results = await runAssetsGen(pubspec, generated, fact);
final actual = results.first, expected = results.last;
expect(
File(generated).readAsStringSync(),
isNotEmpty,
);
expect(actual, expected);
}

/// Colors
Future<void> expectedColorsGen(
String pubspec, String generated, String fact) async {
await FlutterGenerator(File(pubspec), colorsName: p.basename(generated))
.build();
Future<List<String>> runColorsGen(
String pubspec,
String generated,
String fact,
) async {
await FlutterGenerator(
File(pubspec),
colorsName: p.basename(generated),
).build();

final pubspecFile = File(pubspec);
final config = loadPubspecConfig(pubspecFile);
final formatter = DartFormatter(
pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n');
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);

final actual =
generateColors(pubspecFile, formatter, config.pubspec.flutterGen.colors);
final expected =
formatter.format(File(fact).readAsStringSync().replaceAll('\r\n', '\n'));
final actual = generateColors(
pubspecFile,
formatter,
config.pubspec.flutterGen.colors,
);
final expected = formatter.format(
File(fact).readAsStringSync().replaceAll('\r\n', '\n'),
);
return [actual, expected];
}

/// Colors
Future<void> expectedColorsGen(
String pubspec,
String generated,
String fact,
) async {
final results = await runColorsGen(pubspec, generated, fact);
final actual = results.first, expected = results.last;
expect(
File(generated).readAsStringSync(),
isNotEmpty,
);
expect(actual, expected);
}

/// Fonts
Future<void> expectedFontsGen(
String pubspec, String generated, String fact) async {
await FlutterGenerator(File(pubspec), fontsName: p.basename(generated))
.build();
Future<List<String>> runFontsGen(
String pubspec,
String generated,
String fact,
) async {
await FlutterGenerator(
File(pubspec),
fontsName: p.basename(generated),
).build();

final pubspecFile = File(pubspec);
final config = loadPubspecConfig(pubspecFile);
final formatter = DartFormatter(
pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n');
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);

final actual = generateFonts(
formatter, config.pubspec.flutter.fonts, config.pubspec.flutterGen.fonts);
final expected =
formatter.format(File(fact).readAsStringSync().replaceAll('\r\n', '\n'));
formatter,
config.pubspec.flutter.fonts,
config.pubspec.flutterGen.fonts,
);
final expected = formatter.format(
File(fact).readAsStringSync().replaceAll('\r\n', '\n'),
);

return [actual, expected];
}

/// Fonts
Future<void> expectedFontsGen(
String pubspec,
String generated,
String fact,
) async {
final results = await runFontsGen(pubspec, generated, fact);
final actual = results.first, expected = results.last;
expect(
File(generated).readAsStringSync(),
isNotEmpty,
Expand Down

0 comments on commit e708ebf

Please sign in to comment.