Skip to content

Commit 1822dc0

Browse files
Merge branch '152-generator-min-dart-3.7' into 'main'
Follow-up: format generator code with Dart 3.7 rules #152 See merge request objectbox/objectbox-dart!110
2 parents 3761429 + ade5b73 commit 1822dc0

File tree

21 files changed

+1092
-689
lines changed

21 files changed

+1092
-689
lines changed

generator/integration-tests/basics/1.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ void main() {
3434
expect(entity(model, 'D').flags, equals(OBXEntityFlags.SYNC_ENABLED));
3535
expect(entity(jsonModel, 'D').flags, equals(OBXEntityFlags.SYNC_ENABLED));
3636

37-
expect(entity(model, 'E').flags,
38-
equals(OBXEntityFlags.SYNC_ENABLED | OBXEntityFlags.SHARED_GLOBAL_IDS));
39-
expect(entity(jsonModel, 'E').flags,
40-
equals(OBXEntityFlags.SYNC_ENABLED | OBXEntityFlags.SHARED_GLOBAL_IDS));
37+
expect(
38+
entity(model, 'E').flags,
39+
equals(OBXEntityFlags.SYNC_ENABLED | OBXEntityFlags.SHARED_GLOBAL_IDS),
40+
);
41+
expect(
42+
entity(jsonModel, 'E').flags,
43+
equals(OBXEntityFlags.SYNC_ENABLED | OBXEntityFlags.SHARED_GLOBAL_IDS),
44+
);
4145
});
4246

4347
test('types', () {
@@ -76,7 +80,9 @@ void main() {
7680

7781
expect(property(model, 'T.tDoubleList').type, OBXPropertyType.DoubleVector);
7882
expect(
79-
property(model, 'T.tFloat64List').type, OBXPropertyType.DoubleVector);
83+
property(model, 'T.tFloat64List').type,
84+
OBXPropertyType.DoubleVector,
85+
);
8086

8187
expect(property(model, 'T.tListString').type, OBXPropertyType.StringVector);
8288

generator/integration-tests/basics/lib/other.dart

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,37 @@ class NonNullA {
7474
List<String> tListString;
7575

7676
NonNullA(
77-
this.id,
78-
this.tBool,
79-
this.tByte,
80-
this.tShort,
81-
this.tChar,
82-
this.tDate,
83-
this.tDateNano,
84-
this.tListInt,
85-
this.tInt8List,
86-
this.tUint8List,
87-
this.tCharList,
88-
this.tShortList,
89-
this.tInt16List,
90-
this.tUint16List,
91-
this.tIntList,
92-
this.tInt32List,
93-
this.tUint32List,
94-
this.tLongList,
95-
this.tInt64List,
96-
this.tUint64List,
97-
this.tFloatList,
98-
this.tFloat32List,
99-
this.tDoubleList,
100-
this.tFloat64List,
101-
this.tListString,
102-
[this.tInt = 0,
103-
this.tLong = 0,
104-
this.tFloat = 0,
105-
int unknown = 42, // breaks up here, the remaining params use cascade
106-
this.tDouble = 0]);
77+
this.id,
78+
this.tBool,
79+
this.tByte,
80+
this.tShort,
81+
this.tChar,
82+
this.tDate,
83+
this.tDateNano,
84+
this.tListInt,
85+
this.tInt8List,
86+
this.tUint8List,
87+
this.tCharList,
88+
this.tShortList,
89+
this.tInt16List,
90+
this.tUint16List,
91+
this.tIntList,
92+
this.tInt32List,
93+
this.tUint32List,
94+
this.tLongList,
95+
this.tInt64List,
96+
this.tUint64List,
97+
this.tFloatList,
98+
this.tFloat32List,
99+
this.tDoubleList,
100+
this.tFloat64List,
101+
this.tListString, [
102+
this.tInt = 0,
103+
this.tLong = 0,
104+
this.tFloat = 0,
105+
int unknown = 42, // breaks up here, the remaining params use cascade
106+
this.tDouble = 0,
107+
]);
107108
}
108109

109110
/// Entity with non-null properties and constructor with named optional parameters.
@@ -176,35 +177,37 @@ class NonNullB {
176177

177178
List<String> tListString;
178179

179-
NonNullB(this.id,
180-
{required this.tBool,
181-
required this.tByte,
182-
required this.tShort,
183-
required this.tChar,
184-
required this.tInt,
185-
required this.tFloat,
186-
required this.tDouble,
187-
required this.tString,
188-
required this.tDate,
189-
required this.tDateNano,
190-
required this.tListInt,
191-
required this.tInt8List,
192-
required this.tUint8List,
193-
required this.tCharList,
194-
required this.tShortList,
195-
required this.tInt16List,
196-
required this.tUint16List,
197-
required this.tIntList,
198-
required this.tInt32List,
199-
required this.tUint32List,
200-
required this.tLongList,
201-
required this.tInt64List,
202-
required this.tUint64List,
203-
required this.tFloatList,
204-
required this.tFloat32List,
205-
required this.tDoubleList,
206-
required this.tFloat64List,
207-
required this.tListString,
208-
int unknown = 42, // skipped, but continues using the constructor
209-
required this.tLong});
180+
NonNullB(
181+
this.id, {
182+
required this.tBool,
183+
required this.tByte,
184+
required this.tShort,
185+
required this.tChar,
186+
required this.tInt,
187+
required this.tFloat,
188+
required this.tDouble,
189+
required this.tString,
190+
required this.tDate,
191+
required this.tDateNano,
192+
required this.tListInt,
193+
required this.tInt8List,
194+
required this.tUint8List,
195+
required this.tCharList,
196+
required this.tShortList,
197+
required this.tInt16List,
198+
required this.tUint16List,
199+
required this.tIntList,
200+
required this.tInt32List,
201+
required this.tUint32List,
202+
required this.tLongList,
203+
required this.tInt64List,
204+
required this.tUint64List,
205+
required this.tFloatList,
206+
required this.tFloat32List,
207+
required this.tDoubleList,
208+
required this.tFloat64List,
209+
required this.tListString,
210+
int unknown = 42, // skipped, but continues using the constructor
211+
required this.tLong,
212+
});
210213
}

generator/integration-tests/changes/2.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ void main() {
6262
}
6363

6464
boxA.put(A()..text2 = 'bar');
65-
boxA.put(A()
66-
..text1 = 'lorem'
67-
..text2 = 'ipsum');
65+
boxA.put(
66+
A()
67+
..text1 = 'lorem'
68+
..text2 = 'ipsum',
69+
);
6870
boxB.put(B()..value = true);
6971

7072
store.close();

generator/integration-tests/common.dart

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
88
ModelInfo 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

93112
ModelProperty 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
}

