summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs/CompletionsScopesTest.java
blob: 50b47595457de743e11511479b95fb28bc5554fa (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package org.javacs;

import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import org.junit.Ignore;
import org.junit.Test;

public class CompletionsScopesTest extends CompletionsBase {
    @Test
    public void staticSub() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 15, 14);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, hasItems("testStatic"));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, not(hasItems("testInner")));
        assertThat(suggestions, hasItems("test"));
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("testOuterMethods")));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        assertThat(suggestions, hasItems("testInheritedMethods"));
        // this/super in enclosing scopes
        assertThat(suggestions, hasItems("this"));
    }

    @Test
    public void staticSubThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // StaticSub.this, StaticSub.super
        assertThat(insertText(file, 37, 23), hasItems("this"));
        // AutocompleteScopes.this, AutocompleteScopes.super
        // TODO this is not accessible
        // assertThat(insertText(file, 39, 32), not(hasItems("this")));
        // Super.this, Super.super
        // TODO this is not accessible
        // assertThat(insertText(file, 41, 19), not(hasItems("this")));
    }

    @Test
    public void staticSubInner() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 45, 22);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, hasItems("testStatic"));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, hasItems("testInner"));
        assertThat(suggestions, hasItems("test"));
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("testOuterMethods")));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        assertThat(suggestions, hasItems("testInheritedMethods"));
        // this/super in enclosing scopes
        assertThat(suggestions, hasItems("this"));
    }

    @Test
    public void staticSubInnerThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // StaticSub.this, StaticSub.super
        assertThat(insertText(file, 67, 31), hasItems("this"));
        // AutocompleteScopes.this, AutocompleteScopes.super
        // TODO this is not accessible
        // assertThat(insertText(file, 69, 40), not(hasItems("this")));
        // Super.this, Super.super
        // TODO this is not accessible
        // assertThat(insertText(file, 71, 27), not(hasItems("this")));
    }

    @Test
    public void staticSubStaticMethod() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 78, 14);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, hasItems("testStatic"));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, not(hasItems("testInner")));
        assertThat(suggestions, not(hasItems("test")));
        assertThat(suggestions, not(hasItems("testOuterMethods")));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        assertThat(suggestions, not(hasItems("testInheritedMethods")));
        // this/super in enclosing scopes
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("this")));
    }

    // TODO this is not accessible
    @Ignore
    @Test
    public void staticSubStaticMethodThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // StaticSub.this, StaticSub.super
        assertThat(insertText(file, 100, 23), not(hasItems("this")));
        // AutocompleteScopes.this, AutocompleteScopes.super
        assertThat(insertText(file, 102, 32), not(hasItems("this")));
        // Super.this, Super.super
        assertThat(insertText(file, 104, 19), not(hasItems("this")));
    }

    @Test
    public void staticSubStaticMethodInner() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 108, 22);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, hasItems("testStatic"));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, hasItems("testInner"));
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("test")));
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("testOuterMethods")));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        // TODO this is not accessible
        // assertThat(suggestions, not(hasItems("testInheritedMethods")));
        // this/super in enclosing scopes
        assertThat(suggestions, hasItems("this"));
    }

    // TODO this is not accessible
    @Ignore
    @Test
    public void staticSubStaticMethodInnerThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // StaticSub.this, StaticSub.super
        assertThat(insertText(file, 130, 31), not(hasItems("this")));
        // AutocompleteScopes.this, AutocompleteScopes.super
        assertThat(insertText(file, 132, 40), not(hasItems("this")));
        // Super.this, Super.super
        assertThat(insertText(file, 134, 27), not(hasItems("this")));
    }

    @Test
    public void sub() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 143, 14);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, not(hasItems("testStatic")));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, not(hasItems("testInner")));
        assertThat(suggestions, hasItems("test"));
        assertThat(suggestions, hasItems("testOuterMethods"));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        assertThat(suggestions, hasItems("testInheritedMethods"));
        // this/super in enclosing scopes
        assertThat(suggestions, hasItems("this"));
    }

    @Test
    public void subThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // sub.this, sub.super
        assertThat(insertText(file, 158, 17), hasItems("this"));
        // AutocompleteScopes.this, AutocompleteScopes.super
        assertThat(insertText(file, 160, 32), hasItems("this"));
        // Super.this, Super.super
        // TODO this is not accessible
        // assertThat(insertText(file, 162, 19), not(hasItems("this")));
    }

    @Test
    public void subInner() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // Static method
        var suggestions = insertText(file, 166, 22);

        // Locals
        assertThat(suggestions, hasItems("testLocalVariables", "testArguments"));
        // Static methods in enclosing scopes
        assertThat(suggestions, not(hasItems("testStatic")));
        assertThat(suggestions, hasItems("testOuterStaticMethod"));
        // Virtual methods in enclosing scopes
        assertThat(suggestions, hasItems("testInner"));
        assertThat(suggestions, hasItems("test"));
        assertThat(suggestions, hasItems("testOuterMethods"));
        // Inherited static methods
        assertThat(suggestions, hasItems("testInheritedStaticMethod"));
        // Inherited virtual methods
        assertThat(suggestions, hasItems("testInheritedMethods"));
        // this/super in enclosing scopes
        assertThat(suggestions, hasItems("this"));
    }

    @Test
    public void subInnerThisSuper() throws IOException {
        var file = "/org/javacs/example/AutocompleteScopes.java";

        // sub.this, sub.super
        assertThat(insertText(file, 181, 25), hasItems("this"));
        // AutocompleteScopes.this, AutocompleteScopes.super
        assertThat(insertText(file, 183, 40), hasItems("this"));
        // Super.this, Super.super
        // TODO this is not accessible
        // assertThat(insertText(file, 185, 27), not(hasItems("this")));
    }
}