Remove non-valued return

(cherry picked from commit 42e515f43523ffbfe0b28c2f3f5c342e4d4b1c1d)
This commit is contained in:
Octavia Togami
2020-02-25 16:13:44 -08:00
committed by MattBDev
parent 8c385b0593
commit 6d9f30e6a6
4 changed files with 31 additions and 10 deletions

View File

@ -103,6 +103,12 @@ class ExpressionTest extends BaseExpressionTest {
() -> compile("x()"));
assertEquals(0, e.getPosition(), "Error position");
}
{
// verify that you must return a value
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("return"));
assertEquals(6, e.getPosition(), "Error position");
}
assertThrows(ExpressionException.class,
() -> compile("("));
assertThrows(ExpressionException.class,
@ -156,6 +162,24 @@ class ExpressionTest extends BaseExpressionTest {
public void testWhile() throws ExpressionException {
checkTestCase("c=5; a=0; while (c > 0) { ++a; --c; } a", 5);
checkTestCase("c=5; a=0; do { ++a; --c; } while (c > 0); a", 5);
checkTestCase("" +
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" --c;" +
" if (c == 1) break;" +
"}" +
"a", 4);
checkTestCase("" +
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" if (a < 5) continue;" +
" --c;" +
"}" +
"a", 9);
}
@Test