Started filter embedded test
ADD
packages/isar_test/test/filter/filter_embedded_list_test.dart
+// ignore_for_file: hash_and_equals
+
+import 'package:isar/isar.dart';
+import 'package:test/test.dart';
+
+import '../util/common.dart';
+import '../util/matchers.dart';
+import '../util/sync_async_helper.dart';
+
+part 'filter_embedded_list_test.g.dart';
+
+@collection
+class Model {
+ Model({
+ required this.embeddedAs,
+ required this.embeddedBs,
+ });
+
+ Id id = Isar.autoIncrement;
+
+ List<EmbeddedA> embeddedAs;
+
+ List<EmbeddedB?>? embeddedBs;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is Model &&
+ runtimeType == other.runtimeType &&
+ id == other.id &&
+ listEquals(embeddedAs, other.embeddedAs) &&
+ listEquals(embeddedBs, other.embeddedBs);
+
+ @override
+ String toString() {
+ return 'Model{id: $id, embeddedAs: $embeddedAs, embeddedBs: $embeddedBs}';
+ }
+}
+
+@embedded
+class EmbeddedA {
+ EmbeddedA({
+ this.name = '',
+ this.embeddedBs = const [],
+ });
+
+ String name;
+
+ final List<EmbeddedB?>? embeddedBs;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is EmbeddedA &&
+ runtimeType == other.runtimeType &&
+ name == other.name &&
+ listEquals(embeddedBs, other.embeddedBs);
+
+ @override
+ String toString() {
+ return 'EmbeddedA{name: $name, embeddedBs: $embeddedBs}';
+ }
+}
+
+@embedded
+class EmbeddedB {
+ EmbeddedB({
+ this.name = '',
+ });
+
+ String name;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is EmbeddedB &&
+ runtimeType == other.runtimeType &&
+ name == other.name;
+
+ @override
+ String toString() {
+ return 'EmbeddedB{name: $name}';
+ }
+}
+
+void main() {
+ group('Filter embedded list', () {
+ late Isar isar;
+
+ late Model obj1;
+ late Model obj2;
+ late Model obj3;
+ late Model obj4;
+ late Model obj5;
+ late Model obj6;
+
+ setUp(() async {
+ isar = await openTempIsar([ModelSchema]);
+
+ obj1 = Model(
+ embeddedAs: [
+ EmbeddedA(
+ name: 'embedded a1 - 1',
+ embeddedBs: null,
+ ),
+ EmbeddedA(
+ name: 'embedded a1 - 2',
+ embeddedBs: [null, null],
+ ),
+ EmbeddedA(
+ name: 'embedded a1 - 3',
+ embeddedBs: [
+ EmbeddedB(
+ name: 'embedded a1 b1 - 1',
+ ),
+ EmbeddedB(
+ name: 'embedded a1 b1 - 2',
+ ),
+ EmbeddedB(
+ name: 'embedded a1 b1 - 3',
+ ),
+ ],
+ ),
+ ],
+ embeddedBs: [
+ EmbeddedB(name: 'embedded b1 - 1'),
+ EmbeddedB(name: 'embedded b1 - 2'),
+ EmbeddedB(name: 'embedded b1 - 3'),
+ ],
+ );
+ obj2 = Model(
+ embeddedAs: [
+ EmbeddedA(
+ name: 'embedded a2 - 1',
+ embeddedBs: null,
+ ),
+ ],
+ embeddedBs: [null],
+ );
+ obj3 = Model(
+ embeddedAs: [
+ EmbeddedA(
+ name: 'embedded a3 - 1',
+ embeddedBs: [
+ null,
+ EmbeddedB(name: 'embedded a3 b3 - 1'),
+ ],
+ ),
+ ],
+ embeddedBs: null,
+ );
+ obj4 = Model(
+ embeddedAs: [],
+ embeddedBs: [],
+ );
+ obj5 = Model(
+ embeddedAs: [
+ EmbeddedA(
+ name: 'embedded a5 - 1',
+ embeddedBs: [
+ EmbeddedB(name: 'embedded a5 b5 - 1'),
+ EmbeddedB(name: 'embedded a5 b5 - 2'),
+ EmbeddedB(name: 'embedded a5 b5 - 3'),
+ EmbeddedB(name: 'embedded a5 b5 - 4'),
+ EmbeddedB(name: 'embedded a5 b5 - 5'),
+ ],
+ ),
+ ],
+ embeddedBs: [
+ EmbeddedB(name: 'embedded b5 - 1'),
+ EmbeddedB(name: 'embedded b5 - 2'),
+ EmbeddedB(name: 'embedded b5 - 3'),
+ EmbeddedB(name: 'embedded b5 - 4'),
+ EmbeddedB(name: 'embedded b5 - 5'),
+ ],
+ );
+ obj6 = Model(
+ embeddedAs: [
+ EmbeddedA(
+ name: 'embedded a6 - 1',
+ embeddedBs: [
+ EmbeddedB(name: 'embedded a6 b6 - 1'),
+ null,
+ null,
+ null,
+ ],
+ ),
+ ],
+ embeddedBs: [
+ null,
+ EmbeddedB(name: 'embedded b6 - 1'),
+ null,
+ ],
+ );
+
+ await isar.tWriteTxn(
+ () => isar.models.tPutAll([
+ obj1,
+ obj2,
+ obj3,
+ obj4,
+ obj5,
+ obj6,
+ ]),
+ );
+ });
+
+ isarTest('.embeddedIsNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBsIsNull(),
+ [obj3],
+ );
+ });
+
+ isarTest('.embeddedIsNotNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBsIsNotNull(),
+ [obj1, obj2, obj4, obj5, obj6],
+ );
+ });
+
+ isarTest('.embeddedLengthEqualTo()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthEqualTo(0),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthEqualTo(1),
+ [obj2, obj3, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthEqualTo(3),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthEqualTo(4),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(0),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(1),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(2),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(3),
+ [obj1, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(4),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(5),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthEqualTo(6),
+ [],
+ );
+ });
+
+ isarTest('.embeddedLengthGreaterThan()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthGreaterThan(0),
+ [obj1, obj2, obj3, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthGreaterThan(1),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthGreaterThan(2),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthGreaterThan(3, include: true),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthGreaterThan(3),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(0),
+ [obj1, obj2, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(1),
+ [obj1, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(2),
+ [obj1, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(3),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(4),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(5, include: true),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthGreaterThan(5),
+ [],
+ );
+ });
+
+ isarTest('.embeddedLengthLessThanThan()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(0),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(1),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(2),
+ [obj2, obj3, obj4, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(3),
+ [obj2, obj3, obj4, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(3),
+ [obj2, obj3, obj4, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthLessThan(3, include: true),
+ [obj1, obj2, obj3, obj4, obj5, obj6],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(0),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(1),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(2),
+ [obj2, obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(3),
+ [obj2, obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(4),
+ [obj1, obj2, obj4, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(5),
+ [obj1, obj2, obj4, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthLessThan(5, include: true),
+ [obj1, obj2, obj4, obj5, obj6],
+ );
+ });
+
+ isarTest('.embeddedLengthBetweenThan()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthBetween(1, 3),
+ [obj1, obj2, obj3, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthBetween(3, 4),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsLengthBetween(10, 12),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthBetween(1, 3),
+ [obj1, obj2, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthBetween(3, 4),
+ [obj1, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsLengthBetween(10, 12),
+ [],
+ );
+ });
+
+ isarTest('.embeddedIsEmpty()', () async {});
+ isarTest('.embeddedIsNotEmpty()', () async {});
+
+ // FIXME: IsarError: Unsupported type for condition
+ isarTest('.embeddedElementEqualTo()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj1.embeddedAs[0]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj1.embeddedAs[1]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj1.embeddedAs[2]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj2.embeddedAs[0]),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj3.embeddedAs[0]),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj5.embeddedAs[0]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElementEqualTo(obj6.embeddedAs[0]),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElementEqualTo(EmbeddedA(name: 'non existing')),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj1.embeddedBs![0]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj1.embeddedBs![1]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj1.embeddedBs![2]),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj5.embeddedBs![0]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj5.embeddedBs![1]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj5.embeddedBs![2]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj5.embeddedBs![3]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj5.embeddedBs![4]),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementEqualTo(obj6.embeddedBs![1]),
+ [obj6],
+ );
+ });
+
+ // FIXME: IsarError: IllegalArg: Property does not support this filter..
+ isarTest('.embeddedElementIsNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementIsNull(),
+ [obj2, obj6],
+ );
+ });
+
+ // FIXME: IsarError: IllegalArg: Property does not support this filter..
+ isarTest('.embeddedElementIsNotNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBsElementIsNotNull(),
+ [obj1, obj5, obj6],
+ );
+ });
+
+ isarTest('.embeddedElement()', () async {
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameStartsWith('embedded')),
+ [obj1, obj2, obj3, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a1 - 1')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a1 - 2')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a1 - 3')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a2 - 1')),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a3 - 1')),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a5 - 1')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('embedded a6 - 1')),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedAsElement((q) => q.nameEqualTo('non existing')),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameStartsWith('embedded')),
+ [obj1, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b1 - 1')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b1 - 2')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b1 - 3')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b5 - 1')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b5 - 2')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b5 - 3')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b5 - 4')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b5 - 5')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('embedded b6 - 1')),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedBsElement((q) => q.nameEqualTo('non existing')),
+ [],
+ );
+ });
+
+ isarTest('.embeddedElement() then .embeddedIsNull()', () async {});
+ isarTest('.embeddedElement() then .embeddedIsNotNull()', () async {});
+ isarTest('.embeddedElement() then .embeddedLengthEqualTo()', () async {});
+ isarTest('.embeddedElement() then .embeddedLengthLessThan()', () async {});
+ isarTest(
+ '.embeddedElement() then .embeddedLengthGreaterThan()', () async {});
+ isarTest('.embeddedElement() then .embeddedLengthBetween()', () async {});
+ isarTest('.embeddedElement() then .embeddedLengthIsEmpty()', () async {});
+ isarTest(
+ '.embeddedElement() then .embeddedLengthIsNotEmpty()', () async {});
+ isarTest('.embeddedElement() then .embeddedElementIsNull()', () async {});
+ isarTest(
+ '.embeddedElement() then .embeddedElementIsNotNull()', () async {});
+ isarTest('.embeddedElement() then .embeddedElement()', () async {});
+ isarTest('.embeddedElement() then .embeddedElement()', () async {});
+
+ // FIXME: IsarError: Unsupported type for condition
+ isarTest('.embeddedElement() then .embeddedElementEqualTo()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj1.embeddedAs[2].embeddedBs![0],
+ ),
+ ),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj1.embeddedAs[2].embeddedBs![1],
+ ),
+ ),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj1.embeddedAs[2].embeddedBs![2],
+ ),
+ ),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj3.embeddedAs[0].embeddedBs![1],
+ ),
+ ),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![0],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![1],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![2],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![3],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![4],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj5.embeddedAs[0].embeddedBs![5],
+ ),
+ ),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ obj6.embeddedAs[0].embeddedBs![0],
+ ),
+ ),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAsElement(
+ (q) => q.embeddedBsElementEqualTo(
+ EmbeddedB(name: 'non existing'),
+ ),
+ ),
+ [],
+ );
+ });
+ });
+}

