[vala/staging: 6/6] tests: Make lambda tests fatal and add some more cases



commit c4a80b11e19b8fcb1134049e2a33dfc08475c83e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Nov 22 21:49:11 2017 +0100

    tests: Make lambda tests fatal and add some more cases

 tests/methods/lambda.vala |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/tests/methods/lambda.vala b/tests/methods/lambda.vala
index d533f68..c659cb6 100644
--- a/tests/methods/lambda.vala
+++ b/tests/methods/lambda.vala
@@ -1,20 +1,31 @@
 using GLib;
 
 static delegate int Maman.ActionCallback (int i);
+static delegate void Maman.ActionOutCallback (out int i);
+static delegate void Maman.ActionRefCallback (ref int i);
 
 class Maman.Bar : Object {
        static int do_action (ActionCallback cb) {
                return cb (1);
        }
 
+       static int do_out_action (ActionOutCallback cb) {
+               int i;
+               cb (out i);
+               return i;
+       }
+
+       static int do_ref_action (ActionRefCallback cb) {
+               int i = 1;
+               cb (ref i);
+               return i;
+       }
+
        public static int main () {
-               stdout.printf ("Lambda Test: 1");
-               
-               stdout.printf (" %d", do_action (i => i * 2));
-               
-               stdout.printf (" %d", do_action (i => { return i * 3; }));
-               
-               stdout.printf (" 4\n");
+               assert (do_action (i => i * 2) == 2);
+               assert (do_action (i => { return i * 3; }) == 3);
+               assert (do_out_action ((out i) => { i = 4; }) == 4);
+               assert (do_ref_action ((ref i) => { i += 4; }) == 5);
                
                return 0;
        }


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