diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-05 13:32:56 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-05 13:32:56 +0100 |
| commit | 4921990578830926ecc294604c43ec28c851fe8d (patch) | |
| tree | 1836fdd9d407e9a6c1823d5b0e61860bf165de07 /src/test/java/org/zwobble | |
| parent | 38cc6849339b37c29af80e2affc1931479d61c05 (diff) | |
Support local variable declarations in Python backend
Diffstat (limited to 'src/test/java/org/zwobble')
| -rw-r--r-- | src/test/java/org/zwobble/couscous/tests/BackendTests.java | 13 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java | 12 |
2 files changed, 13 insertions, 12 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(); diff --git a/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java b/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java index a54f150..d5a7617 100644 --- a/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java +++ b/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java @@ -62,18 +62,6 @@ public class InterpreterTests extends BackendTests { } @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); - } - - @Test public void canDeclareVariableAndThenAssignValues() { val localVariableDeclaration = localVariableDeclaration( 42, "x", StringValue.REF, LiteralNode.literal("[initial value]")); |
