[vala/staging: 7/10] tests: Add more "delegate" tests to increase coverage




commit f7b419897a97e1ebf96064227a04a1100d21f903
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Nov 14 21:31:03 2020 +0100

    tests: Add more "delegate" tests to increase coverage

 tests/Makefile.am                          |  2 ++
 tests/methods/parameter-ref-delegate.vala  | 26 ++++++++++++++++++++++++++
 tests/methods/return-unowned-delegate.vala | 25 +++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 50816d39c..48aa3a55c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -159,9 +159,11 @@ TESTS = \
        methods/parameter-fixed-array-initializer.vala \
        methods/parameter-ref-array-resize.vala \
        methods/parameter-ref-array-resize-captured.vala \
+       methods/parameter-ref-delegate.vala \
        methods/prepostconditions.vala \
        methods/prepostconditions-captured.vala \
        methods/postconditions.vala \
+       methods/return-unowned-delegate.vala \
        methods/same-name.vala \
        methods/symbolresolution.vala \
        methods/bug540483.vala \
diff --git a/tests/methods/parameter-ref-delegate.vala b/tests/methods/parameter-ref-delegate.vala
new file mode 100644
index 000000000..432dd94d7
--- /dev/null
+++ b/tests/methods/parameter-ref-delegate.vala
@@ -0,0 +1,26 @@
+delegate int FooFunc ();
+
+void foo (int i, ref FooFunc func) {
+       assert (func () == i);
+       func = () => 4711;
+}
+
+int bar () {
+       return 23;
+}
+
+void main () {
+       {
+               FooFunc func = bar;
+               assert (func () == 23);
+               foo (23, ref func);
+               assert (func () == 4711);
+       }
+       {
+               int i = 42;
+               FooFunc func = () => i;
+               assert (func () == 42);
+               foo (42, ref func);
+               assert (func () == 4711);
+       }
+}
diff --git a/tests/methods/return-unowned-delegate.vala b/tests/methods/return-unowned-delegate.vala
new file mode 100644
index 000000000..daa6eef71
--- /dev/null
+++ b/tests/methods/return-unowned-delegate.vala
@@ -0,0 +1,25 @@
+delegate int FooFunc ();
+
+unowned FooFunc foo () {
+       return (FooFunc) manam;
+}
+
+unowned FooFunc bar () {
+       return () => 4711;
+}
+
+int manam () {
+       return 42;
+}
+
+void main () {
+       {
+               FooFunc func = foo ();
+               assert (func == (FooFunc) manam);
+               assert (func () == 42);
+       }
+       {
+               FooFunc func = bar ();
+               assert (func () == 4711);
+       }
+}


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