mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[inplace extract function] KTIJ-21682 KTIJ-21681: test inplace mode
GitOrigin-RevId: b195ff183305395820f33bd947623878dc21f146
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dffe7781bf
commit
b2c836a40c
+68
@@ -0,0 +1,68 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.refactoring.introduce
|
||||
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
||||
import com.intellij.codeInsight.template.impl.TemplateState
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ExtractKotlinFunctionHandler
|
||||
import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.TestRoot
|
||||
import org.jetbrains.kotlin.test.TestMetadata
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@TestRoot("idea/tests")
|
||||
@TestDataPath("\$CONTENT_ROOT")
|
||||
@TestMetadata("testData/refactoring/extractFunction/inplace")
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
class InplaceExtractFunctionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
fun testStringTemplate() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testStringTemplateWithNameConflict() {
|
||||
doTest(changedName = "substring")
|
||||
}
|
||||
|
||||
fun testConflictNameNotAccepted() {
|
||||
doTest(changedName = "conflict", checkResult = false)
|
||||
TestCase.assertTrue(getActiveTemplate() != null)
|
||||
}
|
||||
|
||||
fun testConsecutiveDuplicates() {
|
||||
doTest(changedName = "renamed")
|
||||
}
|
||||
|
||||
fun testExposedAssignment() {
|
||||
doTest(changedName = "getX")
|
||||
}
|
||||
|
||||
fun doTest(changedName: String? = null, checkResult: Boolean = true) {
|
||||
TemplateManagerImpl.setTemplateTesting(testRootDisposable)
|
||||
myFixture.configureByFile("${getTestName(false)}.kt")
|
||||
ExtractKotlinFunctionHandler().invoke(myFixture.project, myFixture.editor, myFixture.file, null)
|
||||
val template = getActiveTemplate()
|
||||
require(template != null) { "Failed to start refactoring" }
|
||||
if (changedName != null) {
|
||||
renameTemplate(template, changedName)
|
||||
}
|
||||
template.gotoEnd(false)
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
if (checkResult) {
|
||||
myFixture.checkResultByFile("${getTestName(false)}.after.kt")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getActiveTemplate() = TemplateManagerImpl.getTemplateState(editor)
|
||||
|
||||
private fun renameTemplate(templateState: TemplateState, name: String) {
|
||||
WriteCommandAction.runWriteCommandAction(project) {
|
||||
val range = templateState.currentVariableRange!!
|
||||
editor.document.replaceString(range.startOffset, range.endOffset, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun sample(){
|
||||
<selection>println("42")</selection>
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun sample(){
|
||||
<selection>println("42")</selection>
|
||||
}
|
||||
|
||||
fun conflict(){
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun sample(){
|
||||
renamed<caret>()
|
||||
renamed()
|
||||
}
|
||||
|
||||
private fun renamed() {
|
||||
println("duplicate")
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun sample(){
|
||||
<selection>println("duplicate")</selection>
|
||||
println("duplicate")
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun sample(){
|
||||
val x = getX<caret>()
|
||||
|
||||
println(x)
|
||||
}
|
||||
|
||||
private fun getX(): Int {
|
||||
val x = 42
|
||||
println()
|
||||
return x
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun sample(){
|
||||
<selection>val x = 42
|
||||
println()</selection>
|
||||
|
||||
println(x)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
val example = "STRING_${extracted<caret>()}_BIG"
|
||||
|
||||
private fun extracted() = "SAMPLE"
|
||||
+1
@@ -0,0 +1 @@
|
||||
val example = "STRING_<selection>SAMPLE</selection>_BIG"
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
val example = "STRING_${substring<caret>()}_BIG"
|
||||
|
||||
private fun substring() = "SAMPLE"
|
||||
|
||||
fun extracted(): String = "42"
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
val example = "STRING_<selection>SAMPLE</selection>_BIG"
|
||||
|
||||
fun extracted(): String = "42"
|
||||
Reference in New Issue
Block a user