gnodet-bot commented on code in PR #26560:
URL: https://github.com/apache/camel/pull/26560#discussion_r4039371086
##########
components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java:
##########
@@ -112,6 +112,29 @@ public void nestedSimpleExpression() {
assertEquals(3, ((InParameter)
template.getParameterList().get(1)).getValueExtractor().eval(exchange, null));
}
+ @Test
+ public void simpleFunctionWithParentheses() {
+ Exchange exchange = createExchangeWithBody(42);
+ exchange.getIn().setHeader("bar", 3);
+ Template template = parser.parseTemplate(
+ "ADDNUMBERS2(INTEGER ${val(1)},VARCHAR ${bodyAs(String)},INOUT
INTEGER ${val(7)} inout1,OUT INTEGER out1)");
+
+ assertEquals(4, template.getParameterList().size());
+ assertEquals("1", ((InParameter)
template.getParameterList().get(0)).getValueExtractor().eval(exchange, null));
+ assertEquals("42", ((InParameter)
template.getParameterList().get(1)).getValueExtractor().eval(exchange, null));
+ assertEquals("7", ((InOutParameter)
template.getParameterList().get(2)).getValueExtractor().eval(exchange, null));
+ assertEquals("out1", ((OutParameter)
template.getParameterList().get(3)).getOutValueMapKey());
+ }
+
+ @Test
+ public void simpleFunctionAsLastParameter() {
+ // the closing parenthesis of the function must not be confused with
the end of the procedure
+ Exchange exchange = createExchangeWithBody(1);
+ Template template = parser.parseTemplate("ADDNUMBERS2(INTEGER
${val(1)} )");
+ assertEquals(1, template.getParameterList().size());
+ assertEquals("1", ((InParameter)
template.getParameterList().get(0)).getValueExtractor().eval(exchange, null));
+ }
+
@Test
Review Comment:
💡 **Missing negative test for the documented limitation.**
The docs explicitly state that multi-argument comma functions like
`${replace(a,b)}` are unsupported. Since `,` is not in `SIMPLE_EXP_TOKEN`'s
character class, the comma would be consumed as `SEPARATOR` and break the parse
— but there's no test asserting that this fails gracefully with
`ParseRuntimeException`.
Consider adding:
```java
@Test
public void multiArgFunctionShouldFail() {
// comma inside a Simple function is treated as SEPARATOR — grammar
cannot handle it
assertThrows(ParseRuntimeException.class,
() -> parser.parseTemplate("PROC(INTEGER ${replace(a,b)})"));
}
```
This pins the documented limitation so a future grammar expansion doesn't
silently change the behaviour.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]