From 5f8dc8ae0b82e55325fa90b116d93ba48490a9b9 Mon Sep 17 00:00:00 2001 From: Alexey Makeyev Date: Mon, 19 Oct 2015 15:45:45 +0300 Subject: [PATCH] path compilation issues tests moved to proper location --- .../com/jayway/jsonpath/PathCompilerTest.java | 103 ++++++++++++++++++ .../com/jayway/jsonpath/PredicateTest.java | 103 ------------------ 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java b/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java index 5a1d05b6..32a14671 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java +++ b/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.Test; +import java.util.List; + import static com.jayway.jsonpath.internal.PathCompiler.compile; import static org.assertj.core.api.Assertions.assertThat; @@ -128,4 +130,105 @@ public class PathCompilerTest { 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 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 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 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 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 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 result = JsonPath.read(json, "$.logs[?(@.message == '] it')].message"); + + assertThat(result).containsExactly("] it"); + } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java index 956ec2a6..62939070 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java @@ -1,6 +1,5 @@ package com.jayway.jsonpath; -import org.junit.Ignore; import org.junit.Test; 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"); } - - @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 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 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 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 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 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 result = JsonPath.read(json, "$.logs[?(@.message == '] it')].message"); - - assertThat(result).containsExactly("] it"); - } }