aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-04-03 13:38:53 +0100
committerMichael Williamson <mike@zwobble.org>2016-04-03 13:38:53 +0100
commit3c42c0a7c1196cc290dbcdc55dcb84379ad523e4 (patch)
treef746640db075a3d613f21581d0c392b16d024439 /src/test
parent26f7b223ebfcf3e514ffa8c2b81ccaaa7a6605cc (diff)
C# backend: Implement for-each loops
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/CompilerTests.java12
-rw-r--r--src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java7
-rw-r--r--src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java7
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/NodeMatchers.java4
-rw-r--r--src/test/resources/java/for-each/com/example/ForEach.java16
5 files changed, 46 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 0099d26..7a60821 100644
--- a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
@@ -85,6 +85,18 @@ public abstract class CompilerTests {
}
@Test
+ public void forEach() throws Exception {
+ assertEquals(
+ value("abc"),
+ execTestProgram(
+ "for-each",
+ ScalarType.of("com.example.ForEach"),
+ "value",
+ list(),
+ Types.STRING));
+ }
+
+ @Test
public void staticNestedClasses() throws Exception {
assertEquals(
value(42),
diff --git a/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java b/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
index 2c8a1e6..209aaa8 100644
--- a/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
@@ -1,6 +1,8 @@
package org.zwobble.couscous.tests;
import com.google.common.collect.ImmutableList;
+import org.junit.Ignore;
+import org.junit.Test;
import org.zwobble.couscous.ast.TypeNode;
import org.zwobble.couscous.frontends.java.JavaFrontend;
import org.zwobble.couscous.interpreter.Interpreter;
@@ -20,6 +22,11 @@ import static com.google.common.collect.Iterables.transform;
import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaToInterpreterTests extends CompilerTests {
+ @Test
+ @Ignore("WIP")
+ public void forEach() throws Exception {
+ }
+
@Override
protected PrimitiveValue execProgram(
Path directory,
diff --git a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
index f482d11..ba2e8b4 100644
--- a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
@@ -1,5 +1,7 @@
package org.zwobble.couscous.tests;
+import org.junit.Ignore;
+import org.junit.Test;
import org.zwobble.couscous.CouscousCompiler;
import org.zwobble.couscous.types.ScalarType;
import org.zwobble.couscous.backends.python.PythonBackend;
@@ -16,6 +18,11 @@ import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaToPythonTests extends CompilerTests {
+ @Test
+ @Ignore("WIP")
+ public void forEach() throws Exception {
+ }
+
protected PrimitiveValue execProgram(
Path directory,
ScalarType type,
diff --git a/src/test/java/org/zwobble/couscous/tests/frontends/java/NodeMatchers.java b/src/test/java/org/zwobble/couscous/tests/frontends/java/NodeMatchers.java
index 739d664..a1b60e9 100644
--- a/src/test/java/org/zwobble/couscous/tests/frontends/java/NodeMatchers.java
+++ b/src/test/java/org/zwobble/couscous/tests/frontends/java/NodeMatchers.java
@@ -10,6 +10,10 @@ import static org.zwobble.couscous.tests.util.ExtraMatchers.hasFeature;
import static org.zwobble.couscous.tests.util.ExtraMatchers.isInstance;
public class NodeMatchers {
+ public static Matcher<LocalVariableDeclarationNode> declarationHasValue(Matcher<ExpressionNode> matcher) {
+ return hasFeature("initial value", node -> node.getInitialValue(), matcher);
+ }
+
@SafeVarargs
public static Matcher<ExpressionNode> isFieldAccess(Matcher<? super FieldAccessNode>... matchers) {
return isInstance(FieldAccessNode.class, allOf(matchers));
diff --git a/src/test/resources/java/for-each/com/example/ForEach.java b/src/test/resources/java/for-each/com/example/ForEach.java
new file mode 100644
index 0000000..807927d
--- /dev/null
+++ b/src/test/resources/java/for-each/com/example/ForEach.java
@@ -0,0 +1,16 @@
+package com.example;
+
+import static java.util.Arrays.asList;
+
+public class ForEach {
+ public static String value() {
+ Iterable<String> values = asList("a", "b", "c");
+ String result = "";
+
+ for (String value : values) {
+ result += value;
+ }
+
+ return result;
+ }
+}