forked from fwcd/kotlin-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompiledFileTest.kt
49 lines (41 loc) · 1.6 KB
/
CompiledFileTest.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
package org.javacs.kt
import org.hamcrest.Matchers.equalTo
import org.javacs.kt.compiler.Compiler
import org.javacs.kt.database.DatabaseService
import org.junit.AfterClass
import org.junit.Assert.assertThat
import org.junit.Test
import org.junit.BeforeClass
import java.io.File
import java.nio.file.Files
class CompiledFileTest {
val compiledFile = compileFile()
companion object {
lateinit var outputDirectory: File
@JvmStatic @BeforeClass fun setup() {
LOG.connectStdioBackend()
outputDirectory = Files.createTempDirectory("klsBuildOutput").toFile()
}
@JvmStatic @AfterClass fun tearDown() {
outputDirectory.delete()
}
}
fun compileFile(): CompiledFile = Compiler(
javaSourcePath = setOf(),
classPath = setOf(),
scriptsConfig = ScriptsConfiguration(),
outputDirectory = outputDirectory
).use { compiler ->
val file = testResourcesRoot().resolve("compiledFile/CompiledFileExample.kt")
val content = Files.readAllLines(file).joinToString("\n")
val parse = compiler.createKtFile(content, file)
val classPath = CompilerClassPath(CompilerConfiguration(), ScriptsConfiguration(), DatabaseService())
val sourcePath = listOf(parse)
val (context, container) = compiler.compileKtFiles(sourcePath, sourcePath)
CompiledFile(content, parse, context, container, sourcePath, classPath)
}
@Test fun `typeAtPoint should return type for x`() {
val type = compiledFile.typeAtPoint(87)!!
assertThat(type.toString(), equalTo("Int"))
}
}