[vala/0.36: 136/212] tests: Add "iterator" methods tests to increase coverage



commit 4813b9d052792ef9385b4f73a84dfe8c4975685d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Jan 7 14:09:38 2018 +0100

    tests: Add "iterator" methods tests to increase coverage

 tests/Makefile.am           |    1 +
 tests/methods/iterator.vala |   72 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 86e8333..7966968 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -64,6 +64,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
index 0000000..3dd9966
--- /dev/null
+++ b/tests/methods/iterator.vala
@@ -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);
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]