From 1200edc0d440e1f752ed5809d5b6c38db5c97ea8 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sat, 14 Nov 2020 21:31:03 +0100 Subject: [PATCH] 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(+) create mode 100644 tests/methods/parameter-ref-delegate.vala create mode 100644 tests/methods/return-unowned-delegate.vala 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); + } +} -- 2.47.2