From bc06840e00425db342bc5a021c0900d9e63b71f0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 15 Jul 2016 14:23:47 +0100 Subject: Split switch handling off to desugar step --- .../org/zwobble/couscous/tests/CompilerTests.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/test/java/org/zwobble/couscous/tests/CompilerTests.java') diff --git a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java index be3ca29..94c6e6a 100644 --- a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java +++ b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java @@ -288,6 +288,30 @@ public abstract class CompilerTests { Types.INT)); } + @Test + public void switchStatements() throws Exception { + switchStatementTest("simpleReturn", "one", 1); + switchStatementTest("simpleReturn", "zero", 0); + + switchStatementTest("simpleFallthroughReturn", "one", 1); + switchStatementTest("simpleFallthroughReturn", "two", 1); + switchStatementTest("simpleFallthroughReturn", "zero", 0); + + switchStatementTest("noDefaultReturn", "one", 1); + switchStatementTest("noDefaultReturn", "zero", 0); + } + + private void switchStatementTest(String methodName, String input, int expected) throws Exception { + assertEquals( + value(expected), + execTestProgram( + "switch-statements", + ScalarType.of("com.example.SwitchStatements"), + methodName, + list(value(input)), + Types.INT)); + } + @Test public void stringAdd() throws Exception { assertEquals(value("42"), evalExpression(Types.STRING, "\"4\" + \"2\"")); -- cgit v1.2.3