]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Add "iterator" methods tests to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Jan 2018 13:09:38 +0000 (14:09 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 10 Jan 2018 19:44:55 +0000 (20:44 +0100)
tests/Makefile.am
tests/methods/iterator.vala [new file with mode: 0644]

index a8c3e735e68880e60938ec4544312a66aecb8fec..36a16cfbfc8f02c8ef6b23f998463a3af08ed062 100644 (file)
@@ -65,6 +65,7 @@ TESTS = \
        methods/lambda.vala \
        methods/closures.vala \
        methods/contains.vala \
+       methods/iterator.vala \
        methods/prepostconditions.vala \
        methods/symbolresolution.vala \
        methods/bug595538.vala \
diff --git a/tests/methods/iterator.vala b/tests/methods/iterator.vala
new file mode 100644 (file)
index 0000000..3dd9966
--- /dev/null
@@ -0,0 +1,72 @@
+class Foo {
+}
+
+class FooIterator {
+       bool called = false;
+       
+       public bool next () {
+               return !called;
+       }
+
+       public Foo @get () {
+               assert (!called);
+               called = true;
+               return foo_instance;
+       }
+}
+
+class FooCollection {
+       public FooIterator iterator () {
+               return new FooIterator ();
+       }
+}
+
+class FooIterator2 {
+       bool called = false;
+       
+       public Foo? next_value () {
+               if (called)
+                       return null;
+               called = true;
+               return foo_instance;
+       }
+}
+
+class FooCollection2 {
+       public FooIterator2 iterator () {
+               return new FooIterator2 ();
+       }
+}
+
+class FooCollection3 {
+       public int size { get { return 1; } }
+
+       public Foo @get (int index) {
+               assert (index == 0);
+               return foo_instance;
+       }
+}
+
+Foo foo_instance;
+
+void main () {
+       foo_instance = new Foo ();
+
+       // Uses next() and get()
+       var collection = new FooCollection ();
+       foreach (var foo in collection) {
+               assert (foo == foo_instance);
+       }
+
+       // Uses next_value()
+       var collection2 = new FooCollection2 ();
+       foreach (var foo2 in collection2) {
+               assert (foo2 == foo_instance);
+       }
+
+       // Uses size and get()
+       var collection3 = new FooCollection3 ();
+       foreach (var foo3 in collection3) {
+               assert (foo3 == foo_instance);
+       }
+}