Details
Description
Logical operator ('or') are not working properly:
'or' has different result from '||'; compile mode work different from no compile mode also.
Check the following code and results:
public void testCalculate() {
Map vars = new LinkedHashMap();
vars.put("bal", new BigDecimal("999.99"));
String[] testCases =
{ "bal < 100 or bal > 200", // "bal < 100 || bal > 200", // "bal > 200 or bal < 100", // "bal > 200 || bal < 100", // "bal < 100 and bal > 200", // "bal < 100 && bal > 200", // "bal > 200 and bal < 100", // "bal > 200 && bal < 100", // };
log.info("bal = " + vars.get("bal"));
for (String expr : testCases)
{ log.info("Evaluating '" + expr + "': ......"); Object ret = MVEL.eval(expr, vars); log.info("'" + expr + " ' = " + ret.toString()); Assert.assertNotNull(ret); // test in compile mode Serializable compiled = MVEL.compileExpression(expr); ret = MVEL.executeExpression(compiled, vars); log.info("'" + expr + " ' = " + ret.toString()); Assert.assertNotNull(ret); }} // end method testCalculate
GenericTests.testCalculate(45) | bal = 999.99
GenericTests.testCalculate(48) | Evaluating 'bal < 100 or bal > 200': ......
GenericTests.testCalculate(51) | 'bal < 100 or bal > 200 ' = false
GenericTests.testCalculate(57) | 'bal < 100 or bal > 200 ' = false
GenericTests.testCalculate(48) | Evaluating 'bal < 100 || bal > 200': ......
GenericTests.testCalculate(51) | 'bal < 100 || bal > 200 ' = true
GenericTests.testCalculate(57) | 'bal < 100 || bal > 200 ' = true
GenericTests.testCalculate(48) | Evaluating 'bal > 200 or bal < 100': ......
GenericTests.testCalculate(51) | 'bal > 200 or bal < 100 ' = false
GenericTests.testCalculate(57) | 'bal > 200 or bal < 100 ' = true
GenericTests.testCalculate(48) | Evaluating 'bal > 200 || bal < 100': ......
GenericTests.testCalculate(51) | 'bal > 200 || bal < 100 ' = true
GenericTests.testCalculate(57) | 'bal > 200 || bal < 100 ' = true
GenericTests.testCalculate(48) | Evaluating 'bal < 100 and bal > 200': ......
GenericTests.testCalculate(51) | 'bal < 100 and bal > 200 ' = false
GenericTests.testCalculate(57) | 'bal < 100 and bal > 200 ' = false
GenericTests.testCalculate(48) | Evaluating 'bal < 100 && bal > 200': ......
GenericTests.testCalculate(51) | 'bal < 100 && bal > 200 ' = false
GenericTests.testCalculate(57) | 'bal < 100 && bal > 200 ' = false
GenericTests.testCalculate(48) | Evaluating 'bal > 200 and bal < 100': ......
GenericTests.testCalculate(51) | 'bal > 200 and bal < 100 ' = false
GenericTests.testCalculate(57) | 'bal > 200 and bal < 100 ' = false
GenericTests.testCalculate(48) | Evaluating 'bal > 200 && bal < 100': ......
GenericTests.testCalculate(51) | 'bal > 200 && bal < 100 ' = false
GenericTests.testCalculate(57) | 'bal > 200 && bal < 100 ' = false