package com.fasterxml.jackson.databind.node;

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.databind.*;

public class JsonPointerWithNodeTest
    extends BaseMapTest
{
    public void testIt() throws Exception
    {
        final JsonNode SAMPLE_ROOT = objectMapper().readTree(SAMPLE_DOC_JSON_SPEC);
        
        // first: "empty" pointer points to context node:
        assertSame(SAMPLE_ROOT, SAMPLE_ROOT.at(JsonPointer.compile("")));

        // then simple reference
        assertTrue(SAMPLE_ROOT.at(JsonPointer.compile("/Image")).isObject());

        JsonNode n = SAMPLE_ROOT.at(JsonPointer.compile("/Image/Width"));
        assertTrue(n.isNumber());
        assertEquals(SAMPLE_SPEC_VALUE_WIDTH, n.asInt());

        // ok also with implicit compile() for pointer:
        assertEquals(SAMPLE_SPEC_VALUE_HEIGHT,
                SAMPLE_ROOT.at("/Image/Height").asInt());

        assertEquals(SAMPLE_SPEC_VALUE_TN_ID3,
                SAMPLE_ROOT.at(JsonPointer.compile("/Image/IDs/2")).asInt());

        // and then check that "missing" paths are ok too but
        assertTrue(SAMPLE_ROOT.at("/Image/Depth").isMissingNode());
        assertTrue(SAMPLE_ROOT.at("/Image/1").isMissingNode());
    }

    // To help verify [Core#133]; should be fine with "big numbers" as property keys
    public void testLongNumbers() throws Exception
    {
        
        // First, with small int key
        JsonNode root = objectMapper().readTree("{\"123\" : 456}");
        JsonNode jn2 = root.at("/123"); 
        assertEquals(456, jn2.asInt());

        // and then with above int-32:
        root = objectMapper().readTree("{\"35361706045\" : 1234}");
        jn2 = root.at("/35361706045"); 
        assertEquals(1234, jn2.asInt());
    }
}

@@ -191,16 +191,78 @@
 pTest%0A%7B%0A
+    private final ObjectMapper MAPPER = newJsonMapper();%0A    %0A
     publ
@@ -338,30 +338,22 @@
 _ROOT = 
-objectMapper()
+MAPPER
 .readTre
@@ -517,16 +517,176 @@
 e(%22%22)));
+%0A        // second: %22/%22 is NOT root, but %22root property with name of Empty String%22%0A        assertTrue(SAMPLE_ROOT.at(JsonPointer.compile(%22/%22)).isMissingNode());
 %0A%0A      
@@ -1470,17 +1470,17 @@
 verify %5B
-C
+c
 ore#133%5D
@@ -1589,25 +1589,16 @@
 n%0A    %7B%0A
-        %0A
         
@@ -1646,38 +1646,30 @@
 Node root = 
-objectMapper()
+MAPPER
 .readTree(%22%7B
@@ -1826,22 +1826,14 @@
 t = 
-objectMapper()
+MAPPER
 .rea
@@ -1953,11 +1953,244 @@
 );%0A    %7D
+%0A%0A    // %5Bdatabind#2934%5D%0A    public void testIssue2934() throws Exception%0A    %7B%0A        JsonNode tree = MAPPER.readTree(%22%7B%5C%22%5C%22 : 123%7D%22);%0A        assertEquals(123, tree.at(%22/%22).intValue());%0A        assertSame(tree, tree.at(%22%22));%0A    %7D
 %0A%7D%0A

add passing tests for #2932