Support symbolic boolean operators for OR and AND
SpEL typically supports logical operators for boolean expressions consistent with standard Java language syntax. However, the operators for logical AND and logical OR are currently only supported as textual operators. In other words, SpEL does not support the use of && and || as logical operators. The SpEL tokenizer has now been modified to recognize && and || as symbolic boolean operators. The parser has been modified to allow the use of either the textual or symbolic operators. Issue: SPR-9614
This commit is contained in:
committed by
Sam Brannen
parent
6249539426
commit
58e6214b7b
@@ -70,7 +70,7 @@ public class SpelParserTests {
|
||||
assertEquals(5, expr.getValue());
|
||||
expr = parser.parseRaw("2 + 3");
|
||||
assertEquals(5, expr.getValue());
|
||||
expr = parser.parseRaw("2\n+ 3");
|
||||
expr = parser.parseRaw("2\n+\t3");
|
||||
assertEquals(5, expr.getValue());
|
||||
expr = parser.parseRaw("2\r\n+\t3");
|
||||
assertEquals(5, expr.getValue());
|
||||
@@ -229,6 +229,24 @@ public class SpelParserTests {
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators_symbolic_spr9614() throws EvaluationException, ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("false && false");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("true && (true || false)");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("true && true || false");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("!true");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("!(false || true)");
|
||||
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiterals() throws EvaluationException, ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'");
|
||||
|
||||
Reference in New Issue
Block a user