From: Rico Tzschichholz Date: Sat, 14 Nov 2020 20:31:03 +0000 (+0100) Subject: tests: Add more "delegate" tests to increase coverage X-Git-Tag: 0.40.25~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1200edc0d440e1f752ed5809d5b6c38db5c97ea8;p=thirdparty%2Fvala.git tests: Add more "delegate" tests to increase coverage --- 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); + } +}