[vala/wip/issue/658: 15/34] Added anonymous delegate tests
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/658: 15/34] Added anonymous delegate tests
- Date: Fri, 6 Nov 2020 11:17:08 +0000 (UTC)
commit 6866d8e62564310d6b3338b00d296f5ece426789
Author: Nick Schrader <nick schrader mailbox org>
Date: Sat Oct 17 00:25:13 2020 -0300
Added anonymous delegate tests
tests/Makefile.am | 3 +++
tests/delegates/anonymous-array.vala | 15 +++++++++++++++
tests/delegates/anonymous-type-param.vala | 20 ++++++++++++++++++++
tests/delegates/anonymous.vala | 9 +++++++++
4 files changed, 47 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 47e9a711b..ebe3d2680 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -355,6 +355,9 @@ TESTS = \
structs/bug775761.vala \
structs/bug777194.vala \
structs/bug777194-2.vala \
+ delegates/anonymous.vala \
+ delegates/anonymous-array.vala \
+ delegates/anonymous-type-param.vala \
delegates/casting.vala \
delegates/compatible.vala \
delegates/delegate_only.vala \
diff --git a/tests/delegates/anonymous-array.vala b/tests/delegates/anonymous-array.vala
new file mode 100644
index 000000000..116a523fd
--- /dev/null
+++ b/tests/delegates/anonymous-array.vala
@@ -0,0 +1,15 @@
+void main() {
+ f((a, b) => {
+ int r = 0;
+ for (int i = 0; i < a.length; i++) {
+ r += a[i]*b[i];
+ }
+ return r;
+ });
+}
+
+void f(delegate(int[], int[]) => int abc) {
+ int i[] = {1, 2, 3};
+ int j[] = {7, 8, 9};
+ assert (abc (i, j) == 50);
+}
diff --git a/tests/delegates/anonymous-type-param.vala b/tests/delegates/anonymous-type-param.vala
new file mode 100644
index 000000000..052a703ef
--- /dev/null
+++ b/tests/delegates/anonymous-type-param.vala
@@ -0,0 +1,20 @@
+void main() {
+ f(t);
+}
+
+string t(Comp<string> a, Comp<string> b) {
+ return a.a+b.a;
+}
+
+
+void f(delegate(Comp<string>, Comp<string>) => string abc) {
+ assert (abc(new Comp<string>("x"), new Comp<string>("y")) == "xy");
+}
+
+class Comp<A> {
+ public A a { get; private set; }
+
+ public Comp (A a) {
+ this.a = a;
+ }
+}
diff --git a/tests/delegates/anonymous.vala b/tests/delegates/anonymous.vala
new file mode 100644
index 000000000..cbb8b049b
--- /dev/null
+++ b/tests/delegates/anonymous.vala
@@ -0,0 +1,9 @@
+void main () {
+ f((a, b) => {
+ return a+b;
+ });
+}
+
+void f (delegate(int, int) => int abc) {
+ assert (abc (1, 2) == 3);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]