use of cn.taketoday.expression.Expression in project today-infrastructure by TAKETODAY.
the class SpelReproTests method SPR10417.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void SPR10417() {
List list1 = new ArrayList();
list1.add("a");
list1.add("b");
list1.add("x");
List list2 = new ArrayList();
list2.add("c");
list2.add("x");
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("list1", list1);
context.setVariable("list2", list2);
// #this should be the element from list1
Expression ex = parser.parseExpression("#list1.?[#list2.contains(#this)]");
Object result = ex.getValue(context);
assertThat(result.toString()).isEqualTo("[x]");
// toString() should be called on the element from list1
ex = parser.parseExpression("#list1.?[#list2.contains(toString())]");
result = ex.getValue(context);
assertThat(result.toString()).isEqualTo("[x]");
List list3 = new ArrayList();
list3.add(1);
list3.add(2);
list3.add(3);
list3.add(4);
context = new StandardEvaluationContext();
context.setVariable("list3", list3);
ex = parser.parseExpression("#list3.?[#this > 2]");
result = ex.getValue(context);
assertThat(result.toString()).isEqualTo("[3, 4]");
ex = parser.parseExpression("#list3.?[#this >= T(java.lang.Math).abs(T(java.lang.Math).abs(#this))]");
result = ex.getValue(context);
assertThat(result.toString()).isEqualTo("[1, 2, 3, 4]");
}
use of cn.taketoday.expression.Expression in project today-infrastructure by TAKETODAY.
the class SpelReproTests method SPR9486_addFloatWithFloat.
@Test
void SPR9486_addFloatWithFloat() {
Number expectedNumber = 10.21f + 10.2f;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = parser.parseExpression("10.21f + 10.2f");
Number result = expression.getValue(context, null, Number.class);
assertThat(result).isEqualTo(expectedNumber);
}
use of cn.taketoday.expression.Expression in project today-infrastructure by TAKETODAY.
the class SpelReproTests method SPR9486_floatPowerDouble.
@Test
void SPR9486_floatPowerDouble() {
Number expectedResult = Math.pow(10.21f, 10.2);
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = parser.parseExpression("10.21f ^ 10.2");
Number result = expression.getValue(context, null, Number.class);
assertThat(result).isEqualTo(expectedResult);
}
use of cn.taketoday.expression.Expression in project today-infrastructure by TAKETODAY.
the class TemplateExpressionParsingTests method testParsingSimpleTemplateExpression04.
@Test
public void testParsingSimpleTemplateExpression04() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
assertThat(o.toString()).isEqualTo("hello world");
expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
o = expr.getValue();
assertThat(o.toString()).isEqualTo("");
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
o = expr.getValue();
assertThat(o.toString()).isEqualTo("abc");
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
o = expr.getValue((Object) null);
assertThat(o.toString()).isEqualTo("abc");
}
use of cn.taketoday.expression.Expression in project today-infrastructure by TAKETODAY.
the class TemplateExpressionParsingTests method testParsingNormalExpressionThroughTemplateParser.
@Test
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
Expression expr = parser.parseExpression("1+2+3");
assertThat(expr.getValue()).isEqualTo(6);
}
Aggregations