Browse Source

Merge pull request #458 from thackem/master

Fix compiling of functions with single character arguments
pull/517/head
kallestenflo 6 years ago committed by GitHub
parent
commit
b5d66aba58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  2. 8
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java
  3. 6
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

2
json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java

@ -195,7 +195,7 @@ public class PathCompiler {
}
else if (c == OPEN_PARENTHESIS) {
isFunction = true;
endPosition = readPosition++;
endPosition = readPosition;
break;
}
readPosition++;

8
json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java

@ -296,6 +296,14 @@ public class PathCompilerTest {
assertThat(result).containsExactly("] it");
}
@Test
public void a_function_can_be_compiled() {
assertThat(compile("$.aaa.foo()").toString()).isEqualTo("$['aaa'].foo()");
assertThat(compile("$.aaa.foo(5)").toString()).isEqualTo("$['aaa'].foo(...)");
assertThat(compile("$.aaa.foo($.bar)").toString()).isEqualTo("$['aaa'].foo(...)");
assertThat(compile("$.aaa.foo(5,10,15)").toString()).isEqualTo("$['aaa'].foo(...)");
}
@Test(expected = InvalidPathException.class)
public void array_indexes_must_be_separated_by_commas() {
compile("$[0, 1, 2 4]");

6
json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

@ -58,6 +58,12 @@ public class NestedFunctionTest extends BaseFunctionTest {
verifyMathFunction(conf, "$.sum(5, 3, $.numbers.max(), 2)", 20.0);
}
@Test
public void testSimpleLiteralArgument() {
verifyMathFunction(conf, "$.sum(5)", 5.0);
verifyMathFunction(conf, "$.sum(50)", 50.0);
}
@Test
public void testStringConcat() {
verifyTextFunction(conf, "$.text.concat()", "abcdef");

Loading…
Cancel
Save