Implement IdeReplCompletionTest to test completion of entities declared in already evaluated lines

This commit is contained in:
Pavel V. Talanov
2016-04-13 16:45:49 +03:00
parent f59638d60f
commit c7cefad7d5
10 changed files with 193 additions and 0 deletions
@@ -102,6 +102,7 @@ import org.jetbrains.kotlin.idea.refactoring.pullUp.AbstractPullUpTest
import org.jetbrains.kotlin.idea.refactoring.pushDown.AbstractPushDownTest
import org.jetbrains.kotlin.idea.refactoring.rename.AbstractRenameTest
import org.jetbrains.kotlin.idea.refactoring.safeDelete.AbstractSafeDeleteTest
import org.jetbrains.kotlin.idea.repl.AbstractIdeReplCompletionTest
import org.jetbrains.kotlin.idea.resolve.*
import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest
import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
@@ -813,6 +814,10 @@ fun main(args: Array<String>) {
testClass<AbstractGenerateToStringActionTest>() {
model("codeInsight/generate/toString")
}
testClass<AbstractIdeReplCompletionTest>() {
model("repl/completion")
}
}
testGroup("idea/idea-maven/test", "idea/idea-maven/testData") {
+4
View File
@@ -0,0 +1,4 @@
>> val c = 4
-- c.unary
// EXIST: unaryPlus
// EXIST: unaryMinus
+4
View File
@@ -0,0 +1,4 @@
>> class MyClass { fun f() {} fun g() {} }
-- val g: M
// EXIST: MyClass
+5
View File
@@ -0,0 +1,5 @@
>> class MyClass { fun f() {} fun g() {} }
-- MyClass().
// EXIST: f
// EXIST: g
+4
View File
@@ -0,0 +1,4 @@
>> fun String.myExt() = "a"
-- "asd".myEx
// EXIST: myExt
// NOTHING_ELSE
+8
View File
@@ -0,0 +1,8 @@
>> fun foo() {}
>> fun foo(i: Int) {}
>> fun foo(s: String = "asd") {}
>> foo(3)
-- fo
// EXIST: { itemText: "foo", tailText:"()" }
// EXIST: { itemText: "foo", tailText:"(i: Int)" }
// EXIST: { itemText: "foo", tailText:"(s: String = ...)" }
+3
View File
@@ -0,0 +1,3 @@
>> val str = "a"
-- str.capi
// EXIST: capitalize
+5
View File
@@ -0,0 +1,5 @@
>> var variable = 5
>> var variable2 = "Sdsd"
-- varia
// EXIST: variable
// EXIST: variable2
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.repl
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.console.KotlinConsoleKeeper
import org.jetbrains.kotlin.console.KotlinConsoleRunner
import org.jetbrains.kotlin.idea.completion.test.KotlinFixtureCompletionBaseTestCase
import org.jetbrains.kotlin.idea.completion.test.testCompletion
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import java.io.File
import kotlin.properties.Delegates
abstract class AbstractIdeReplCompletionTest : KotlinFixtureCompletionBaseTestCase() {
private var consoleRunner: KotlinConsoleRunner by Delegates.notNull()
override fun setUp() {
super.setUp()
consoleRunner = KotlinConsoleKeeper.getInstance(project).run(myModule)!!
}
override fun tearDown() {
consoleRunner.dispose()
super.tearDown()
}
override fun getPlatform() = JvmPlatform
override fun defaultCompletionType() = CompletionType.BASIC
override fun doTest(testPath: String) {
val file = File(testPath)
val lines = file.readLines()
lines.prefixedWith(">> ").forEach { consoleRunner.successfulLine(it) } // not actually executing anything, only simulating
val codeSample = lines.prefixedWith("-- ").joinToString("\n")
runWriteAction {
val editor = consoleRunner.consoleView.editorDocument
editor.setText(codeSample)
FileDocumentManager.getInstance().saveDocument(consoleRunner.consoleView.editorDocument)
PsiDocumentManager.getInstance(getProject()).commitAllDocuments()
}
myFixture.configureFromExistingVirtualFile(consoleRunner.consoleFile.virtualFile)
myFixture.editor.caretModel.moveToOffset(myFixture.editor.document.getLineEndOffset(0))
testCompletion(file.readText(), getPlatform(), { completionType, count -> myFixture.complete(completionType, count) })
}
private fun List<String>.prefixedWith(prefix: String) = filter { it.startsWith(prefix) }.map { it.removePrefix(prefix) }
override fun getProjectDescriptor(): LightProjectDescriptor = FullJdkProjectDescriptor
}
private object FullJdkProjectDescriptor : KotlinWithJdkAndRuntimeLightProjectDescriptor() {
override fun getSdk() = PluginTestCaseBase.fullJdk()
}
@@ -0,0 +1,79 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.repl;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/repl/completion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class IdeReplCompletionTestGenerated extends AbstractIdeReplCompletionTest {
public void testAllFilesPresentInCompletion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/repl/completion"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("builtInMember.kt")
public void testBuiltInMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/builtInMember.kt");
doTest(fileName);
}
@TestMetadata("definedClass.kt")
public void testDefinedClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/definedClass.kt");
doTest(fileName);
}
@TestMetadata("definedClassMember.kt")
public void testDefinedClassMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/definedClassMember.kt");
doTest(fileName);
}
@TestMetadata("definedExtension.kt")
public void testDefinedExtension() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/definedExtension.kt");
doTest(fileName);
}
@TestMetadata("functions.kt")
public void testFunctions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/functions.kt");
doTest(fileName);
}
@TestMetadata("stdlib.kt")
public void testStdlib() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/stdlib.kt");
doTest(fileName);
}
@TestMetadata("variables.kt")
public void testVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/repl/completion/variables.kt");
doTest(fileName);
}
}