package kilim.test;

import junit.framework.TestCase;
import kilim.ExitMsg;
import kilim.Pausable;
import kilim.Task;

public class TestLambda extends TestCase {
    public void testLambda() throws Exception {
        ExitMsg e = new LamTask("testLambda", 100, 200).start().joinb();
        if (!(e.result.equals("testLambda300"))) {
            fail("Expected add300");
        }
    }
    /**
     * Task that calls a pausable lambda method. We test with repeated pauses, captured variables
     * and explicit arguments. 
     */
    static class LamTask extends kilim.Task {
        
        
        private String s;
        private int a;
        private int b;

        public LamTask(String s, int a, int b) {
            this.s = s;
            this.a = a;
            this.b = b;
        }

        @Override
        public void execute() throws Pausable {
            int captured1 = this.a;
            int captured2 = this.b;
            
            Lambda<String> lam = (String input) -> {
                int c = 0;
                Task.yield();
                c += captured1;
                Task.sleep(10);
                c += captured2;
                Task.yield();
                return input + c;
            };
            String output = lam.process("testLambda"); // should be testLambda<a+b>
            Task.exit(output);
        }
    }
    
    static interface Lambda<T> {
        T process(String input) throws Pausable;
    }
}


@@ -203,16 +203,161 @@
 ption %7B%0A
+        // loop to ensure that multiple invocations of the invokedynamic instruction work as expected%0A        for (int i = 1; i %3C 10; i++) %7B%0A    
         
@@ -398,16 +398,16 @@
 a%22, 
-100, 200
+i, i * 2
 ).st
@@ -429,16 +429,20 @@
         
+   
+ 
 if (!(e.
@@ -470,18 +470,32 @@
 mbda
-300%22
+%22 + ( i + i*2)
 ))) %7B%0A
+    
     
@@ -521,17 +521,40 @@
 ted 
-add300%22);
+testLambda%3Ca+b%3E%22);%0A            %7D
 %0A   
@@ -712,16 +712,16 @@
      */%0A
+
     stat
@@ -762,26 +762,8 @@
 k %7B%0A
-        %0A        %0A
     
@@ -1439,28 +1439,22 @@
 process(
-%22testLambda%22
+this.s
 ); // sh

Test case modified to account for multiple invocations through a lambda function. modified: test/kilim/test/TestLambda.java