Search in sources :

Example 6 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9486_floatGreaterThanDouble.

@Test
void SPR9486_floatGreaterThanDouble() {
    Boolean expectedResult = -10.21f > -10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("-10.21f > -10.2");
    Boolean result = expression.getValue(context, null, Boolean.class);
    assertThat(result).isEqualTo(expectedResult);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 7 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR12035.

@Test
void SPR12035() {
    ExpressionParser parser = new SpelExpressionParser();
    Expression expression1 = parser.parseExpression("list.?[ value>2 ].size()!=0");
    assertThat(expression1.getValue(new BeanClass(new ListOf(1.1), new ListOf(2.2)), Boolean.class)).isTrue();
    Expression expression2 = parser.parseExpression("list.?[ T(java.lang.Math).abs(value) > 2 ].size()!=0");
    assertThat(expression2.getValue(new BeanClass(new ListOf(1.1), new ListOf(-2.2)), Boolean.class)).isTrue();
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 8 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9486_floatEqFloat.

@Test
void SPR9486_floatEqFloat() {
    Boolean expectedResult = 10.215f == 10.2109f;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.215f == 10.2109f");
    Boolean result = expression.getValue(context, null, Boolean.class);
    assertThat(result).isEqualTo(expectedResult);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 9 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelDocumentationTests method equalityCheck.

@Test
void equalityCheck() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(tesla);
    Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
    // evaluates to true
    boolean isEqual = exp.getValue(context, Boolean.class);
    assertThat(isEqual).isTrue();
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 10 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelDocumentationTests method propertyNavigation.

@Test
void propertyNavigation() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    // Inventions Array
    StandardEvaluationContext teslaContext = TestScenarioCreator.getTestEvaluationContext();
    // teslaContext.setRootObject(tesla);
    // evaluates to "Induction motor"
    String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
    assertThat(invention).isEqualTo("Induction motor");
    // Members List
    StandardEvaluationContext societyContext = new StandardEvaluationContext();
    IEEE ieee = new IEEE();
    ieee.Members[0] = tesla;
    societyContext.setRootObject(ieee);
    // evaluates to "Nikola Tesla"
    String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
    assertThat(name).isEqualTo("Nikola Tesla");
    // List and Array navigation
    // evaluates to "Wireless communication"
    invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
    assertThat(invention).isEqualTo("Wireless communication");
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Aggregations

ExpressionParser (cn.taketoday.expression.ExpressionParser)132 SpelExpressionParser (cn.taketoday.expression.spel.standard.SpelExpressionParser)132 Test (org.junit.jupiter.api.Test)132 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)112 Expression (cn.taketoday.expression.Expression)110 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)72 EvaluationContext (cn.taketoday.expression.EvaluationContext)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 Map (java.util.Map)10 EvaluationException (cn.taketoday.expression.EvaluationException)6 MethodResolver (cn.taketoday.expression.MethodResolver)6 ReflectiveMethodResolver (cn.taketoday.expression.spel.support.ReflectiveMethodResolver)6 Method (java.lang.reflect.Method)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 TreeMap (java.util.TreeMap)6 MethodParameter (cn.taketoday.core.MethodParameter)4 TypeDescriptor (cn.taketoday.core.TypeDescriptor)4 AccessException (cn.taketoday.expression.AccessException)4