Skip to content
Permalink
Browse files
JEXL-360: missed a few test cases;
- opportunistic fix of '%=' not being controlled for side-effects;
  • Loading branch information
henrib committed May 9, 2022
1 parent 72490fa commit 57b6a5a4b6db0fe9f75b7ef73dabaf60bd09d17f
Showing 4 changed files with 29 additions and 4 deletions.
@@ -214,6 +214,11 @@ protected Object visit(final ASTSetDivNode node, final Object data) {
return controlSideEffect(node, data);
}

@Override
protected Object visit(final ASTSetModNode node, final Object data) {
return controlSideEffect(node, data);
}

@Override
protected Object visit(final ASTSetAndNode node, final Object data) {
return controlSideEffect(node, data);
@@ -125,9 +125,13 @@ public void testNoSideEffects() throws Exception {
"x -= 1",
"x *= 1",
"x /= 1",
"x %= 1",
"x ^= 1",
"x &= 1",
"x |= 1",
"x >>= 1",
"x <<= 1",
"x >>>= 1",
};
checkFeature(f, scripts);
}
@@ -151,10 +151,14 @@ public Object shiftRightUnsigned(String value, StringBuilder c) {
@Test
public void testOverloadedShift() throws Exception {
JexlEngine jexl = new JexlBuilder().arithmetic(new ShiftArithmetic(true)).create();
JexlScript e = jexl.createScript("x << 'Left'", "x");
StringBuilder x = new StringBuilder("1");
Object o = e.execute(null, x);
Assert.assertEquals(e.getSourceText(), "1Left", x.toString());
StringBuilder x;
JexlScript e;
Object o;

x = new StringBuilder("1");
e = jexl.createScript("x << 'Left'", "x");
o = e.execute(null, x);
Assert.assertEquals(e.getSourceText(), "1Left", o.toString());

e = jexl.createScript("'Right' >> x", "x");
x = new StringBuilder("1");
@@ -89,6 +89,18 @@ public void testSideEffectVar() throws Exception {
context.put("foo", foo);
asserter.assertExpression("foo ^= 2", (long)(i41 ^ 2));
Assert.assertEquals(context.get("foo"), (long)(i41 ^ 2));

context.put("foo", foo);
asserter.assertExpression("foo <<= 2", (long)(i41 << 2));
Assert.assertEquals(context.get("foo"), (long)(i41 << 2));

context.put("foo", foo);
asserter.assertExpression("foo >>= 2", (long)(i41 >> 2));
Assert.assertEquals(context.get("foo"), (long)(i41 >> 2));

context.put("foo", foo);
asserter.assertExpression("foo >>>= 2", (long)(i41 >>> 2));
Assert.assertEquals(context.get("foo"), (long)(i41 >>> 2));
}

@Test

0 comments on commit 57b6a5a

Please sign in to comment.