use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectionWithPrimitiveArray.
@Test
void selectionWithPrimitiveArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertThat(value.getClass().isArray()).isTrue();
TypedValue typedValue = new TypedValue(value);
assertThat(typedValue.getTypeDescriptor().getElementDescriptor().getType()).isEqualTo(Integer.class);
Integer[] array = (Integer[]) value;
assertThat(array).containsExactly(0, 1, 2, 3, 4);
}
use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.
the class SelectionAndProjectionTests method selectionWithArray.
@Test
void selectionWithArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertThat(value.getClass().isArray()).isTrue();
TypedValue typedValue = new TypedValue(value);
assertThat(typedValue.getTypeDescriptor().getElementDescriptor().getType()).isEqualTo(Integer.class);
Integer[] array = (Integer[]) value;
assertThat(array).containsExactly(0, 1, 2, 3, 4);
}
use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.
the class ExpressionStateTests method testActiveContextObject.
@Test
public void testActiveContextObject() {
ExpressionState state = getState();
assertThat(state.getActiveContextObject().getValue()).isEqualTo(state.getRootContextObject().getValue());
assertThatIllegalStateException().isThrownBy(state::popActiveContextObject);
state.pushActiveContextObject(new TypedValue(34));
assertThat(state.getActiveContextObject().getValue()).isEqualTo(34);
state.pushActiveContextObject(new TypedValue("hello"));
assertThat(state.getActiveContextObject().getValue()).isEqualTo("hello");
state.popActiveContextObject();
assertThat(state.getActiveContextObject().getValue()).isEqualTo(34);
state.popActiveContextObject();
assertThat(state.getActiveContextObject().getValue()).isEqualTo(state.getRootContextObject().getValue());
state = new ExpressionState(new StandardEvaluationContext());
assertThat(state.getActiveContextObject()).isEqualTo(TypedValue.NULL);
}
use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.
the class ExpressionStateTests method testVariables.
@Test
public void testVariables() {
ExpressionState state = getState();
TypedValue typedValue = state.lookupVariable("foo");
assertThat(typedValue).isEqualTo(TypedValue.NULL);
state.setVariable("foo", 34);
typedValue = state.lookupVariable("foo");
assertThat(typedValue.getValue()).isEqualTo(34);
assertThat(typedValue.getTypeDescriptor().getType()).isEqualTo(Integer.class);
state.setVariable("foo", "abc");
typedValue = state.lookupVariable("foo");
assertThat(typedValue.getValue()).isEqualTo("abc");
assertThat(typedValue.getTypeDescriptor().getType()).isEqualTo(String.class);
}
use of cn.taketoday.expression.TypedValue in project today-infrastructure by TAKETODAY.
the class ExpressionStateTests method testTypeConversion.
@Test
public void testTypeConversion() throws EvaluationException {
ExpressionState state = getState();
String s = (String) state.convertValue(34, TypeDescriptor.valueOf(String.class));
assertThat(s).isEqualTo("34");
s = (String) state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
assertThat(s).isEqualTo("34");
}
Aggregations