@@ -6,8 +6,11 @@ import 'package:test/test.dart';
66
77/// it's necessary to read json model because the generated one doesn't contain all the information
88ModelInfo readModelJson (String dir) {
9- return ModelInfo .fromMap (json
10- .decode (File (path.join (dir, 'objectbox-model.json' )).readAsStringSync ()));
9+ return ModelInfo .fromMap (
10+ json.decode (
11+ File (path.join (dir, 'objectbox-model.json' )).readAsStringSync (),
12+ ),
13+ );
1114}
1215
1316/// Configures test cases to check that the model is specified correctly
@@ -20,19 +23,24 @@ commonModelTests(ModelDefinition defs, ModelInfo jsonModel) {
2023 test ('unique UIDs' , () {
2124 // collect UIDs on all entities and properties
2225 final allUIDs = defs.model.entities
23- .map ((entity) => < int > []
24- ..add (entity.id.uid)
25- ..addAll (entity.properties.map ((prop) => prop.id.uid))
26- ..addAll (entity.properties
27- .where ((prop) => prop.hasIndexFlag ())
28- .map ((prop) => prop.indexId! .uid))
29- ..addAll (entity.relations.map ((rel) => rel.id.uid)))
26+ .map (
27+ (entity) =>
28+ < int > []
29+ ..add (entity.id.uid)
30+ ..addAll (entity.properties.map ((prop) => prop.id.uid))
31+ ..addAll (
32+ entity.properties
33+ .where ((prop) => prop.hasIndexFlag ())
34+ .map ((prop) => prop.indexId! .uid),
35+ )
36+ ..addAll (entity.relations.map ((rel) => rel.id.uid)),
37+ )
3038 .reduce ((List <int > a, List <int > b) => a + b);
3139
3240 expect (allUIDs.toSet ().length, allUIDs.length);
3341 });
3442
35- final testLastId = (IdUid last, Iterable <IdUid > all, Iterable <int > retired) {
43+ Null testLastId (IdUid last, Iterable <IdUid > all, Iterable <int > retired) {
3644 if (last.isEmpty) return ;
3745 var amongAll = false ;
3846 for (final current in all) {
@@ -50,39 +58,50 @@ commonModelTests(ModelDefinition defs, ModelInfo jsonModel) {
5058 } else {
5159 expect (retired, isNot (contains (last.uid)));
5260 }
53- };
61+ }
5462
5563 test ('lastPropertyId' , () {
5664 for (final entity in defs.model.entities) {
57- testLastId (entity.lastPropertyId, entity.properties.map ((el) => el.id),
58- jsonModel.retiredPropertyUids);
65+ testLastId (
66+ entity.lastPropertyId,
67+ entity.properties.map ((el) => el.id),
68+ jsonModel.retiredPropertyUids,
69+ );
5970 }
6071 });
6172
6273 test ('lastEntityId' , () {
63- testLastId (defs.model.lastEntityId, defs.model.entities.map ((el) => el.id),
64- jsonModel.retiredEntityUids);
74+ testLastId (
75+ defs.model.lastEntityId,
76+ defs.model.entities.map ((el) => el.id),
77+ jsonModel.retiredEntityUids,
78+ );
6579 });
6680
6781 test ('lastIndexId' , () {
6882 testLastId (
69- defs.model.lastIndexId,
70- defs.model.entities
71- .map ((ModelEntity e) => e.properties
72- .where ((p) => p.hasIndexFlag ())
73- .map ((p) => p.indexId! )
74- .toList ())
75- .reduce ((List <IdUid > a, List <IdUid > b) => a + b),
76- jsonModel.retiredIndexUids);
83+ defs.model.lastIndexId,
84+ defs.model.entities
85+ .map (
86+ (ModelEntity e) =>
87+ e.properties
88+ .where ((p) => p.hasIndexFlag ())
89+ .map ((p) => p.indexId! )
90+ .toList (),
91+ )
92+ .reduce ((List <IdUid > a, List <IdUid > b) => a + b),
93+ jsonModel.retiredIndexUids,
94+ );
7795 });
7896
7997 test ('lastRelationId' , () {
8098 testLastId (
81- defs.model.lastRelationId,
82- defs.model.entities
83- .map ((ModelEntity e) => e.relations.map ((r) => r.id).toList ())
84- .reduce ((List <IdUid > a, List <IdUid > b) => a + b),
85- jsonModel.retiredRelationUids);
99+ defs.model.lastRelationId,
100+ defs.model.entities
101+ .map ((ModelEntity e) => e.relations.map ((r) => r.id).toList ())
102+ .reduce ((List <IdUid > a, List <IdUid > b) => a + b),
103+ jsonModel.retiredRelationUids,
104+ );
86105 });
87106}
88107
@@ -92,7 +111,8 @@ ModelEntity entity(ModelInfo model, String name) {
92111
93112ModelProperty property (ModelInfo model, String path) {
94113 final components = path.split ('.' );
95- return entity (model, components[0 ])
96- .properties
97- .firstWhere ((ModelProperty p) => p.name == components[1 ]);
114+ return entity (
115+ model,
116+ components[0 ],
117+ ).properties.firstWhere ((ModelProperty p) => p.name == components[1 ]);
98118}
0 commit comments