From 1116e421be541900c204cf8f0975c6879211a950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Fri, 1 Sep 2023 10:23:21 +0200 Subject: [PATCH] Add test of _RealmResultsIterator edge-cases --- test/results_test.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/results_test.dart b/test/results_test.dart index bb7c13ece..7ae8b43fe 100644 --- a/test/results_test.dart +++ b/test/results_test.dart @@ -939,4 +939,33 @@ Future main([List? 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())); + expect(it.moveNext(), isTrue); + expect(it.moveNext(), isFalse); + // you are not supposed to call current, if moveNext return false + expect(() => it.current, throwsA(isA())); + + // behavior of _RealmResultsIterator + final config = Configuration.local([Task.schema]); + final realm = getRealm(config); + realm.write(() { + realm.add(Task(ObjectId())); + }); + final results = realm.all(); + expect(results.length, 1); + final rit = results.iterator; + + // you are not supposed to call current before first moveNext + expect(() => rit.current, throwsA(isA())); + expect(rit.moveNext(), isTrue); + expect(rit.moveNext(), isFalse); + // you are not supposed to call current, if moveNext return false + expect(() => rit.current, throwsA(isA())); + }); }