Skip to content

Commit

Permalink
Merge pull request #145 from icapps/feature/#142-up-test-coverage
Browse files Browse the repository at this point in the history
Feature/#142 up test coverage
  • Loading branch information
vanlooverenkoen committed Sep 7, 2023
2 parents 9525e23 + ede66f7 commit a444c7e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
12 changes: 9 additions & 3 deletions lib/run_process/run_process.dart
Expand Up @@ -6,7 +6,10 @@ class ProcessRunner {
ProcessRunner._();

static Future<void> runProcessVerbose(
String command, List<String> args) async {
String command,
List<String> args, [
void Function(String lines)? onLineWrite,
]) async {
print('\n$command ${args.join(' ')}\n');
final completer = Completer<void>();
final result = await Process.start(
Expand All @@ -16,8 +19,11 @@ class ProcessRunner {
);
print(
'======================================================================');
final subscription = result.stdout
.listen((codeUnits) => stdout.write(utf8.decode(codeUnits)));
final subscription = result.stdout.listen((codeUnits) {
final line = utf8.decode(codeUnits);
onLineWrite?.call(line);
stdout.write(line);
});
subscription.onDone(() {
print(
'======================================================================');
Expand Down
18 changes: 18 additions & 0 deletions test/run_process_test.dart
@@ -0,0 +1,18 @@
import 'package:model_generator/run_process/run_process.dart';
import 'package:test/test.dart';

void main() {
test('test run process', () async {
final lines = [];
await ProcessRunner.runProcessVerbose(
'echo',
[
'hello',
'world',
],
(line) => lines.add(line),
);

expect(lines.join('\n'), 'hello world\n');
});
}
50 changes: 45 additions & 5 deletions test/writer/model_reader_test.dart
Expand Up @@ -20,6 +20,7 @@ void main() {
PubspecConfig("name: test"),
"""
TestModel:
disallow_null_for_defaults: true
properties:
simpleString: string
nullableString: string?
Expand Down Expand Up @@ -65,6 +66,8 @@ TestModel:

expect(simpleDateTime.type, isA<DateTimeType>());
expect(simpleDateTime.isRequired, false);

expect(model.disallowNullForDefaults, true);
});

test('Test required not definable anymore', () {
Expand Down Expand Up @@ -152,22 +155,28 @@ TestModel:
});

test('Test simple generic fields', () {
final models = YmlGeneratorConfig(
PubspecConfig("name: test"),
"""
dynamic error;
final config = YmlGeneratorConfig(
PubspecConfig("name: test"),
"""
TestModel:
properties:
simpleStringList: List<string>
nullableStringList: List<string>?
simpleMap: Map<String, int>
""",
'')
.models;
'');
final models = config.models;

expect(models.length, 1);
final model = models.first;
expect(model is ObjectModel, true);
model as ObjectModel;
try {
config.checkIfTypesAvailable();
} catch (e) {
error = e;
}

final simpleStringList = model.fields.getByName("simpleStringList");
final nullableStringList = model.fields.getByName("nullableStringList");
Expand All @@ -181,6 +190,8 @@ TestModel:

expect(simpleMap.type, isA<MapType>());
expect(simpleMap.isRequired, true);

expect(error, isNull);
});
test('Test simple object reference fields', () {
final models = YmlGeneratorConfig(
Expand Down Expand Up @@ -216,6 +227,35 @@ TestModel2:
expect(nullableRef.type, isA<ObjectType>());
expect(nullableRef.isRequired, false);
});

test('Test enum item_type should be string or integer', () {
dynamic error;
try {
YmlGeneratorConfig(
PubspecConfig("name: test"),
"""
Gender:
path: user/person/
type: enum
item_type: List
properties:
MALE:
value: male
FEMALE:
value: female
""",
'')
.models;
} catch (e) {
error = e;
}
expect(error, isNotNull);
expect(error, isException);
if (error is Exception) {
expect(error.toString(),
'Exception: item_type should be a string or integer. model: Gender');
}
});
});
}

Expand Down

0 comments on commit a444c7e

Please sign in to comment.