Skip to content

Commit 107f47c

Browse files
committed
Add tests for status quo for SpEL compiler
1 parent fad544e commit 107f47c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ void indexIntoMap() {
536536
assertCanCompile(expression);
537537
assertThat(expression.getValue(map)).isEqualTo(111);
538538
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/Object");
539+
540+
// String key not enclosed in single quotes
541+
expression = parser.parseExpression("[aaa]");
542+
543+
assertThat(expression.getValue(map)).isEqualTo(111);
544+
assertCanCompile(expression);
545+
assertThat(expression.getValue(map)).isEqualTo(111);
546+
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/Object");
539547
}
540548

541549
@Test
@@ -644,6 +652,19 @@ void indexIntoMapOfPrimitiveIntArrayWithCompilableMapAccessor() {
644652
assertThat(getAst().getExitDescriptor()).isEqualTo("I");
645653
}
646654

655+
@Test
656+
void indexIntoStringCannotBeCompiled() {
657+
String text = "enigma";
658+
659+
// "g" is the 4th letter in "enigma" (index 3)
660+
expression = parser.parseExpression("[3]");
661+
662+
assertThat(expression.getValue(text)).isEqualTo("g");
663+
assertCannotCompile(expression);
664+
assertThat(expression.getValue(text)).isEqualTo("g");
665+
assertThat(getAst().getExitDescriptor()).isNull();
666+
}
667+
647668
@Test
648669
void indexIntoObject() {
649670
TestClass6 tc = new TestClass6();

0 commit comments

Comments
 (0)