fix for ternary or elvis using a full expression for their result components. parser polishing

This commit is contained in:
Andy Clement
2009-05-27 19:16:45 +00:00
parent 1a7ec7daf2
commit e5fea54aea
12 changed files with 172 additions and 192 deletions

View File

@@ -217,6 +217,7 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate("2>4?1:2",2,Integer.class);
}
@Test
public void testTernaryOperator02() {
evaluate("'abc'=='abc'?1:2",1,Integer.class);
@@ -233,6 +234,14 @@ public class EvaluationTests extends ExpressionTestCase {
Assert.assertFalse(expr.isWritable(eContext));
}
@Test
public void testTernaryOperator05() {
evaluate("1>2?#var=4:#var=5",5,Integer.class);
evaluate("3?:#var=5",3,Integer.class);
evaluate("null?:#var=5",5,Integer.class);
evaluate("2>4?(3>2?true:false):(5<3?true:false)",false,Boolean.class);
}
@Test
public void testIndexer03() {
evaluate("'christian'[8]", "n", String.class);

View File

@@ -85,7 +85,7 @@ public class HelperTests extends ExpressionTestCase {
// IntLiteral value:2
// ===> Expression '3+4+5+6+7-2' - AST end
Assert.assertTrue(s.indexOf("===> Expression '3+4+5+6+7-2' - AST start")!=-1);
Assert.assertTrue(s.indexOf(" OperatorPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
Assert.assertTrue(s.indexOf(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
}
@Test

View File

@@ -24,8 +24,8 @@ import org.springframework.expression.spel.SpelExpression;
import org.springframework.expression.spel.SpelMessages;
import org.springframework.expression.spel.SpelNode;
import org.springframework.expression.spel.SpelParseException;
import org.springframework.expression.spel.ast.OperatorAnd;
import org.springframework.expression.spel.ast.OperatorOr;
import org.springframework.expression.spel.ast.OpAnd;
import org.springframework.expression.spel.ast.OpOr;
public class SpelParserTests {
@@ -228,8 +228,8 @@ public class SpelParserTests {
public void testPositionalInformation() throws EvaluationException, ParseException {
SpelExpression expr = new SpelExpressionParser().parse("true and true or false");
SpelNode rootAst = expr.getAST();
OperatorOr operatorOr = (OperatorOr)rootAst;
OperatorAnd operatorAnd = (OperatorAnd)operatorOr.getLeftOperand();
OpOr operatorOr = (OpOr)rootAst;
OpAnd operatorAnd = (OpAnd)operatorOr.getLeftOperand();
SpelNode rightOrOperand = operatorOr.getRightOperand();
// check position for final 'false'