You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2018/09/13 16:26:33 UTC
[commons-jexl] 03/04: JEXL: more tests on do...while loops
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
commit 4c17fb2790a2837ab2e2d49b3860c2700ff5609f
Author: henrib <he...@apache.org>
AuthorDate: Thu Sep 13 18:05:37 2018 +0200
JEXL: more tests on do...while loops
---
.../java/org/apache/commons/jexl3/DoWhileTest.java | 35 ++++++++++++----------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
index a01e851..b712821 100644
--- a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
+++ b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
@@ -20,8 +20,8 @@ import org.junit.Assert;
import org.junit.Test;
/**
- * Tests for while statement.
- * @since 1.1
+ * Tests do while statement.
+ * @since 3.2
*/
@SuppressWarnings({"UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes"})
public class DoWhileTest extends JexlTestCase {
@@ -37,16 +37,32 @@ public class DoWhileTest extends JexlTestCase {
Object o = e.execute(jc);
Assert.assertNull("Result is not null", o);
+ e = JEXL.createScript("do {} while (false); 23");
+ o = e.execute(jc);
+ Assert.assertEquals(23, o);
+
}
@Test
public void testWhileExecutesExpressionWhenLooping() throws Exception {
JexlScript e = JEXL.createScript("do x = x + 1 while (x < 10)");
JexlContext jc = new MapContext();
- jc.set("x", new Integer(1));
+ jc.set("x", 1);
Object o = e.execute(jc);
- Assert.assertEquals("Result is wrong", new Integer(10), o);
+ Assert.assertEquals(10, o);
+ Assert.assertEquals(10, jc.get("x"));
+
+ e = JEXL.createScript("var x = 0; do x += 1; while (x < 23)");
+ o = e.execute(jc);
+ Assert.assertEquals(23, o);
+
+
+ jc.set("x", 1);
+ e = JEXL.createScript("do x += 1; while (x < 23); return 42;");
+ o = e.execute(jc);
+ Assert.assertEquals(23, jc.get("x"));
+ Assert.assertEquals(42, o);
}
@Test
@@ -62,15 +78,4 @@ public class DoWhileTest extends JexlTestCase {
Assert.assertEquals("y is wrong", new Integer(512), jc.get("y"));
}
- @Test
- public void testWhileRemoveBroken() throws Exception {
- try {
- JexlScript e = JEXL.createScript("do remove while (x < 10)");
- Assert.fail("remove is out of loop!");
- } catch (JexlException.Parsing xparse) {
- String str = xparse.detailedMessage();
- Assert.assertTrue(str.contains("remove"));
- }
- }
-
}