ADD
packages/isar_test/test/filter/filter_embedded_test.dart
+// ignore_for_file: hash_and_equals
+
+import 'package:isar/isar.dart';
+import 'package:test/test.dart';
+
+import '../util/common.dart';
+import '../util/matchers.dart';
+import '../util/sync_async_helper.dart';
+
+part 'filter_embedded_test.g.dart';
+
+@collection
+class Model {
+ Model({
+ required this.embeddedA,
+ required this.embeddedB,
+ });
+
+ Id id = Isar.autoIncrement;
+
+ // FIXME: Generator doesn't prevent us from indexing this field, but crashes
+ // at runtime (...objects cannot be indexed)
+ // @Index()
+ EmbeddedModelA embeddedA;
+
+ EmbeddedModelB? embeddedB;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is Model &&
+ runtimeType == other.runtimeType &&
+ id == other.id &&
+ embeddedA == other.embeddedA &&
+ embeddedB == other.embeddedB;
+
+ @override
+ String toString() {
+ return '''Model{id: $id, embeddedA: $embeddedA, embeddedB: $embeddedB}''';
+ }
+}
+
+@embedded
+class EmbeddedModelA {
+ const EmbeddedModelA({
+ this.name = '',
+ this.embeddedB = const EmbeddedModelB(),
+ });
+
+ final String name;
+
+ final EmbeddedModelB? embeddedB;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is EmbeddedModelA &&
+ runtimeType == other.runtimeType &&
+ name == other.name &&
+ embeddedB == other.embeddedB;
+
+ @override
+ String toString() {
+ return 'EmbeddedModelA{name: $name, embeddedB: $embeddedB}';
+ }
+}
+
+@embedded
+class EmbeddedModelB {
+ const EmbeddedModelB({
+ this.name = '',
+ });
+
+ final String name;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ other is EmbeddedModelB &&
+ runtimeType == other.runtimeType &&
+ name == other.name;
+
+ @override
+ String toString() {
+ return 'EmbeddedModelB{name: $name}';
+ }
+}
+
+void main() {
+ group('Filter embedded', () {
+ late Isar isar;
+
+ late Model obj1;
+ late Model obj2;
+ late Model obj3;
+ late Model obj4;
+ late Model obj5;
+ late Model obj6;
+
+ setUp(() async {
+ isar = await openTempIsar([ModelSchema]);
+
+ obj1 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a1',
+ embeddedB: EmbeddedModelB(name: 'embedded a1 b1'),
+ ),
+ embeddedB: const EmbeddedModelB(name: 'embedded b1'),
+ );
+ obj2 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a2',
+ embeddedB: EmbeddedModelB(name: 'embedded a2 b2'),
+ ),
+ embeddedB: null,
+ );
+ obj3 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a3',
+ embeddedB: null,
+ ),
+ embeddedB: const EmbeddedModelB(name: 'embedded b3'),
+ );
+ obj4 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a4',
+ embeddedB: EmbeddedModelB(name: 'embedded a4 b4'),
+ ),
+ embeddedB: const EmbeddedModelB(name: 'embedded b4'),
+ );
+ obj5 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a5',
+ embeddedB: null,
+ ),
+ embeddedB: const EmbeddedModelB(name: 'embedded b5'),
+ );
+ obj6 = Model(
+ embeddedA: const EmbeddedModelA(
+ name: 'embedded a6',
+ embeddedB: EmbeddedModelB(name: 'embedded a6 b6'),
+ ),
+ embeddedB: null,
+ );
+
+ await isar.tWriteTxn(
+ () => isar.models.tPutAll([
+ obj1,
+ obj2,
+ obj3,
+ obj4,
+ obj5,
+ obj6,
+ ]),
+ );
+ });
+
+ // FIXME: IsarError: Unsupported type for condition
+ isarTest('.equalTo()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj1.embeddedA),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj2.embeddedA),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj3.embeddedA),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj4.embeddedA),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj5.embeddedA),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(obj6.embeddedA),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedAEqualTo(
+ const EmbeddedModelA(
+ name: 'non existing',
+ ),
+ ),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedBEqualTo(obj1.embeddedB),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBEqualTo(obj3.embeddedB),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBEqualTo(obj4.embeddedB),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBEqualTo(obj5.embeddedB),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedBEqualTo(
+ const EmbeddedModelB(
+ name: 'non existing',
+ ),
+ ),
+ [],
+ );
+ });
+
+ isarTest('.embedded()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameStartsWith('embedded')),
+ [obj1, obj2, obj3, obj4, obj5, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a1')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a2')),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a3')),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a4')),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a5')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded a6')),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('non existing')),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.nameEqualTo('embedded b1')),
+ [],
+ );
+
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameStartsWith('embedded')),
+ [obj1, obj3, obj4, obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b1')),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b2')),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b3')),
+ [obj3],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b4')),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b5')),
+ [obj5],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded b6')),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('non existing')),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedB((q) => q.nameEqualTo('embedded a1')),
+ [],
+ );
+ });
+
+ isarTest('.embeddedIsNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBIsNull(),
+ [obj2, obj6],
+ );
+ });
+
+ isarTest('.embeddedIsNotNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedBIsNotNull(),
+ [obj1, obj3, obj4, obj5],
+ );
+ });
+
+ // FIXME: IsarError: Unsupported type for condition
+ isarTest('.embedded() then .embeddedEqualTo()', () async {
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj1.embeddedA.embeddedB)),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj2.embeddedA.embeddedB)),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj3.embeddedA.embeddedB)),
+ [obj3, obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj4.embeddedA.embeddedB)),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj5.embeddedA.embeddedB)),
+ [obj3, obj5],
+ );
+ await qEqualSet(
+ isar.models
+ .filter()
+ .embeddedA((q) => q.embeddedBEqualTo(obj6.embeddedA.embeddedB)),
+ [obj6],
+ );
+ });
+
+ // FIXME(severe): panic
+ // Shell: thread 'isarworker' panicked at 'range start index 6579554 out of
+ // range for slice of length 11', library/core/src/slice/index.rs:52:5
+ isarTest('.embedded() then .embedded()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameStartsWith('embedded'),
+ ),
+ ),
+ [obj1, obj2, obj4, obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a1 b1'),
+ ),
+ ),
+ [obj1],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a2 b2'),
+ ),
+ ),
+ [obj2],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a3 b3'),
+ ),
+ ),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a4 b4'),
+ ),
+ ),
+ [obj4],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a5 b5'),
+ ),
+ ),
+ [],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('embedded a6 b6'),
+ ),
+ ),
+ [obj6],
+ );
+ await qEqualSet(
+ isar.models.filter().embeddedA(
+ (q) => q.embeddedB(
+ (q) => q.nameEqualTo('non existing'),
+ ),
+ ),
+ [],
+ );
+ });
+
+ isarTest('.embedded() then .embeddedIsNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.embeddedBIsNull()),
+ [obj3, obj5],
+ );
+ });
+
+ isarTest('.embedded() then .embeddedIsNotNull()', () async {
+ await qEqualSet(
+ isar.models.filter().embeddedA((q) => q.embeddedBIsNotNull()),
+ [obj1, obj2, obj4, obj6],
+ );
+ });
+ });
+}

Started filter embedded test