Skip to content

Commit

Permalink
RDART-960 Fix generated _fromEJson on Realm models (#1543)
Browse files Browse the repository at this point in the history
* Fix bug wrt. argument to Process.start

* Remove redundant argument. Handled by cmake preset

* Fix issue with ejson serialization skipping collections

This is done by restoring sanity to allSettable,
required, and nonRequired fields.

This also fixes an unnecessary reordering of nonRequired
fields, where collections was always at the back, and
ordered list, set, then map.

This commit also fixes a blemish regarding initializers.
Since field initializers become ctor parameter initializers
they need to be constant. For now we only allow literals.

* Fix good tests

* Add extra error test for const initializers

* Update realm_dart after realm_generator fix

* Fix dynamic tests regression
  • Loading branch information
nielsenko authored Mar 7, 2024
1 parent eca576b commit 8714f74
Show file tree
Hide file tree
Showing 29 changed files with 298 additions and 126 deletions.
6 changes: 4 additions & 2 deletions packages/realm_dart/test/backlinks_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/realm_dart/test/dynamic_realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

// ignore_for_file: avoid_relative_lib_imports

import 'dart:ffi';
import 'dart:typed_data';

import 'package:test/test.dart' hide test, throws;
import 'package:realm_dart/realm.dart';

Expand Down Expand Up @@ -72,7 +75,7 @@ void main() {
final objectId = ObjectId();
final uuid = Uuid.v4();

AllTypes _getPopulatedAllTypes() => AllTypes('abc', true, date, -123.456, objectId, uuid, -987, Decimal128.fromDouble(42),
AllTypes _getPopulatedAllTypes() => AllTypes('abc', true, date, -123.456, objectId, uuid, -987, Decimal128.fromDouble(42), Uint8List.fromList([1, 2, 3]),
nullableStringProp: 'def',
nullableBoolProp: true,
nullableDateProp: date,
Expand All @@ -82,7 +85,7 @@ void main() {
nullableIntProp: 123,
nullableDecimalProp: Decimal128.fromDouble(4242));

AllTypes _getEmptyAllTypes() => AllTypes('', false, DateTime(0).toUtc(), 0, objectId, uuid, 0, Decimal128.zero);
AllTypes _getEmptyAllTypes() => AllTypes('', false, DateTime(0).toUtc(), 0, objectId, uuid, 0, Decimal128.zero, Uint8List(16));

AllCollections _getPopulatedAllCollections() => AllCollections(
stringList: ['abc', 'def'],
Expand Down
5 changes: 4 additions & 1 deletion packages/realm_dart/test/geospatial_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions packages/realm_dart/test/realm_map_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions packages/realm_dart/test/realm_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void main() {
final config = Configuration.local([AllTypes.schema]);
final realm = getRealm(config);
final obj = realm.write(() {
return realm.add(AllTypes('', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
return realm.add(AllTypes('', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
});

final json = obj.toJson();
Expand Down Expand Up @@ -462,7 +462,7 @@ void main() {
expect(date.isUtc, isFalse);

final obj = realm.write(() {
return realm.add(AllTypes('', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
return realm.add(AllTypes('', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
});

final json = obj.toJson();
Expand All @@ -479,8 +479,8 @@ void main() {
final date = DateTime.now();

realm.write(() {
realm.add(AllTypes('abc', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
realm.add(AllTypes('cde', false, DateTime.now().add(Duration(seconds: 1)), 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
realm.add(AllTypes('abc', false, date, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
realm.add(AllTypes('cde', false, DateTime.now().add(Duration(seconds: 1)), 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
});

var results = realm.all<AllTypes>().query('dateProp = \$0', [date]);
Expand All @@ -497,9 +497,9 @@ void main() {
final date3 = date1.subtract(Duration(microseconds: 1));

realm.write(() {
realm.add(AllTypes('1', false, date1, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
realm.add(AllTypes('2', false, date2, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
realm.add(AllTypes('3', false, date3, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one));
realm.add(AllTypes('1', false, date1, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
realm.add(AllTypes('2', false, date2, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
realm.add(AllTypes('3', false, date3, 0, ObjectId(), Uuid.v4(), 0, Decimal128.one, Uint8List(16)));
});

final lessThan1 = realm.all<AllTypes>().query('dateProp < \$0', [date1]);
Expand All @@ -524,7 +524,7 @@ void main() {
var uuid = Uuid.v4();

final object = realm.write(() {
return realm.add(AllTypes('cde', false, date, 0.1, objectId, uuid, 4, Decimal128.ten, binaryProp: Uint8List.fromList([1, 2]), nullableBinaryProp: null));
return realm.add(AllTypes('cde', false, date, 0.1, objectId, uuid, 4, Decimal128.ten, Uint8List.fromList([1, 2]), nullableBinaryProp: null));
});

expect(object.stringProp, 'cde');
Expand Down
18 changes: 18 additions & 0 deletions packages/realm_dart/test/realm_set_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/realm_dart/test/realm_value_test.realm.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/realm_dart/test/results_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ void main() {
final config = Configuration.local([AllTypes.schema]);
Realm realm = getRealm(config);
realm.write(() => realm.addAll([
AllTypes(text_1, false, DateTime.now(), 1.1, id_1, uid_1, 1, Decimal128.one, binaryProp: Uint8List.fromList([1, 2])),
AllTypes('text2', true, date_1, 2.2, id_2, uid_2, 2, Decimal128.ten),
AllTypes('text3', true, date_2, 3.3, ObjectId(), Uuid.v4(), 3, Decimal128.infinity, binaryProp: Uint8List.fromList([3, 4])),
AllTypes(text_1, false, DateTime.now(), 1.1, id_1, uid_1, 1, Decimal128.one, Uint8List.fromList([1, 2])),
AllTypes('text2', true, date_1, 2.2, id_2, uid_2, 2, Decimal128.ten, Uint8List(16)),
AllTypes('text3', true, date_2, 3.3, ObjectId(), Uuid.v4(), 3, Decimal128.infinity, Uint8List.fromList([3, 4])),
]));

void queryWithListArg(String propName, Object? argument, {int expected = 0}) {
Expand Down
3 changes: 1 addition & 2 deletions packages/realm_dart/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class _Schedule {
@RealmModel()
class _Foo {
late Uint8List requiredBinaryProp;
var defaultValueBinaryProp = Uint8List(8);
late Uint8List? nullableBinaryProp;
}

Expand All @@ -123,7 +122,7 @@ class _AllTypes {
late Uuid uuidProp;
late int intProp;
late Decimal128 decimalProp;
var binaryProp = Uint8List(16);
late Uint8List binaryProp;

late String? nullableStringProp;
late bool? nullableBoolProp;
Expand Down
Loading

0 comments on commit 8714f74

Please sign in to comment.