-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
}); | ||
} |