Skip to content

Commit

Permalink
#142: check maptype
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Sep 1, 2023
1 parent 0a70ab6 commit 58831c2
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions test/writer/model_reader_test.dart
Expand Up @@ -94,7 +94,8 @@ TestModel:
expect(error, isNotNull);
expect(error, isArgumentError);
if (error is ArgumentError) {
expect(error.message, 'required is removed, follow the migration to version 7.0.0');
expect(error.message,
'required is removed, follow the migration to version 7.0.0');
}
});

Expand All @@ -120,7 +121,8 @@ TestModel:
expect(error, isNotNull);
expect(error, isException);
if (error is Exception) {
expect(error.toString(), 'Exception: Could not generate all models. `array` is not added to the config file');
expect(error.toString(),
'Exception: Could not generate all models. `array` is not added to the config file');
}
});

Expand All @@ -147,27 +149,34 @@ TestModel:
expect(error, isNotNull);
expect(error, isException);
if (error is Exception) {
expect(error.toString(), 'Exception: Could not generate all models. `map` is not added to the config file');
expect(error.toString(),
'Exception: Could not generate all models. `map` is not added to the config file');
}
});

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 @@ -240,8 +251,9 @@ Gender:
}
expect(error, isNotNull);
expect(error, isException);
if(error is Exception){
expect(error.toString(), 'Exception: item_type should be a string or integer. model: Gender');
if (error is Exception) {
expect(error.toString(),
'Exception: item_type should be a string or integer. model: Gender');
}
});
});
Expand Down

0 comments on commit 58831c2

Please sign in to comment.