generator/integration-tests/final/1.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,29 @@ void main() {
4848
expect(box.count(), 0);
4949

5050
expect(
51-
() => box.put(
52-
A(0, 0, 0, '', 0, 0, [], Uint8List(0), [], false, Int8List(0))),
53-
throwsA(predicate((ArgumentError e) =>
54-
e.toString().contains('You must assign an ID'))));
51+
() => box.put(
52+
A(0, 0, 0, '', 0, 0, [], Uint8List(0), [], false, Int8List(0)),
53+
),
54+
throwsA(
55+
predicate(
56+
(ArgumentError e) => e.toString().contains('You must assign an ID'),
57+
),
58+
),
59+
);
5560

56-
final inserted = A(42, 1, 2, 'foo', 3, 4, [5, 6], Uint8List(1),
57-
['foo', 'bar'], true, Int8List(2));
61+
final inserted = A(
62+
42,
63+
1,
64+
2,
65+
'foo',
66+
3,
67+
4,
68+
[5, 6],
69+
Uint8List(1),
70+
['foo', 'bar'],
71+
true,
72+
Int8List(2),
73+
);
5874
box.put(inserted);
5975
final read = box.get(inserted.id)!;
6076
expect(read.tBool, inserted.tBool);

generator/integration-tests/final/lib/lib.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ class A {
2222
final List<String> tListString;
2323

2424
A(
25-
this.id,
26-
this.tLong,
27-
this.tDouble,
28-
this.tString,
29-
this.tDate,
30-
this.tDateNano,
31-
this.tListInt,
32-
this.tUint8List,
33-
this.tListString,
34-
bool tBool,
35-
Int8List tInt8List)
36-
: tBool = tBool,
37-
tInt8List = tInt8List;
25+
this.id,
26+
this.tLong,
27+
this.tDouble,
28+
this.tString,
29+
this.tDate,
30+
this.tDateNano,
31+
this.tListInt,
32+
this.tUint8List,
33+
this.tListString,
34+
bool tBool,
35+
Int8List tInt8List,
36+
) : tBool = tBool,
37+
tInt8List = tInt8List;
3838
}
3939

4040
// Test getters and setters with a private field. Let's make the getter and the

generator/integration-tests/getters/1.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ void main() {
3535
expect(prop.type, OBXPropertyType.Int);
3636
expect(prop.flags, OBXPropertyFlags.INDEXED);
3737
// @Transient on getter ignores property
38-
expect(() => property(model, 'AnnotatedGetters.ignored'),
39-
throwsA(isStateError));
38+
expect(
39+
() => property(model, 'AnnotatedGetters.ignored'),
40+
throwsA(isStateError),
41+
);
4042
});
4143
}

0 commit comments

Comments
 (0)