SpelNodeImpl manages start/end position in separate integer values
Fixes gh-22157
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.ExpressionState;
|
||||
@@ -45,16 +44,16 @@ public class OpPlusTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_emptyOperands() {
|
||||
new OpPlus(-1);
|
||||
new OpPlus(-1, -1);
|
||||
}
|
||||
|
||||
@Test(expected = SpelEvaluationException.class)
|
||||
public void test_unaryPlusWithStringLiteral() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral str = new StringLiteral("word", -1, "word");
|
||||
StringLiteral str = new StringLiteral("word", -1, -1, "word");
|
||||
|
||||
OpPlus o = new OpPlus(-1, str);
|
||||
OpPlus o = new OpPlus(-1, -1, str);
|
||||
o.getValueInternal(expressionState);
|
||||
}
|
||||
|
||||
@@ -63,8 +62,8 @@ public class OpPlusTests {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
{
|
||||
RealLiteral realLiteral = new RealLiteral("123.00", -1, 123.0);
|
||||
OpPlus o = new OpPlus(-1, realLiteral);
|
||||
RealLiteral realLiteral = new RealLiteral("123.00", -1, -1, 123.0);
|
||||
OpPlus o = new OpPlus(-1, -1, realLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -73,8 +72,8 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
{
|
||||
IntLiteral intLiteral = new IntLiteral("123", -1, 123);
|
||||
OpPlus o = new OpPlus(-1, intLiteral);
|
||||
IntLiteral intLiteral = new IntLiteral("123", -1, -1, 123);
|
||||
OpPlus o = new OpPlus(-1, -1, intLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -83,8 +82,8 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
{
|
||||
LongLiteral longLiteral = new LongLiteral("123", -1, 123L);
|
||||
OpPlus o = new OpPlus(-1, longLiteral);
|
||||
LongLiteral longLiteral = new LongLiteral("123", -1, -1, 123L);
|
||||
OpPlus o = new OpPlus(-1, -1, longLiteral);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -98,9 +97,9 @@ public class OpPlusTests {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
{
|
||||
RealLiteral n1 = new RealLiteral("123.00", -1, 123.0);
|
||||
RealLiteral n2 = new RealLiteral("456.00", -1, 456.0);
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
RealLiteral n1 = new RealLiteral("123.00", -1, -1, 123.0);
|
||||
RealLiteral n2 = new RealLiteral("456.00", -1, -1, 456.0);
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -109,9 +108,9 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
{
|
||||
LongLiteral n1 = new LongLiteral("123", -1, 123L);
|
||||
LongLiteral n2 = new LongLiteral("456", -1, 456L);
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
LongLiteral n1 = new LongLiteral("123", -1, -1, 123L);
|
||||
LongLiteral n2 = new LongLiteral("456", -1, -1, 456L);
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -120,9 +119,9 @@ public class OpPlusTests {
|
||||
}
|
||||
|
||||
{
|
||||
IntLiteral n1 = new IntLiteral("123", -1, 123);
|
||||
IntLiteral n2 = new IntLiteral("456", -1, 456);
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
IntLiteral n1 = new IntLiteral("123", -1, -1, 123);
|
||||
IntLiteral n2 = new IntLiteral("456", -1, -1, 456);
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -135,9 +134,9 @@ public class OpPlusTests {
|
||||
public void test_binaryPlusWithStringOperands() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral n1 = new StringLiteral("\"foo\"", -1, "\"foo\"");
|
||||
StringLiteral n2 = new StringLiteral("\"bar\"", -1, "\"bar\"");
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
StringLiteral n1 = new StringLiteral("\"foo\"", -1, -1, "\"foo\"");
|
||||
StringLiteral n2 = new StringLiteral("\"bar\"", -1, -1, "\"bar\"");
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -149,9 +148,9 @@ public class OpPlusTests {
|
||||
public void test_binaryPlusWithLeftStringOperand() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
StringLiteral n1 = new StringLiteral("\"number is \"", -1, "\"number is \"");
|
||||
LongLiteral n2 = new LongLiteral("123", -1, 123);
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
StringLiteral n1 = new StringLiteral("\"number is \"", -1, -1, "\"number is \"");
|
||||
LongLiteral n2 = new LongLiteral("123", -1, -1, 123);
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -163,9 +162,9 @@ public class OpPlusTests {
|
||||
public void test_binaryPlusWithRightStringOperand() {
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
LongLiteral n1 = new LongLiteral("123", -1, 123);
|
||||
StringLiteral n2 = new StringLiteral("\" is a number\"", -1, "\" is a number\"");
|
||||
OpPlus o = new OpPlus(-1, n1, n2);
|
||||
LongLiteral n1 = new LongLiteral("123", -1, -1, 123);
|
||||
StringLiteral n2 = new StringLiteral("\" is a number\"", -1, -1, "\" is a number\"");
|
||||
OpPlus o = new OpPlus(-1, -1, n1, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -175,16 +174,14 @@ public class OpPlusTests {
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithTime_ToString() {
|
||||
|
||||
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
|
||||
|
||||
Time time = new Time(new Date().getTime());
|
||||
|
||||
VariableReference var = new VariableReference("timeVar", -1);
|
||||
VariableReference var = new VariableReference("timeVar", -1, -1);
|
||||
var.setValue(expressionState, time);
|
||||
|
||||
StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
|
||||
OpPlus o = new OpPlus(-1, var, n2);
|
||||
StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\"");
|
||||
OpPlus o = new OpPlus(-1, -1, var, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
@@ -194,29 +191,22 @@ public class OpPlusTests {
|
||||
|
||||
@Test
|
||||
public void test_binaryPlusWithTimeConverted() {
|
||||
|
||||
final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
|
||||
SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
|
||||
|
||||
GenericConversionService conversionService = new GenericConversionService();
|
||||
conversionService.addConverter(new Converter<Time, String>() {
|
||||
@Override
|
||||
public String convert(Time source) {
|
||||
return format.format(source);
|
||||
}
|
||||
});
|
||||
conversionService.addConverter(Time.class, String.class, format::format);
|
||||
|
||||
StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext();
|
||||
evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService));
|
||||
|
||||
ExpressionState expressionState = new ExpressionState(evaluationContextConverter);
|
||||
|
||||
Time time = new Time(new Date().getTime());
|
||||
|
||||
VariableReference var = new VariableReference("timeVar", -1);
|
||||
VariableReference var = new VariableReference("timeVar", -1, -1);
|
||||
var.setValue(expressionState, time);
|
||||
|
||||
StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
|
||||
OpPlus o = new OpPlus(-1, var, n2);
|
||||
StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\"");
|
||||
OpPlus o = new OpPlus(-1, -1, var, n2);
|
||||
TypedValue value = o.getValueInternal(expressionState);
|
||||
|
||||
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
|
||||
|
||||
Reference in New Issue
Block a user