forked from fwcd/kotlin-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportsTest.kt
63 lines (51 loc) · 2.69 KB
/
ImportsTest.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
package org.javacs.kt
import org.javacs.kt.imports.getImportTextEditEntry
import org.jetbrains.kotlin.name.FqName
import org.hamcrest.Matchers.*
import org.junit.Assert.assertThat
import org.junit.Test
class ImportTextEditTest : SingleFileTestFixture("imports", "Simple.kt") {
@Test
fun `should return normal import name`() {
val ktFile = languageServer.sourcePath.parsedFile(workspaceRoot.resolve(file).toUri())
val importName = FqName("org.jetbrains.kotlin.name.FqName")
val result = getImportTextEditEntry(ktFile, importName)
assertThat(result.range, equalTo(range(1, 23, 1, 23)))
assertThat(result.newText, equalTo("\n\nimport org.jetbrains.kotlin.name.FqName"))
}
@Test
fun `should wrap -class- in backticks`() {
val ktFile = languageServer.sourcePath.parsedFile(workspaceRoot.resolve(file).toUri())
val importName = FqName("com.class.myMethod")
val result = getImportTextEditEntry(ktFile, importName)
assertThat(result.range, equalTo(range(1, 23, 1, 23)))
assertThat(result.newText, equalTo("\n\nimport com.`class`.myMethod"))
}
@Test
fun `should wrap -fun- in backticks`() {
val ktFile = languageServer.sourcePath.parsedFile(workspaceRoot.resolve(file).toUri())
val importName = FqName("com.fun.myMethod")
val result = getImportTextEditEntry(ktFile, importName)
assertThat(result.range, equalTo(range(1, 23, 1, 23)))
assertThat(result.newText, equalTo("\n\nimport com.`fun`.myMethod"))
}
@Test
fun `should wrap multiple built in keywords in backticks`() {
val ktFile = languageServer.sourcePath.parsedFile(workspaceRoot.resolve(file).toUri())
val importName = FqName("fun.class.someother.package.method.var.val")
val result = getImportTextEditEntry(ktFile, importName)
assertThat(result.range, equalTo(range(1, 23, 1, 23)))
assertThat(result.newText, equalTo("\n\nimport `fun`.`class`.someother.`package`.method.`var`.`val`"))
}
@Test
fun `should NOT wrap soft keywords or modifiers in backticks`() {
// tests for a selection of soft keywords and modifiers
// according to https://kotlinlang.org/docs/keyword-reference.html
// both can be used as identifiers. (only hard keywords can not)
val ktFile = languageServer.sourcePath.parsedFile(workspaceRoot.resolve(file).toUri())
val importName = FqName("as.annotation.import.by.inner.file.field")
val result = getImportTextEditEntry(ktFile, importName)
assertThat(result.range, equalTo(range(1, 23, 1, 23)))
assertThat(result.newText, equalTo("\n\nimport `as`.annotation.import.by.inner.file.field"))
}
}