Skip to content

Commit f2fc5c0

Browse files
committed
Functions valudation
1 parent c06f23a commit f2fc5c0

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

src/main/antlr4/dev/vepo/jsonata/functions/generated/JSONataGrammar.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ expression:
3636
| BOOLEAN # booleanValue
3737
;
3838

39-
functionStatement: FV_NAME '(' parameterStatement (',' parameterStatement)* ')' ;
39+
functionStatement: FV_NAME (('(' parameterStatement (',' parameterStatement)* ')') | '()' ) ;
4040
parameterStatement: expression | functionDeclaration;
4141
functionDeclaration:
4242
'function' '(' FV_NAME (',' FV_NAME)* ')' '{' expression+ '}' # functionDeclarationBuilder

src/main/java/dev/vepo/jsonata/functions/buildin/LengthJSONataFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public record LengthJSONataFunction(List<JSONataFunction> providers) implements
1010

1111
public LengthJSONataFunction {
1212
if (providers.size() != 1) {
13-
throw new IllegalArgumentException("$length function must have 1 argument");
13+
throw new IllegalArgumentException("$length function must have 1 argument!");
1414
}
1515
}
1616

src/main/java/dev/vepo/jsonata/functions/buildin/LowecaseJSONataFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public record LowecaseJSONataFunction(List<JSONataFunction> providers) implements JSONataFunction {
1010
public LowecaseJSONataFunction {
1111
if (providers.size() != 1) {
12-
throw new IllegalArgumentException("$lowecase function must have 1 argument!");
12+
throw new IllegalArgumentException("$lowercase function must have 1 argument!");
1313
}
1414
}
1515

src/main/java/dev/vepo/jsonata/functions/buildin/StringJSONataFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public record StringJSONataFunction(List<JSONataFunction> providers) implements JSONataFunction {
1010
public StringJSONataFunction {
1111
if (providers.size() != 1) {
12-
throw new IllegalArgumentException("$string function must have 1 argument");
12+
throw new IllegalArgumentException("$string function must have 1 argument!");
1313
}
1414
}
1515

src/main/java/dev/vepo/jsonata/functions/buildin/UppercaseJSONataFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public record UppercaseJSONataFunction(List<JSONataFunction> providers) implements JSONataFunction {
1010
public UppercaseJSONataFunction {
1111
if (providers.size() != 1) {
12-
throw new IllegalArgumentException("$uppercase function must have 1 argument");
12+
throw new IllegalArgumentException("$uppercase function must have 1 argument!");
1313
}
1414
}
1515

src/test/java/dev/vepo/jsonata/JSONataTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ void literalTest() {
261261

262262
@Nested
263263
class Functions {
264+
@Test
265+
void argumentValidationTest() {
266+
assertThatThrownBy(() -> jsonata("$string()")).isInstanceOf(IllegalArgumentException.class)
267+
.hasMessage("$string function must have 1 argument!");
268+
assertThatThrownBy(() -> jsonata("$length()")).isInstanceOf(IllegalArgumentException.class)
269+
.hasMessage("$length function must have 1 argument!");
270+
assertThatThrownBy(() -> jsonata("$lowercase()")).isInstanceOf(IllegalArgumentException.class)
271+
.hasMessage("$lowercase function must have 1 argument!");
272+
assertThatThrownBy(() -> jsonata("$uppercase()")).isInstanceOf(IllegalArgumentException.class)
273+
.hasMessage("$uppercase function must have 1 argument!");
274+
275+
}
276+
264277
@Test
265278
void stringTest() {
266279
assertThat(jsonata("$string(5)").evaluate("{}").asText()).isEqualTo("5");

0 commit comments

Comments
 (0)