Skip to content

Commit

Permalink
#130: added enum model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Sep 4, 2023
1 parent cc1a73a commit 3b228ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/writer/enum_model_writer/pubspec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: model_generator_example

model_generator:
config_path: model_generator/config.yaml
41 changes: 40 additions & 1 deletion test/writer/enum_model_writer_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import 'dart:io';

import 'package:model_generator/config/pubspec_config.dart';
import 'package:model_generator/config/yml_generator_config.dart';
import 'package:model_generator/model/model/enum_model.dart';
import 'package:model_generator/writer/enum_model_writer.dart';
import 'package:test/test.dart';

void main() {
group('EnumModel', () {});
void testEnumModelWriter(String path) {
final file = File('$path/output.txt');
final pubspecFile = File('test/writer/enum_model_writer/pubspec.txt');
final configFile = File('$path/config.txt');
final expected = file.readAsStringSync();
final pubspecContent = pubspecFile.readAsStringSync();
final configContent = configFile.readAsStringSync();
final pubspecConfig = PubspecConfig(pubspecContent);
final ymlConfig = YmlGeneratorConfig(pubspecConfig, configContent, '');
final jsonModel = ymlConfig.models.first;
if (jsonModel is! EnumModel) {
throw Exception('The first model in the config file must be an object model and will be validated. The model is ${ymlConfig.models.first.runtimeType}');
}

final generateActual = EnumModelWriter(jsonModel).write;
if (expected.startsWith('Exception')) {
expect(generateActual, throwsA(isA<Exception>()));
} else {
expect(generateActual(), expected);
}
}

group('EnumModelWriter test', () {
final directory = Directory('test/writer/enum_model_writer');
final folders = directory.listSync();
for (final folder in folders) {
if (folder is Directory) {
test('Folder ${folder.path}', () {
print('Testing folder ${folder.path}');
testEnumModelWriter(folder.path);
});
}
}
});
}

0 comments on commit 3b228ec

Please sign in to comment.