package com.jayway.jsonpath;

import org.junit.Test;

import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

/**
 * Created by IntelliJ IDEA.
 * User: kallestenflo
 * Date: 2/29/12
 * Time: 8:42 AM
 */
public class IssuesTest {
    @Test
    public void issue_7() throws Exception {

        String json = "{ \"foo\" : [\n" +
                "  { \"id\": 1 },  \n" +
                "  { \"id\": 2 },  \n" +
                "  { \"id\": 3 }\n" +
                "  ] }";


        assertNull(JsonPath.read(json, "$.foo.id"));
    }
    
    @Test
    public void issue_11() throws Exception {
        String json = "{ \"foo\" : [] }";
        List<String> result = JsonPath.read(json, "$.foo[?(@.rel= 'item')][0].uri");

        System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')][0].uri").isPathDefinite());
        System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')][0]").isPathDefinite());
        System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')]").isPathDefinite());

        assertTrue(result.isEmpty());
    }



}

@@ -1159,12 +1159,432 @@
 %0A    %7D%0A%0A
+    %0A    @Test%0A    public void issue_29_b() throws Exception %7B%0A        String json = %22%7B%5C%22list%5C%22: %5B %7B %5C%22a%5C%22:%5C%22atext%5C%22, %5C%22b%5C%22:%7B %5C%22b-a%5C%22:%5C%22batext%5C%22, %5C%22b-b%5C%22:%5C%22bbtext%5C%22 %7D %7D, %7B %5C%22a%5C%22:%5C%22atext2%5C%22, %5C%22b%5C%22:%7B %5C%22b-a%5C%22:%5C%22batext2%5C%22, %5C%22b-b%5C%22:%5C%22bbtext2%5C%22 %7D %7D %5D %7D%22;%0A        List%3CString%3E result = JsonPath.read(json, %22$.list%5B?%5D%22, Filter.filter(Criteria.where(%22b.b-a%22).eq(%22batext2%22)));%0A       %0A        assertTrue(result.size() == 1);%0A    %7D
 %0A%0A%7D%0A

add a test for one of the cases in issue 29