summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs/PtrTest.java
blob: 69a42ab086b500c7c22e29333e794451cb769e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package org.javacs;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.net.URI;
import java.util.Collections;
import org.junit.Test;

public class PtrTest {

    static JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
    static String file = "/org/javacs/example/Ptrs.java";
    static URI uri = FindResource.uri(file);
    static CompileBatch compile = server.compiler.compileBatch(Collections.singleton(uri));

    @Test
    public void classPtr() {
        var el = compile.element(uri, 3, 15).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void fieldPtr() {
        var el = compile.element(uri, 4, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#field"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void emptyMethodPtr() {
        var el = compile.element(uri, 6, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method()"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void intMethodPtr() {
        var el = compile.element(uri, 8, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method(int)"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void stringMethodPtr() {
        var el = compile.element(uri, 10, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method(java.lang.String)"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void constructorPtr() {
        var el = compile.element(uri, 12, 13).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#<init>(int)"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void innerClassPtr() {
        var el = compile.element(uri, 14, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void innerFieldPtr() {
        var el = compile.element(uri, 15, 20).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#innerField"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void innerEmptyMethodPtr() {
        var el = compile.element(uri, 17, 25).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#innerMethod()"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }

    @Test
    public void innerConstructorPtr() {
        var el = compile.element(uri, 19, 21).get();
        var ptr = new Ptr(el);
        assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#<init>()"));

        var copy = new Ptr(ptr.toString());
        assertThat(copy, equalTo(ptr));
    }
}