use of cn.taketoday.expression.ExpressionParser 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.ExpressionParser in project today-infrastructure by TAKETODAY.
the class SpelReproTests method SPR10091_simpleTestValueType.
@Test
void SPR10091_simpleTestValueType() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Class<?> valueType = parser.parseExpression("simpleProperty").getValueType(evaluationContext);
assertThat(valueType).isEqualTo(Boolean.class);
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class SpelExceptionTests method spelExpressionArrayWithVariables.
@Test
@SuppressWarnings("serial")
public void spelExpressionArrayWithVariables() {
ExpressionParser parser = new SpelExpressionParser();
Expression spelExpression = parser.parseExpression("#anArray[0] eq 1");
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariables(new HashMap<String, Object>() {
{
put("anArray", new int[] { 1, 2, 3 });
}
});
boolean result = spelExpression.getValue(ctx, Boolean.class);
assertThat(result).isTrue();
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class SpelExceptionTests method spelExpressionMapNullVariables.
@Test
public void spelExpressionMapNullVariables() {
ExpressionParser parser = new SpelExpressionParser();
Expression spelExpression = parser.parseExpression("#aMap.containsKey('one')");
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(spelExpression::getValue);
}
use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.
the class SpelExceptionTests method spelExpressionListIndexAccessWithVariables.
@Test
@SuppressWarnings("serial")
public void spelExpressionListIndexAccessWithVariables() {
ExpressionParser parser = new SpelExpressionParser();
Expression spelExpression = parser.parseExpression("#aList[0] eq 'one'");
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariables(new HashMap<String, Object>() {
{
put("aList", new ArrayList<String>() {
{
add("one");
add("two");
add("three");
}
});
}
});
boolean result = spelExpression.getValue(ctx, Boolean.class);
assertThat(result).isTrue();
}
Aggregations