aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/BackendTests.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-10-05 13:32:56 +0100
committerMichael Williamson <mike@zwobble.org>2015-10-05 13:32:56 +0100
commit4921990578830926ecc294604c43ec28c851fe8d (patch)
tree1836fdd9d407e9a6c1823d5b0e61860bf165de07 /src/test/java/org/zwobble/couscous/tests/BackendTests.java
parent38cc6849339b37c29af80e2affc1931479d61c05 (diff)
Support local variable declarations in Python backend
Diffstat (limited to 'src/test/java/org/zwobble/couscous/tests/BackendTests.java')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/BackendTests.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/BackendTests.java b/src/test/java/org/zwobble/couscous/tests/BackendTests.java
index 0f3956d..f9566d7 100644
--- a/src/test/java/org/zwobble/couscous/tests/BackendTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/BackendTests.java
@@ -15,6 +15,7 @@ import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.zwobble.couscous.ast.FormalArgumentNode.formalArg;
import static org.zwobble.couscous.ast.LiteralNode.literal;
+import static org.zwobble.couscous.ast.LocalVariableDeclarationNode.localVariableDeclaration;
import static org.zwobble.couscous.ast.MethodNode.staticMethod;
import static org.zwobble.couscous.ast.VariableDeclaration.var;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
@@ -61,6 +62,18 @@ public abstract class BackendTests {
assertEquals(value("[updated value]"), result);
}
+
+ @Test
+ public void canDeclareVariable() {
+ val localVariableDeclaration = localVariableDeclaration(
+ 42, "x", StringValue.REF, LiteralNode.literal("[initial value]"));
+ val method = staticMethod("hello")
+ .statement(localVariableDeclaration)
+ .statement(new ReturnNode(reference(localVariableDeclaration)));
+ val result = runMethod(method);
+
+ assertEquals(value("[initial value]"), result);
+ }
protected PrimitiveValue runMethod(MethodNode.MethodNodeBuilder methodBuilder, PrimitiveValue... arguments) {
val method = methodBuilder.build();