[vala/staging: 2/4] tests: Add "generic array" test to increase coverage




commit 7e2bbebc92f20c42bb62e2f03d94aeb145337237
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Apr 28 21:33:10 2021 +0200

    tests: Add "generic array" test to increase coverage

 tests/Makefile.am          |  1 +
 tests/generics/arrays.vala | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16cd7303b..b5a1acf04 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -675,6 +675,7 @@ TESTS = \
        asynchronous/variadic-invalid.test \
        asynchronous/variadic-invalid-2.test \
        asynchronous/yield.vala \
+       generics/arrays.vala \
        generics/arrays-not-supported.test \
        generics/arrays-not-supported-2.test \
        generics/arrays-not-supported-3.test \
diff --git a/tests/generics/arrays.vala b/tests/generics/arrays.vala
new file mode 100644
index 000000000..b28d8cc47
--- /dev/null
+++ b/tests/generics/arrays.vala
@@ -0,0 +1,35 @@
+class Foo<G> {
+       public G[] ga;
+
+       public Foo (G g) {
+               var gs = new G[] { g };
+               assert (gs.length == 1);
+               assert (gs[0] == "foo");
+
+               ga = gs;
+               assert (ga.length == 1);
+               assert (ga[0] == "foo");
+       }
+
+       public void foo (owned G[] gs) {
+               assert (gs.length == 1);
+               assert (gs[0] == "foo");
+       }
+}
+
+void bar<G> (G g) {
+       var gs = new G[] { g };
+       assert (gs.length == 1);
+       assert (gs[0] == "bar");
+
+       var gs_copy = gs;
+       assert (gs_copy.length == 1);
+       assert (gs_copy[0] == "bar");
+}
+
+void main () {
+       var foo = new Foo<string> ("foo");
+       foo.foo (foo.ga);
+
+       bar<string> ("bar");
+}


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