Skip to content

Commit 58831c2

Browse files
committed
#142: check maptype
1 parent 0a70ab6 commit 58831c2

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

test/writer/model_reader_test.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ TestModel:
9494
expect(error, isNotNull);
9595
expect(error, isArgumentError);
9696
if (error is ArgumentError) {
97-
expect(error.message, 'required is removed, follow the migration to version 7.0.0');
97+
expect(error.message,
98+
'required is removed, follow the migration to version 7.0.0');
9899
}
99100
});
100101

@@ -120,7 +121,8 @@ TestModel:
120121
expect(error, isNotNull);
121122
expect(error, isException);
122123
if (error is Exception) {
123-
expect(error.toString(), 'Exception: Could not generate all models. `array` is not added to the config file');
124+
expect(error.toString(),
125+
'Exception: Could not generate all models. `array` is not added to the config file');
124126
}
125127
});
126128

@@ -147,27 +149,34 @@ TestModel:
147149
expect(error, isNotNull);
148150
expect(error, isException);
149151
if (error is Exception) {
150-
expect(error.toString(), 'Exception: Could not generate all models. `map` is not added to the config file');
152+
expect(error.toString(),
153+
'Exception: Could not generate all models. `map` is not added to the config file');
151154
}
152155
});
153156

154157
test('Test simple generic fields', () {
155-
final models = YmlGeneratorConfig(
156-
PubspecConfig("name: test"),
157-
"""
158+
dynamic error;
159+
final config = YmlGeneratorConfig(
160+
PubspecConfig("name: test"),
161+
"""
158162
TestModel:
159163
properties:
160164
simpleStringList: List<string>
161165
nullableStringList: List<string>?
162166
simpleMap: Map<String, int>
163167
""",
164-
'')
165-
.models;
168+
'');
169+
final models = config.models;
166170

167171
expect(models.length, 1);
168172
final model = models.first;
169173
expect(model is ObjectModel, true);
170174
model as ObjectModel;
175+
try {
176+
config.checkIfTypesAvailable();
177+
} catch (e) {
178+
error = e;
179+
}
171180

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

182191
expect(simpleMap.type, isA<MapType>());
183192
expect(simpleMap.isRequired, true);
193+
194+
expect(error, isNull);
184195
});
185196
test('Test simple object reference fields', () {
186197
final models = YmlGeneratorConfig(
@@ -240,8 +251,9 @@ Gender:
240251
}
241252
expect(error, isNotNull);
242253
expect(error, isException);
243-
if(error is Exception){
244-
expect(error.toString(), 'Exception: item_type should be a string or integer. model: Gender');
254+
if (error is Exception) {
255+
expect(error.toString(),
256+
'Exception: item_type should be a string or integer. model: Gender');
245257
}
246258
});
247259
});

0 commit comments

Comments
 (0)