From e8c8fe86c757bd1208427c0ad4f8134f1b1bff1f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 4 Oct 2015 17:27:54 +0100 Subject: Throw exception if getting value of variable out of scope --- .../couscous/tests/interpreter/InterpreterTests.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/test/java') 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 66a1f8b..58a1b6b 100644 --- a/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java +++ b/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java @@ -117,6 +117,19 @@ public class InterpreterTests { assertEquals(new VariableNotInScope(42), exception); } + + @Test + public void errorIfTryingToGetValueOfVariableNotInScope() { + val localVariableDeclaration = localVariableDeclaration( + 42, StringValue.REF, "x", literal("")); + val method = staticMethod("hello") + .statement(new ReturnNode(reference(localVariableDeclaration))); + + val exception = assertThrows(VariableNotInScope.class, + () -> runMethod(method)); + + assertEquals(new VariableNotInScope(42), exception); + } private InterpreterValue runMethod(MethodNode.MethodNodeBuilder methodBuilder, InterpreterValue... arguments) { val method = methodBuilder.build(); -- cgit v1.2.3