diff options
Diffstat (limited to 'src/test/java/org/zwobble')
4 files changed, 36 insertions, 8 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java b/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java index 4eb925a..68e9761 100644 --- a/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java +++ b/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java @@ -7,6 +7,7 @@ import org.zwobble.couscous.values.PrimitiveValue; import static org.junit.Assert.assertEquals; import static org.zwobble.couscous.ast.LiteralNode.literal; +import static org.zwobble.couscous.ast.MethodCallNode.methodCall; import static org.zwobble.couscous.values.PrimitiveValues.value; import lombok.val; @@ -32,5 +33,11 @@ public abstract class BackendEvalTests { assertEquals(value("F"), result); } + @Test + public void canCallMethodWithNoArgumentsOnBuiltin() { + val result = evalExpression(methodCall(literal("hello"), "length")); + assertEquals(value(5), result); + } + protected abstract PrimitiveValue evalExpression(ExpressionNode expression); } 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); diff --git a/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java b/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java index 0a2a947..766cf3c 100644 --- a/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java +++ b/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java @@ -57,13 +57,6 @@ public class EvaluatorTests extends BackendEvalTests { } @Test - public void canCallMethodWithNoArgumentsOnBuiltin() { - val result = eval(emptyEnvironment(), - methodCall(literal("hello"), "length")); - assertEquals(new IntegerInterpreterValue(5), result); - } - - @Test public void canCallMethodWithArgumentsOnBuiltin() { val result = eval(emptyEnvironment(), methodCall(literal("hello"), "substring", literal(1), literal(4))); |
