Browse Source

Renamed constants an did some clean up.

pull/158/head
Kalle Stenflo 9 years ago
parent
commit
3c1b88a547
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java
  2. 14
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  3. 16
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java
  4. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java
  5. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java
  6. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NumericPathFunctionTest.java

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

@ -255,7 +255,7 @@ public class CharacterIndex {
} }
public boolean currentIsTail() { public boolean currentIsTail() {
return isOutOfBounds(position + 1); return position >= charSequence.length()-1;
} }
public boolean hasMoreCharacters() { public boolean hasMoreCharacters() {

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

@ -26,7 +26,7 @@ public class PathCompiler {
private static final char WILDCARD = '*'; private static final char WILDCARD = '*';
private static final char PERIOD = '.'; private static final char PERIOD = '.';
private static final char SPACE = ' '; private static final char SPACE = ' ';
private static final char QUESTIONMARK = '?'; private static final char BEGIN_FILTER = '?';
private static final char COMMA = ','; private static final char COMMA = ',';
private static final char SPLIT = ':'; private static final char SPLIT = ':';
private static final char MINUS = '-'; private static final char MINUS = '-';
@ -50,11 +50,11 @@ public class PathCompiler {
try { try {
path = path.trim(); path = path.trim();
if(!path.startsWith("$") && !path.startsWith("@")){ if(!(path.charAt(0) == DOC_CONTEXT) && !(path.charAt(0) == EVAL_CONTEXT)){
path = "$." + path; path = "$." + path;
} }
if(path.endsWith("..")){ if(path.endsWith(".")){
fail("Path must not end wid a scan operation '..'"); fail("Path must not end with a '.' or '..'");
} }
LinkedList filterStack = new LinkedList<Predicate>(asList(filters)); LinkedList filterStack = new LinkedList<Predicate>(asList(filters));
Path p = new PathCompiler(path.trim(), filterStack).compile(); Path p = new PathCompiler(path.trim(), filterStack).compile();
@ -186,7 +186,7 @@ public class PathCompiler {
if (!path.currentCharIs(OPEN_SQUARE_BRACKET)) { if (!path.currentCharIs(OPEN_SQUARE_BRACKET)) {
return false; return false;
} }
int questionmarkIndex = path.indexOfNextSignificantChar(QUESTIONMARK); int questionmarkIndex = path.indexOfNextSignificantChar(BEGIN_FILTER);
if (questionmarkIndex == -1) { if (questionmarkIndex == -1) {
return false; return false;
} }
@ -230,12 +230,12 @@ public class PathCompiler {
// [?(...)] // [?(...)]
// //
private boolean readFilterToken(PathTokenAppender appender) { private boolean readFilterToken(PathTokenAppender appender) {
if (!path.currentCharIs(OPEN_SQUARE_BRACKET) && !path.nextSignificantCharIs(QUESTIONMARK)) { if (!path.currentCharIs(OPEN_SQUARE_BRACKET) && !path.nextSignificantCharIs(BEGIN_FILTER)) {
return false; return false;
} }
int openStatementBracketIndex = path.position(); int openStatementBracketIndex = path.position();
int questionMarkIndex = path.indexOfNextSignificantChar(QUESTIONMARK); int questionMarkIndex = path.indexOfNextSignificantChar(BEGIN_FILTER);
if (questionMarkIndex == -1) { if (questionMarkIndex == -1) {
return false; return false;
} }

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

@ -36,14 +36,22 @@ public class PathCompilerTest {
@Test(expected = InvalidPathException.class) @Test(expected = InvalidPathException.class)
public void a_path_may_not_end_with_period() { public void a_path_may_not_end_with_period() {
assertThat(compile("$.").toString()); compile("$.");
assertThat(compile("$.prop.").toString()); }
@Test(expected = InvalidPathException.class)
public void a_path_may_not_end_with_period_2() {
compile("$.prop.");
} }
@Test(expected = InvalidPathException.class) @Test(expected = InvalidPathException.class)
public void a_path_may_not_end_with_scan() { public void a_path_may_not_end_with_scan() {
assertThat(compile("$..").toString()); compile("$..");
assertThat(compile("$.prop..").toString()); }
@Test(expected = InvalidPathException.class)
public void a_path_may_not_end_with_scan_2() {
compile("$.prop..");
} }
@Test @Test

2
json-path/src/test/java/com/jayway/jsonpath/functions/BaseFunctionTest.java → json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java

@ -1,4 +1,4 @@
package com.jayway.jsonpath.functions; package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;

2
json-path/src/test/java/com/jayway/jsonpath/functions/JSONEntityPathFunctionTest.java → json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java

@ -1,4 +1,4 @@
package com.jayway.jsonpath.functions; package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations; import com.jayway.jsonpath.Configurations;

2
json-path/src/test/java/com/jayway/jsonpath/functions/NumericPathFunctionTest.java → json-path/src/test/java/com/jayway/jsonpath/internal/function/NumericPathFunctionTest.java

@ -1,4 +1,4 @@
package com.jayway.jsonpath.functions; package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations; import com.jayway.jsonpath.Configurations;
Loading…
Cancel
Save