From: Rico Tzschichholz Date: Sun, 7 Jan 2018 13:09:38 +0000 (+0100) Subject: tests: Add "iterator" methods tests to increase coverage X-Git-Tag: 0.39.4~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=872d43c704a9234f36ca28e72fa3a0c17be051cf;p=thirdparty%2Fvala.git tests: Add "iterator" methods tests to increase coverage --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 64fd643fe..cf7103a00 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..3dd99666f --- /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); + } +}