diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-04 17:27:54 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-04 17:27:54 +0100 |
| commit | e8c8fe86c757bd1208427c0ad4f8134f1b1bff1f (patch) | |
| tree | cf5dea583a0c0222af227aa439729422f274d1cd /src/test/java | |
| parent | 87f73abf5e7dcec6a9f5ebd213f4a9eb0a5d45db (diff) | |
Throw exception if getting value of variable out of scope
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterTests.java | 13 |
1 files changed, 13 insertions, 0 deletions
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(); |
