Test for smart indent in parameters (KT-17648)

Fixed in IDEA-173208

#KT-17648 Fixed
This commit is contained in:
Nikolay Krasko
2017-09-05 12:49:22 +03:00
parent 80ffc5cd41
commit 385ff3f4eb
@@ -16,9 +16,12 @@
package org.jetbrains.kotlin.idea.editor package org.jetbrains.kotlin.idea.editor
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.testFramework.EditorTestUtil import com.intellij.testFramework.EditorTestUtil
import com.intellij.testFramework.LightCodeInsightTestCase import com.intellij.testFramework.LightCodeInsightTestCase
import com.intellij.testFramework.LightPlatformCodeInsightTestCase import com.intellij.testFramework.LightPlatformCodeInsightTestCase
import com.intellij.testFramework.LightPlatformTestCase
import org.jetbrains.kotlin.idea.KotlinFileType
class TypedHandlerTest : LightCodeInsightTestCase() { class TypedHandlerTest : LightCodeInsightTestCase() {
val dollar = '$' val dollar = '$'
@@ -633,6 +636,41 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
) )
} }
fun testSmartEnterWithTabsOnConstructorParameters() {
doCharTypeTest(
'\n',
"""
|class A(
| a: Int,<caret>
|)
""",
"""
|class A(
| a: Int,
| <caret>
|)
""",
enableSmartEnterWithTabs()
)
}
fun testSmartEnterWithTabsInMethodParameters() {
doCharTypeTest(
'\n',
"""
|fun method(
| arg1: String,<caret>
|) {}
""",
"""
|fun method(
| arg1: String,
| <caret>
|) {}
""",
enableSmartEnterWithTabs()
)
}
fun testMoveThroughGT() { fun testMoveThroughGT() {
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List<Set<Int<caret>>>") LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List<Set<Int<caret>>>")
@@ -645,10 +683,29 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
doCharTypeTest('\'', "val c = <caret>", "val c = ''") doCharTypeTest('\'', "val c = <caret>", "val c = ''")
} }
private fun doCharTypeTest(ch: Char, beforeText: String, afterText: String) { private fun enableSmartEnterWithTabs(): () -> Unit = {
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText.trimMargin()) val project = LightPlatformTestCase.getProject()
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch) val indentOptions = CodeStyleSettingsManager.getInstance(project).currentSettings.getIndentOptions(KotlinFileType.INSTANCE)
checkResultByText(afterText.trimMargin()) indentOptions.USE_TAB_CHARACTER = true
indentOptions.SMART_TABS = true
}
private fun doCharTypeTest(ch: Char, beforeText: String, afterText: String, settingsModifier: (() -> Unit)? = null) {
try {
if (settingsModifier != null) {
settingsModifier()
}
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText.trimMargin())
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch)
checkResultByText(afterText.trimMargin())
}
finally {
if (settingsModifier != null) {
val project = LightPlatformTestCase.getProject()
CodeStyleSettingsManager.getSettings(project).clearCodeStyleSettings()
}
}
} }
private fun doLtGtTestNoAutoClose(initText: String) { private fun doLtGtTestNoAutoClose(initText: String) {