aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/backends/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/zwobble/couscous/tests/backends/python')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java9
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java21
2 files changed, 29 insertions, 1 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
index 6f19eb3..ff51f60 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
@@ -1,5 +1,7 @@
package org.zwobble.couscous.tests.backends.python;
+import org.junit.Ignore;
+import org.junit.Test;
import org.zwobble.couscous.ast.ClassNode;
import org.zwobble.couscous.ast.ExpressionNode;
import org.zwobble.couscous.ast.MethodNode;
@@ -13,6 +15,13 @@ import lombok.val;
public class PythonCompilerEvalTests extends BackendEvalTests {
@Override
+ @Test
+ @Ignore("Work in progress")
+ public void canCallMethodWithNoArgumentsOnBuiltin() {
+
+ }
+
+ @Override
protected PrimitiveValue evalExpression(ExpressionNode expression) {
val runner = new PythonMethodRunner();
return runner.runMethod(
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
index 60aed36..a7708da 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
@@ -8,7 +8,9 @@ import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.zwobble.couscous.backends.python.PythonSerializer.serialize;
import static org.zwobble.couscous.backends.python.ast.PythonAssignmentNode.pythonAssignment;
+import static org.zwobble.couscous.backends.python.ast.PythonAttributeAccessNode.pythonAttributeAccess;
import static org.zwobble.couscous.backends.python.ast.PythonBooleanLiteralNode.pythonBooleanLiteral;
+import static org.zwobble.couscous.backends.python.ast.PythonCallNode.pythonCall;
import static org.zwobble.couscous.backends.python.ast.PythonConditionalExpressionNode.pythonConditionalExpression;
import static org.zwobble.couscous.backends.python.ast.PythonIntegerLiteralNode.pythonIntegerLiteral;
import static org.zwobble.couscous.backends.python.ast.PythonModuleNode.pythonModule;
@@ -45,7 +47,7 @@ public class PythonSerializerTests {
}
@Test
- public void conditionalExpressionIsSerializedUsingParens() {
+ public void conditionalExpressionIsSerializedUsingParenthesisedSubExpression() {
assertEquals("(1) if (True) else (2)", serialize(
pythonConditionalExpression(
pythonBooleanLiteral(true),
@@ -54,6 +56,23 @@ public class PythonSerializerTests {
}
@Test
+ public void attributeAccessIsSerializedUsingParenthesisedSubExpression() {
+ assertEquals("(x).y", serialize(
+ pythonAttributeAccess(
+ pythonVariableReference("x"),
+ "y")));
+ }
+
+ @Test
+ public void callIsSerializedUsingParenthesisedSubExpression() {
+ assertEquals("(f)(x, y)", serialize(
+ pythonCall(
+ pythonVariableReference("f"),
+ asList(pythonVariableReference("x"),
+ pythonVariableReference("y")))));
+ }
+
+ @Test
public void returnKeywordIsUsedForReturns() {
val output = serialize(pythonReturn(pythonIntegerLiteral(42)));
assertEquals("return 42\n", output);