[vala/0.40] tests: Add more "delegate" tests to increase coverage
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] tests: Add more "delegate" tests to increase coverage
- Date: Sun, 3 Jan 2021 12:46:52 +0000 (UTC)
commit 1200edc0d440e1f752ed5809d5b6c38db5c97ea8
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 9d428d5ff..5c72dff88 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,9 +131,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]