Skip to content

Commit

Permalink
Polish SpelParserTests and TemplateExpressionParsingTests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Apr 25, 2023
1 parent 5dacf50 commit ca13b5c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,34 @@ class TemplateExpressionParsingTests extends AbstractExpressionTests {

static final ParserContext DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT = new TemplateParserContext("${", "}");

private final SpelExpressionParser parser = new SpelExpressionParser();



@Test
void parsingSimpleTemplateExpression01() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void parsingSimpleTemplateExpression01() {
Expression expr = parser.parseExpression("hello ${'world'}", DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
assertThat(o.toString()).isEqualTo("hello world");
}

@Test
void parsingSimpleTemplateExpression02() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void parsingSimpleTemplateExpression02() {
Expression expr = parser.parseExpression("hello ${'to'} you", DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
assertThat(o.toString()).isEqualTo("hello to you");
}

@Test
void parsingSimpleTemplateExpression03() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void parsingSimpleTemplateExpression03() {
Expression expr = parser.parseExpression("The quick ${'brown'} fox jumped over the ${'lazy'} dog",
DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
assertThat(o.toString()).isEqualTo("The quick brown fox jumped over the lazy dog");
}

@Test
void parsingSimpleTemplateExpression04() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void parsingSimpleTemplateExpression04() {
Expression expr = parser.parseExpression("${'hello'} world", DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
assertThat(o.toString()).isEqualTo("hello world");
Expand All @@ -87,8 +86,7 @@ void parsingSimpleTemplateExpression04() throws Exception {
}

@Test
void compositeStringExpression() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void compositeStringExpression() {
Expression ex = parser.parseExpression("hello ${'world'}", DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
assertThat(ex.getValue()).isInstanceOf(String.class).isEqualTo("hello world");
assertThat(ex.getValue(String.class)).isInstanceOf(String.class).isEqualTo("hello world");
Expand Down Expand Up @@ -127,8 +125,7 @@ void compositeStringExpression() throws Exception {
static class Rooty {}

@Test
void nestedExpressions() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
void nestedExpressions() {
// treat the nested ${..} as a part of the expression
Expression ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} world",DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
Expand Down Expand Up @@ -158,7 +155,7 @@ void nestedExpressions() throws Exception {
}

@Test
void clashingWithSuffixes() throws Exception {
void clashingWithSuffixes() {
// Just wanting to use the prefix or suffix within the template:
Expression ex = parser.parseExpression("hello ${3+4} world",DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT);
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
Expand All @@ -174,13 +171,13 @@ void clashingWithSuffixes() throws Exception {
}

@Test
void parsingNormalExpressionThroughTemplateParser() throws Exception {
void parsingNormalExpressionThroughTemplateParser() {
Expression expr = parser.parseExpression("1+2+3");
assertThat(expr.getValue()).isEqualTo(6);
}

@Test
void errorCases() throws Exception {
void errorCases() {
assertThatExceptionOfType(ParseException.class).isThrownBy(() ->
parser.parseExpression("hello ${'world'", DOLLAR_SIGN_TEMPLATE_PARSER_CONTEXT))
.satisfies(pex -> {
Expand Down
Loading

0 comments on commit ca13b5c

Please sign in to comment.