[vala/0.48] tests: Add "generic array" test to increase coverage
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] tests: Add "generic array" test to increase coverage
- Date: Wed, 19 May 2021 07:14:27 +0000 (UTC)
commit 0920e866c17a99f1a04831628972f375a304d857
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 fe12b1086..8f77a5e9f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -656,6 +656,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]