Skip to content

Commit

Permalink
Add test of _RealmResultsIterator edge-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Sep 1, 2023
1 parent 9b51d65 commit 1116e42
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/results_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,33 @@ Future<void> main([List<String>? args]) async {
);
}
});

test('_RealmResultsIterator', () {
// behavior of normal iterator
final list = [1];
final it = list.iterator;
// you are not supposed to call current before first moveNext
expect(() => it.current, throwsA(isA<TypeError>()));
expect(it.moveNext(), isTrue);
expect(it.moveNext(), isFalse);
// you are not supposed to call current, if moveNext return false
expect(() => it.current, throwsA(isA<TypeError>()));

// behavior of _RealmResultsIterator
final config = Configuration.local([Task.schema]);
final realm = getRealm(config);
realm.write(() {
realm.add(Task(ObjectId()));
});
final results = realm.all<Task>();
expect(results.length, 1);
final rit = results.iterator;

// you are not supposed to call current before first moveNext
expect(() => rit.current, throwsA(isA<RealmException>()));
expect(rit.moveNext(), isTrue);
expect(rit.moveNext(), isFalse);
// you are not supposed to call current, if moveNext return false
expect(() => rit.current, throwsA(isA<RealmException>()));
});
}

0 comments on commit 1116e42

Please sign in to comment.