Merge branch '6.1.x'

This commit is contained in:
Sam Brannen
2024-03-22 17:18:38 +01:00
3 changed files with 52 additions and 10 deletions

View File

@@ -55,6 +55,15 @@ public class Projection extends SpelNodeImpl {
}
/**
* Does this node represent a null-safe projection operation?
* @since 6.1.6
*/
@Override
public final boolean isNullSafe() {
return this.nullSafe;
}
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
return getValueRef(state).getValue();

View File

@@ -78,6 +78,15 @@ public class Selection extends SpelNodeImpl {
}
/**
* Does this node represent a null-safe selection operation?
* @since 6.1.6
*/
@Override
public final boolean isNullSafe() {
return this.nullSafe;
}
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
return getValueRef(state).getValue();

View File

@@ -44,9 +44,24 @@ class ParsingTests {
@Test
void compoundExpressions() {
parseCheck("#var1.methodOne().methodTwo(42)");
parseCheck("#func1().methodOne().methodTwo(42)");
parseCheck("#func2('enigma').methodOne().methodTwo(42)");
parseCheck("property1.property2.methodOne()");
parseCheck("property1[0].property2['key'].methodOne()");
parseCheck("property1.methodOne('enigma').methodTwo(42)");
parseCheck("property1.methodOne().property2.methodTwo()");
parseCheck("property1[0].property2['key'].methodTwo()");
parseCheck("property1[0][1].property2['key'][42].methodTwo()");
// null-safe variants
parseCheck("#var1?.methodOne()?.methodTwo(42)");
parseCheck("#func1()?.methodOne()?.methodTwo(42)");
parseCheck("#func2('enigma')?.methodOne()?.methodTwo(42)");
parseCheck("property1?.property2?.methodOne()");
parseCheck("property1?.methodOne('enigma')?.methodTwo(42)");
parseCheck("property1?.methodOne()?.property2?.methodTwo()");
parseCheck("property1[0]?.property2['key']?.methodTwo()");
parseCheck("property1[0][1]?.property2['key'][42]?.methodTwo()");
}
@Test
@@ -132,25 +147,34 @@ class ParsingTests {
@Test
void projection() {
parseCheck("{1,2,3,4,5,6,7,8,9,10}.![#isEven()]");
parseCheck("{1,2,3}.![#isEven()]");
// null-safe variant
parseCheck("{1,2,3}?.![#isEven()]");
}
@Test
void selection() {
parseCheck("{1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this) == 'y']",
"{1,2,3,4,5,6,7,8,9,10}.?[(#isEven(#this) == 'y')]");
parseCheck("{1,2,3}.?[#isEven(#this)]");
// null-safe variant
parseCheck("{1,2,3}?.?[#isEven(#this)]");
}
@Test
void selectionFirst() {
parseCheck("{1,2,3,4,5,6,7,8,9,10}.^[#isEven(#this) == 'y']",
"{1,2,3,4,5,6,7,8,9,10}.^[(#isEven(#this) == 'y')]");
void selectFirst() {
parseCheck("{1,2,3}.^[#isEven(#this)]");
// null-safe variant
parseCheck("{1,2,3}?.^[#isEven(#this)]");
}
@Test
void selectionLast() {
parseCheck("{1,2,3,4,5,6,7,8,9,10}.$[#isEven(#this) == 'y']",
"{1,2,3,4,5,6,7,8,9,10}.$[(#isEven(#this) == 'y')]");
void selectLast() {
parseCheck("{1,2,3}.$[#isEven(#this)]");
// null-safe variant
parseCheck("{1,2,3}?.$[#isEven(#this)]");
}
}