File tree Expand file tree Collapse file tree 6 files changed +18
-5
lines changed
antlr4/dev/vepo/jsonata/functions/generated
java/dev/vepo/jsonata/functions/buildin
test/java/dev/vepo/jsonata Expand file tree Collapse file tree 6 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ expression:
3636 | BOOLEAN # booleanValue
3737 ;
3838
39- functionStatement : FV_NAME ' (' parameterStatement (' ,' parameterStatement)* ' )' ;
39+ functionStatement : FV_NAME (( ' (' parameterStatement (' ,' parameterStatement)* ' )' ) | ' () ' ) ;
4040parameterStatement : expression | functionDeclaration;
4141functionDeclaration :
4242 ' function' ' (' FV_NAME (' ,' FV_NAME )* ' )' ' {' expression+ ' }' # functionDeclarationBuilder
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 99public 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
Original file line number Diff line number Diff line change 99public 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
Original file line number Diff line number Diff line change 99public 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
Original file line number Diff line number Diff 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" );
You can’t perform that action at this time.
0 commit comments