Minor: fix caret behaviour in arg template test

#KT-29398 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-27 17:49:42 +03:00
committed by Nikolay Krasko
parent 29d32b213e
commit 0acecb4936
3 changed files with 14 additions and 4 deletions
+1
View File
@@ -1,3 +1,4 @@
// TEMPLATE: \tfunctionCall\t
fun foo(s: String) { fun foo(s: String) {
s.arg<caret> s.arg<caret>
} }
+2 -1
View File
@@ -1,3 +1,4 @@
// TEMPLATE: \tfunctionCall\t
fun foo(s: String) { fun foo(s: String) {
(s<caret>) functionCall(s<caret>)
} }
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.codeInsight.postfix package org.jetbrains.kotlin.idea.codeInsight.postfix
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.InTextDirectivesUtils
@@ -24,16 +25,23 @@ abstract class AbstractPostfixTemplateProviderTest : KotlinLightCodeInsightFixtu
} }
protected fun doTest(fileName: String) { protected fun doTest(fileName: String) {
val fileText = File(fileName).readText()
myFixture.configureByFile(fileName) myFixture.configureByFile(fileName)
myFixture.type("\t") val template = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// TEMPLATE:")
if (template != null) {
TemplateManagerImpl.setTemplateTesting(project, testRootDisposable)
myFixture.type(template.replace("\\t", "\t"))
} else {
myFixture.type('\t')
}
val previouslySuggestedExpressions = KtPostfixTemplateProvider.previouslySuggestedExpressions val previouslySuggestedExpressions = KtPostfixTemplateProvider.previouslySuggestedExpressions
if (previouslySuggestedExpressions.size > 1 && !InTextDirectivesUtils.isDirectiveDefined(File(fileName).readText(), "ALLOW_MULTIPLE_EXPRESSIONS")) { if (previouslySuggestedExpressions.size > 1 && !InTextDirectivesUtils.isDirectiveDefined(fileText, "ALLOW_MULTIPLE_EXPRESSIONS")) {
fail("Only one expression should be suggested, but $previouslySuggestedExpressions were found") fail("Only one expression should be suggested, but $previouslySuggestedExpressions were found")
} }
myFixture.checkResultByFile(fileName + ".after") myFixture.checkResultByFile("$fileName.after")
} }
override fun tearDown() { override fun tearDown() {