/
RsCompletionTestFixture.kt
57 lines (48 loc) · 1.98 KB
/
RsCompletionTestFixture.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
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.lang.core.completion
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.openapi.vfs.VirtualFileFilter
import com.intellij.psi.impl.PsiManagerEx
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import org.rust.*
class RsCompletionTestFixture(
fixture: CodeInsightTestFixture,
private val defaultFileName: String = "main.rs"
) : RsCompletionTestFixtureBase<String>(fixture) {
override fun prepare(code: String) {
InlineFile(myFixture, code.trimIndent(), defaultFileName).withCaret()
}
fun doSingleCompletionByFileTree(before: String, after: String) =
doSingleCompletionByFileTree(fileTreeFromText(before), after)
fun doSingleCompletionByFileTree(fileTree: FileTree, after: String, forbidAstLoading: Boolean = true) {
val testProject = fileTree.createAndOpenFileWithCaretMarker(myFixture)
if (forbidAstLoading) {
checkAstNotLoaded { file ->
!file.path.endsWith(testProject.fileWithCaret)
}
}
executeSoloCompletion()
myFixture.checkResult(replaceCaretMarker(after.trimIndent()))
}
fun checkNoCompletionByFileTree(code: String) {
val testProject = fileTreeFromText(code).createAndOpenFileWithCaretMarker(myFixture)
checkAstNotLoaded { file ->
!file.path.endsWith(testProject.fileWithCaret)
}
noCompletionCheck()
}
fun checkContainsCompletionByFileTree(
code: String,
variants: List<String>,
render: LookupElement.() -> String = { lookupString }
) {
fileTreeFromText(code).createAndOpenFileWithCaretMarker(myFixture)
doContainsCompletion(variants, render)
}
private fun checkAstNotLoaded(fileFilter: VirtualFileFilter) {
PsiManagerEx.getInstanceEx(project).setAssertOnFileLoadingFilter(fileFilter, testRootDisposable)
}
}