aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-04 17:44:25 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-04 17:44:43 +0000
commit909f9d629808da383e6c9e8e514711382cdc331e (patch)
tree968a15b6ab893177e708666500cc339c621ae452 /src/test
parente9eb339f96c3b82bcb6e908c7a86364c768c16f2 (diff)
Add WIP test for this capture in lambdas
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/CompilerTests.java14
-rw-r--r--src/test/resources/java/lambda-this-capture/com/example/Lambda.java20
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
index b5e0d82..56d989c 100644
--- a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
@@ -1,5 +1,6 @@
package org.zwobble.couscous.tests;
+import org.junit.Ignore;
import org.junit.Test;
import org.zwobble.couscous.ast.TypeName;
import org.zwobble.couscous.values.PrimitiveValue;
@@ -13,6 +14,7 @@ import java.nio.file.Path;
import java.util.List;
import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
import static org.zwobble.couscous.values.PrimitiveValues.value;
@@ -121,6 +123,18 @@ public abstract class CompilerTests {
asList(value(2))));
}
+ @Test
+ @Ignore("WIP")
+ public void lambdasWithThisCapture() throws Exception {
+ assertEquals(
+ value(42),
+ execTestProgram(
+ "lambda-this-capture",
+ TypeName.of("com.example.Lambda"),
+ "value",
+ asList(value(2))));
+ }
+
private PrimitiveValue execTestProgram(
String directoryName,
TypeName type,
diff --git a/src/test/resources/java/lambda-this-capture/com/example/Lambda.java b/src/test/resources/java/lambda-this-capture/com/example/Lambda.java
new file mode 100644
index 0000000..b4aadbf
--- /dev/null
+++ b/src/test/resources/java/lambda-this-capture/com/example/Lambda.java
@@ -0,0 +1,20 @@
+package com.example;
+
+import java.util.function.Function;
+
+public class Lambda {
+ public static int value(int factor) {
+ return new Lambda(factor).run();
+ }
+
+ private final int factor;
+
+ private Lambda(int factor) {
+ this.factor = factor;
+ }
+
+ private int run() {
+ Function<Integer, Integer> function = value -> value * factor;
+ return function.apply(21);
+ }
+}