forked from fwcd/kotlin-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReferencesTest.kt
227 lines (180 loc) · 9.37 KB
/
ReferencesTest.kt
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
package org.javacs.kt
import org.hamcrest.Matchers.*
import org.junit.Assert.assertThat
import org.junit.Test
class ReferencesTest : SingleFileTestFixture("references", "ReferenceTo.kt") {
@Test fun `find referencs to foo`() {
val request = referenceParams(file, 2, 11)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
assertThat("Finds references within a file", referenceStrs, hasItem(containsString("ReferenceTo.kt")))
assertThat("Finds references across files", referenceStrs, hasItem(containsString("ReferenceFrom.kt")))
}
}
class ReferenceCollectionishTest : SingleFileTestFixture("references", "ReferenceCollectionish.kt") {
@Test fun `find references to iterator`() {
val request = referenceParams(file, 2, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat("Finds for-loop reference", referenceStrs, hasItem(containsString("line = 8")))
assertThat("Finds iterator() reference", referenceStrs, hasItem(containsString("line = 9")))
}
@Test fun `find references to contains`() {
val request = referenceParams(file, 3, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat("Finds reference using in", referenceStrs, hasItem(containsString("line = 10")))
assertThat("Finds contains() reference", referenceStrs, hasItem(containsString("line = 11")))
}
@Test fun `find references to rangeTo`() {
val request = referenceParams(file, 4, 21)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
}
class ReferenceComponentsTest : SingleFileTestFixture("references", "ReferenceComponents.kt") {
@Test fun `find references to component1`() {
val request = referenceParams(file, 2, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat("Finds destructuring reference", referenceStrs, hasItem(containsString("line = 6")))
assertThat("Finds component1() reference", referenceStrs, hasItem(containsString("line = 7")))
}
}
class ReferenceConstructorTest : SingleFileTestFixture("references", "ReferenceConstructor.kt") {
@Test fun `find reference to main constructor`() {
val request = referenceParams(file, 1, 24)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
assertThat("Finds reference to the main constructor", referenceStrs, hasItem(containsString("ReferenceConstructor.kt")))
}
@Test fun `find reference to secondary constructor`() {
val request = referenceParams(file, 2, 10)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
assertThat("Finds reference to a secondary constructor", referenceStrs, hasItem(containsString("ReferenceConstructor.kt")))
}
}
class ReferenceGetSetValueTest : SingleFileTestFixture("references", "ReferenceGetSetValue.kt") {
@Test fun `find references to getValue`() {
val request = referenceParams(file, 4, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat(referenceStrs, hasItem(containsString("line = 8")))
}
@Test fun `find references to setValue`() {
val request = referenceParams(file, 5, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat(referenceStrs, hasItem(containsString("line = 8")))
}
}
class ReferenceGetterSetterTest : SingleFileTestFixture("references", "ReferenceGetterSetter.kt") {
@Test fun `find references to get`() {
val request = referenceParams(file, 2, 19)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat(referenceStrs, hasItem(containsString("line = 7")))
}
@Test fun `find references to set`() {
val request = referenceParams(file, 3, 19)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat(referenceStrs, hasItem(containsString("line = 8")))
}
}
class ReferenceInvokeTest : SingleFileTestFixture("references", "ReferenceInvoke.kt") {
@Test fun `find references to invoke`() {
val request = referenceParams(file, 2, 21)
val references = languageServer.textDocumentService.references(request).get()
val referenceStrs = references?.map { it.toString() }
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
assertThat(referenceStrs, hasItem(containsString("line = 6")))
}
}
class ReferenceOperatorTest : SingleFileTestFixture("references", "ReferenceOperator.kt") {
@Test fun `find references to equals`() {
val request = referenceParams(file, 2, 30)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to compareTo`() {
val request = referenceParams(file, 3, 22)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to inc`() {
val request = referenceParams(file, 4, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to dec`() {
val request = referenceParams(file, 5, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to plus`() {
val request = referenceParams(file, 6, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to minus`() {
val request = referenceParams(file, 7, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to not`() {
val request = referenceParams(file, 8, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to equals without operator keyword`() {
val request = referenceParams(file, 12, 21)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
}
class ReferenceOperatorUsingNameTest : SingleFileTestFixture("references", "ReferenceOperatorUsingName.kt") {
@Test fun `find references to equals`() {
val request = referenceParams(file, 2, 30)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to compareTo`() {
val request = referenceParams(file, 3, 22)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
@Test fun `find references to inc`() {
val request = referenceParams(file, 4, 20)
val references = languageServer.textDocumentService.references(request).get()
val uris = references?.map { it.uri }
assertThat(uris, hasItem(containsString(file)))
}
}