Browse Source

path compilation issues tests moved to proper location

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
5f8dc8ae0b
  1. 103
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java
  2. 103
      json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

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

@ -3,6 +3,8 @@ package com.jayway.jsonpath;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.List;
import static com.jayway.jsonpath.internal.PathCompiler.compile; import static com.jayway.jsonpath.internal.PathCompiler.compile;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -128,4 +130,105 @@ public class PathCompilerTest {
assertThat(compile("$..['prop']..[*]").toString()).isEqualTo("$..['prop']..[*]"); assertThat(compile("$..['prop']..[*]").toString()).isEqualTo("$..['prop']..[*]");
} }
@Test
public void issue_predicate_can_have_escaped_backslash_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\\\\\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
// message: it\ -> (after json escaping) -> "it\\" -> (after java escaping) -> "\"it\\\\\""
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");
assertThat(result).containsExactly("it\\");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_bracket_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"(it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /\\(it/)].message");
assertThat(result).containsExactly("(it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /&&|it/)].message");
assertThat(result).containsExactly("it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"&& it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '&& it')].message");
assertThat(result).containsExactly("&& it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_brackets_must_change_priorities() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message && (@.id == 1 || @.id == 2))].id");
assertThat(result).isEmpty();
result = JsonPath.read(json, "$.logs[?((@.id == 2 || @.id == 1) && @.message)].id");
assertThat(result).isEmpty();
}
@Test
public void issue_predicate_can_have_square_bracket_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"] it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '] it')].message");
assertThat(result).containsExactly("] it");
}
} }

103
json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

@ -1,6 +1,5 @@
package com.jayway.jsonpath; package com.jayway.jsonpath;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@ -24,106 +23,4 @@ public class PredicateTest extends BaseTest {
assertThat(reader.read("$.store.book[?].isbn", List.class, booksWithISBN)).containsOnly("0-395-19395-8", "0-553-21311-3"); assertThat(reader.read("$.store.book[?].isbn", List.class, booksWithISBN)).containsOnly("0-395-19395-8", "0-553-21311-3");
} }
@Test
public void issue_predicate_can_have_escaped_backslash_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\\\\\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
// message: it\ -> (after json escaping) -> "it\\" -> (after java escaping) -> "\"it\\\\\""
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");
assertThat(result).containsExactly("it\\");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_bracket_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"(it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /\\(it/)].message");
assertThat(result).containsExactly("(it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /&&|it/)].message");
assertThat(result).containsExactly("it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"&& it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '&& it')].message");
assertThat(result).containsExactly("&& it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_brackets_must_change_priorities() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message && (@.id == 1 || @.id == 2))].id");
assertThat(result).isEmpty();
result = JsonPath.read(json, "$.logs[?((@.id == 2 || @.id == 1) && @.message)].id");
assertThat(result).isEmpty();
}
@Test
public void issue_predicate_can_have_square_bracket_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"] it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '] it')].message");
assertThat(result).containsExactly("] it");
}
} }

Loading…
Cancel
Save