From fe9c5cac454f8799d44bc4073fb42463ea58d6ab Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 7 Nov 2019 16:46:50 +0300 Subject: [PATCH] Fix TypedHandlerTest in 193 Unify TypedHandlerTest.kt with the KotlinLightCodeInsightTestCase --- .../kotlin/idea/test/compatTestWrappers.kt | 30 + .../idea/test/compatTestWrappers.kt.193 | 28 + .../kotlin/idea/editor/TypedHandlerTest.kt | 47 +- .../idea/editor/TypedHandlerTest.kt.193 | 935 ------------------ 4 files changed, 80 insertions(+), 960 deletions(-) create mode 100644 idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt create mode 100644 idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt.193 diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt new file mode 100644 index 00000000000..207efe333c8 --- /dev/null +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("unused", "IncompatibleAPI", "PropertyName") + +package org.jetbrains.kotlin.idea.test + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.LightPlatformCodeInsightTestCase +import com.intellij.testFramework.LightPlatformTestCase + +// BUNCH: 192 +@Suppress("DEPRECATION") +@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") +abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() + protected inline val editor_: Editor get() = LightPlatformCodeInsightTestCase.getEditor() +} + +// BUNCH: 192 +abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() +} \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 new file mode 100644 index 00000000000..7e28bfe2707 --- /dev/null +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("unused", "IncompatibleAPI", "PropertyName") + +package org.jetbrains.kotlin.idea.test + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.testFramework.LightIdeaTestCase + +// BUNCH: 192 +@Suppress("DEPRECATION") +@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") +abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { + protected inline val project_: Project get() = project + protected inline val module_: Module get() = module + protected inline val editor_: Editor get() = editor +} + +// BUNCH: 192 +abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { + protected inline val project_: Project get() = project + protected inline val module_: Module get() = module +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt index e44f52aed10..60e4f0a3913 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt @@ -3,21 +3,22 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +@file:Suppress("DEPRECATION") + package org.jetbrains.kotlin.idea.editor import com.intellij.application.options.CodeStyle import com.intellij.testFramework.EditorTestUtil -import com.intellij.testFramework.LightCodeInsightTestCase -import com.intellij.testFramework.LightPlatformCodeInsightTestCase -import com.intellij.testFramework.LightPlatformTestCase import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner import org.junit.runner.RunWith +@Suppress("DEPRECATION") @RunWith(JUnit3WithIdeaConfigurationRunner::class) -class TypedHandlerTest : LightCodeInsightTestCase() { +class TypedHandlerTest : KotlinLightCodeInsightTestCase() { private val dollar = '$' fun testTypeStringTemplateStart() = doTypeTest( @@ -907,7 +908,7 @@ class TypedHandlerTest : LightCodeInsightTestCase() { |fun test() = | """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE + enableKotlinOfficialCodeStyle ) } @@ -925,7 +926,7 @@ class TypedHandlerTest : LightCodeInsightTestCase() { | |} """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE + enableKotlinOfficialCodeStyle ) } @@ -939,14 +940,14 @@ class TypedHandlerTest : LightCodeInsightTestCase() { |val test = | """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE + enableKotlinOfficialCodeStyle ) } fun testMoveThroughGT() { - LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List>>") - EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>') - EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>') + configureFromFileText("a.kt", "val a: List>>") + EditorTestUtil.performTypingAction(editor_, '>') + EditorTestUtil.performTypingAction(editor_, '>') checkResultByText("val a: List>") } @@ -955,8 +956,7 @@ class TypedHandlerTest : LightCodeInsightTestCase() { } private fun enableSmartEnterWithTabs(): () -> Unit = { - val project = LightPlatformTestCase.getProject() - val indentOptions = CodeStyle.getSettings(project).getIndentOptions(KotlinFileType.INSTANCE) + val indentOptions = CodeStyle.getSettings(project_).getIndentOptions(KotlinFileType.INSTANCE) indentOptions.USE_TAB_CHARACTER = true indentOptions.SMART_TABS = true } @@ -971,15 +971,14 @@ class TypedHandlerTest : LightCodeInsightTestCase() { settingsModifier() } - LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText.trimMargin()) + configureFromFileText("a.kt", beforeText.trimMargin()) for (ch in text) { - EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch) + EditorTestUtil.performTypingAction(editor_, ch) } checkResultByText(afterText.trimMargin()) } finally { if (settingsModifier != null) { - val project = LightPlatformTestCase.getProject() - CodeStyle.getSettings(project).clearCodeStyleSettings() + CodeStyle.getSettings(project_).clearCodeStyleSettings() } } } @@ -1001,12 +1000,12 @@ class TypedHandlerTest : LightCodeInsightTestCase() { } private fun doLtGtTest(initText: String, shouldCloseBeInsert: Boolean) { - LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", initText) + configureFromFileText("a.kt", initText) - EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '<') + EditorTestUtil.performTypingAction(editor_, '<') checkResultByText(if (shouldCloseBeInsert) initText.replace("", "<>") else initText.replace("", "<")) - EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), EditorTestUtil.BACKSPACE_FAKE_CHAR) + EditorTestUtil.performTypingAction(editor_, EditorTestUtil.BACKSPACE_FAKE_CHAR) checkResultByText(initText) } @@ -1014,10 +1013,8 @@ class TypedHandlerTest : LightCodeInsightTestCase() { doLtGtTest(initText, true) } - companion object { - private val ENABLE_KOTLIN_OFFICIAL_CODE_STYLE: () -> Unit = { - val settings = ktCodeStyleSettings(LightPlatformTestCase.getProject())?.all ?: error("No Settings") - KotlinStyleGuideCodeStyle.apply(settings) - } + private val enableKotlinOfficialCodeStyle: () -> Unit = { + val settings = ktCodeStyleSettings(project_)?.all ?: error("No Settings") + KotlinStyleGuideCodeStyle.apply(settings) } -} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt.193 deleted file mode 100644 index 53e282be48c..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt.193 +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.idea.editor - -import com.intellij.application.options.CodeStyle -import com.intellij.openapi.project.Project -import com.intellij.testFramework.EditorTestUtil -import com.intellij.testFramework.LightCodeInsightTestCase -import com.intellij.testFramework.LightPlatformCodeInsightTestCase -import com.intellij.testFramework.LightPlatformTestCase -import org.jetbrains.kotlin.idea.KotlinFileType -import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle -import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner -import org.junit.runner.RunWith - -@RunWith(JUnit3WithIdeaConfigurationRunner::class) -class TypedHandlerTest : LightCodeInsightTestCase() { - private val dollar = '$' - - fun testTypeStringTemplateStart() = doTypeTest( - '{', - """val x = "$" """, - """val x = "$dollar{}" """ - ) - - fun testAutoIndentRightOpenBrace() = doTypeTest( - '{', - - "fun test() {\n" + - "\n" + - "}", - - "fun test() {\n" + - " {}\n" + - "}" - ) - - fun testAutoIndentLeftOpenBrace() = doTypeTest( - '{', - - "fun test() {\n" + - " \n" + - "}", - - "fun test() {\n" + - " {}\n" + - "}" - ) - - fun testTypeStringTemplateStartWithCloseBraceAfter() = doTypeTest( - '{', - """fun foo() { "$" }""", - """fun foo() { "$dollar{}" }""" - ) - - fun testTypeStringTemplateStartBeforeStringWithExistingDollar() = doTypeTest( - '{', - """fun foo() { "$something" }""", - """fun foo() { "$dollar{something" }""" - ) - - fun testTypeStringTemplateStartBeforeStringWithNoDollar() = doTypeTest( - "$dollar{", - """fun foo() { "something" }""", - """fun foo() { "$dollar{}something" }""" - ) - - fun testTypeStringTemplateWithUnmatchedBrace() = doTypeTest( - "$dollar{", - """val a = "bar}foo"""", - """val a = "$dollar{bar}foo"""" - ) - - fun testTypeStringTemplateWithUnmatchedBraceComplex() = doTypeTest( - "$dollar{", - """val a = "bar + more}foo"""", - """val a = "$dollar{}bar + more}foo"""" - ) - - fun testTypeStringTemplateStartInStringWithBraceLiterals() = doTypeTest( - "$dollar{", - """val test = "{ code other }"""", - """val test = "{ code $dollar{}other }"""" - ) - - fun testTypeStringTemplateStartInEmptyString() = doTypeTest( - '{', - """fun foo() { "$" }""", - """fun foo() { "$dollar{}" }""" - ) - - fun testKT3575() = doTypeTest( - '{', - """val x = "$]" """, - """val x = "$dollar{}]" """ - ) - - fun testAutoCloseRawStringInEnd() = doTypeTest( - '"', - """val x = """"", - """val x = ""${'"'}""${'"'}""" - ) - - fun testNoAutoCloseRawStringInEnd() = doTypeTest( - '"', - """val x = ""${'"'}""", - """val x = ""${'"'}"""" - ) - - fun testAutoCloseRawStringInMiddle() = doTypeTest( - '"', - """ - val x = "" - val y = 12 - """.trimIndent(), - """ - val x = ""${'"'}""${'"'} - val y = 12 - """.trimIndent() - ) - - fun testNoAutoCloseBetweenMultiQuotes() = doTypeTest( - '"', - """val x = ""${'"'}${'"'}""/**/""", - """val x = ""${'"'}${'"'}""/**/""" - ) - - fun testNoAutoCloseBetweenMultiQuotes1() = doTypeTest( - '"', - """val x = ""${'"'}""${'"'}/**/""", - """val x = ""${'"'}""${'"'}/**/""" - ) - - fun testNoAutoCloseAfterEscape() = doTypeTest( - '"', - """val x = "\""""", - """val x = "\""${'"'}"""" - ) - - fun testAutoCloseBraceInFunctionDeclaration() = doTypeTest( - '{', - "fun foo() ", - "fun foo() {}" - ) - - fun testAutoCloseBraceInLocalFunctionDeclaration() = doTypeTest( - '{', - - "fun foo() {\n" + - " fun bar() \n" + - "}", - - "fun foo() {\n" + - " fun bar() {}\n" + - "}" - ) - - fun testAutoCloseBraceInAssignment() = doTypeTest( - '{', - "fun foo() {\n" + - " val a = \n" + - "}", - - "fun foo() {\n" + - " val a = {}\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if() foo()\n" + - "}", - - "fun foo() {\n" + - " if() {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedElseSurroundOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if(true) {} else foo()\n" + - "}", - - "fun foo() {\n" + - " if(true) {} else {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedTryOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " try foo()\n" + - "}", - - "fun foo() {\n" + - " try {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedCatchOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " try {} catch (e: Exception) foo()\n" + - "}", - - "fun foo() {\n" + - " try {} catch (e: Exception) {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedFinallyOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " try {} catch (e: Exception) finally foo()\n" + - "}", - - "fun foo() {\n" + - " try {} catch (e: Exception) finally {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnSameLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " while() foo()\n" + - "}", - - "fun foo() {\n" + - " while() {foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedWhileSurroundOnNewLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " while()\n" + - "\n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " while()\n" + - " {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnOtherLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if(true) \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true) {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedElseSurroundOnOtherLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if(true) {} else \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true) {} else {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedTryOnOtherLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " try \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " try {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedIfSurroundOnNewLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if(true)\n" + - " \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true)\n" + - " {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedElseSurroundOnNewLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " if(true) {} else\n" + - " \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " if(true) {} else\n" + - " {\n" + - " foo()\n" + - "}" - ) - - fun testDoNotAutoCloseBraceInUnfinishedTryOnNewLine() = doTypeTest( - '{', - - "fun foo() {\n" + - " try\n" + - " \n" + - " foo()\n" + - "}", - - "fun foo() {\n" + - " try\n" + - " {\n" + - " foo()\n" + - "}" - ) - - fun testAutoCloseBraceInsideFor() = doTypeTest( - '{', - - "fun foo() {\n" + - " for (elem in some.filter ) {\n" + - " }\n" + - "}", - - "fun foo() {\n" + - " for (elem in some.filter {}) {\n" + - " }\n" + - "}" - ) - - fun testAutoCloseBraceInsideForAfterCloseParen() = doTypeTest( - '{', - - "fun foo() {\n" + - " for (elem in some.foo(true) ) {\n" + - " }\n" + - "}", - - "fun foo() {\n" + - " for (elem in some.foo(true) {}) {\n" + - " }\n" + - "}" - ) - - fun testAutoCloseBraceBeforeIf() = doTypeTest( - '{', - - "fun foo() {\n" + - " if (true) {}\n" + - "}", - - "fun foo() {\n" + - " {if (true) {}\n" + - "}" - ) - - fun testAutoCloseBraceInIfCondition() = doTypeTest( - '{', - - "fun foo() {\n" + - " if (some.hello (12) )\n" + - "}", - - "fun foo() {\n" + - " if (some.hello (12) {})\n" + - "}" - ) - - fun testInsertSpaceAfterRightBraceOfNestedLambda() = doTypeTest( - '{', - "val t = Array(100) { Array(200) }", - "val t = Array(100) { Array(200) {} }" - ) - - fun testAutoInsertParenInStringLiteral() = doTypeTest( - '(', - """fun f() { println("$dollar{f}") }""", - """fun f() { println("$dollar{f()}") }""" - ) - - fun testAutoInsertParenInCode() = doTypeTest( - '(', - """fun f() { val a = f }""", - """fun f() { val a = f() }""" - ) - - fun testSplitStringByEnter() = doTypeTest( - '\n', - """val s = "foobar"""", - "val s = \"foo\" +\n" + - " \"bar\"" - ) - - fun testSplitStringByEnterEmpty() = doTypeTest( - '\n', - """val s = """"", - "val s = \"\" +\n" + - " \"\"" - ) - - fun testSplitStringByEnterBeforeEscapeSequence() = doTypeTest( - '\n', - """val s = "foo\nbar"""", - "val s = \"foo\" +\n" + - " \"\\nbar\"" - ) - - fun testSplitStringByEnterBeforeSubstitution() = doTypeTest( - '\n', - """val s = "foo${dollar}bar"""", - "val s = \"foo\" +\n" + - " \"${dollar}bar\"" - ) - - fun testSplitStringByEnterAddParentheses() = doTypeTest( - '\n', - """val l = "foobar".length()""", - "val l = (\"foo\" +\n" + - " \"bar\").length()" - ) - - fun testSplitStringByEnterExistingParentheses() = doTypeTest( - '\n', - """val l = ("asdf" + "foobar").length()""", - "val l = (\"asdf\" + \"foo\" +\n" + - " \"bar\").length()" - ) - - fun testTypeLtInFunDeclaration() { - doLtGtTest("fun ") - } - - fun testTypeLtInOngoingConstructorCall() { - doLtGtTest("fun test() { Collection }") - } - - fun testTypeLtInClassDeclaration() { - doLtGtTest("class Some {}") - } - - fun testTypeLtInPropertyType() { - doLtGtTest("val a: List ") - } - - fun testTypeLtInExtensionFunctionReceiver() { - doLtGtTest("fun Collection ") - } - - fun testTypeLtInFunParam() { - doLtGtTest("fun some(a : HashSet)") - } - - fun testTypeLtInFun() { - doLtGtTestNoAutoClose("fun some() { < }") - } - - fun testTypeLtInLess() { - doLtGtTestNoAutoClose("fun some() { val a = 12; a < }") - } - - fun testColonOfSuperTypeList() { - doTypeTest( - ':', - """ - |open class A - |class B - | - """, - """ - |open class A - |class B - | : - """) - } - - fun testColonOfSuperTypeListInObject() { - doTypeTest( - ':', - """ - |interface A - |object B - | - """, - """ - |interface A - |object B - | : - """) - } - - fun testColonOfSuperTypeListInCompanionObject() { - doTypeTest( - ':', - """ - |interface A - |class B { - | companion object - | - |} - """, - """ - |interface A - |class B { - | companion object - | : - |} - """) - } - - fun testColonOfSuperTypeListBeforeBody() { - doTypeTest( - ':', - """ - |open class A - |class B - | { - |} - """, - """ - |open class A - |class B - | : { - |} - """) - } - - fun testColonOfSuperTypeListNotNullIndent() { - doTypeTest( - ':', - """ - |fun test() { - | open class A - | class B - | - |} - """, - """ - |fun test() { - | open class A - | class B - | : - |} - """) - } - - fun testChainCallContinueWithDot() { - doTypeTest( - '.', - """ - |class Test{ fun test() = this } - |fun some() { - | Test() - | - |} - """, - """ - |class Test{ fun test() = this } - |fun some() { - | Test() - | . - |} - """) - } - - fun testChainCallContinueWithSafeCall() { - doTypeTest( - '.', - """ - |class Test{ fun test() = this } - |fun some() { - | Test() - | ? - |} - """, - """ - |class Test{ fun test() = this } - |fun some() { - | Test() - | ?. - |} - """) - } - - fun testContinueWithElvis() { - doTypeTest( - ':', - """ - |fun test(): Any? = null - |fun some() { - | test() - | ? - |} - """, - """ - |fun test(): Any? = null - |fun some() { - | test() - | ?: - |} - """ - ) - } - - fun testContinueWithOr() { - doTypeTest( - '|', - """ - |fun some() { - | if (true - | |) - |} - """, - """ - |fun some() { - | if (true - | ||) - |} - """ - ) - } - - fun testContinueWithAnd() { - doTypeTest( - '&', - """ - |fun some() { - | val test = true - | & - |} - """, - """ - |fun some() { - | val test = true - | && - |} - """ - ) - } - - fun testSpaceAroundRange() { - doTypeTest( - '.', - """ - | val test = 1 - """, - """ - | val test = 1 . - """ - ) - } - - fun testIndentBeforeElseWithBlock() { - doTypeTest( - '\n', - """ - |fun test(b: Boolean) { - | if (b) { - | } - | else if (!b) { - | } - |} - """, - """ - |fun test(b: Boolean) { - | if (b) { - | } - | - | else if (!b) { - | } - |} - """ - ) - } - - fun testIndentBeforeElseWithoutBlock() { - doTypeTest( - '\n', - """ - |fun test(b: Boolean) { - | if (b) - | foo() - | else { - | } - |} - """, - """ - |fun test(b: Boolean) { - | if (b) - | foo() - | - | else { - | } - |} - """ - ) - } - - fun testIndentOnFinishedVariableEndAfterEquals() { - doTypeTest( - '\n', - """ - |fun test() { - | val a = - | foo() - |} - """, - """ - |fun test() { - | val a = - | - | foo() - |} - """ - ) - } - - fun testIndentNotFinishedVariableEndAfterEquals() { - doTypeTest( - '\n', - """ - |fun test() { - | val a = - |} - """, - """ - |fun test() { - | val a = - | - |} - """ - ) - } - - fun testSmartEnterWithTabsOnConstructorParameters() { - doTypeTest( - '\n', - """ - |class A( - | a: Int, - |) - """, - """ - |class A( - | a: Int, - | - |) - """, - enableSmartEnterWithTabs() - ) - } - - fun testSmartEnterWithTabsInMethodParameters() { - doTypeTest( - '\n', - """ - |fun method( - | arg1: String, - |) {} - """, - """ - |fun method( - | arg1: String, - | - |) {} - """, - enableSmartEnterWithTabs() - ) - } - - fun testAutoIndentInWhenClause() { - doTypeTest( - '\n', - """ - |fun test() { - | when (2) { - | is Int -> - | } - |} - """, - """ - |fun test() { - | when (2) { - | is Int -> - | - | } - |} - """ - ) - } - - fun testEnterInFunctionWithExpressionBody() { - doTypeTest( - '\n', - """ - |fun test() = - """, - """ - |fun test() = - | - """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE - ) - } - - fun testEnterInMultiDeclaration() { - doTypeTest( - '\n', - """ - |fun test() { - | val (a, b) = - |} - """, - """ - |fun test() { - | val (a, b) = - | - |} - """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE - ) - } - - fun testEnterInVariableDeclaration() { - doTypeTest( - '\n', - """ - |val test = - """, - """ - |val test = - | - """, - ENABLE_KOTLIN_OFFICIAL_CODE_STYLE - ) - } - - fun testMoveThroughGT() { - configureFromFileText("a.kt", "val a: List>>") - EditorTestUtil.performTypingAction(editor, '>') - EditorTestUtil.performTypingAction(editor, '>') - checkResultByText("val a: List>") - } - - fun testCharClosingQuote() { - doTypeTest('\'', "val c = ", "val c = ''") - } - - private fun enableSmartEnterWithTabs(): (Project) -> Unit = { - val indentOptions = CodeStyle.getSettings(it).getIndentOptions(KotlinFileType.INSTANCE) - indentOptions.USE_TAB_CHARACTER = true - indentOptions.SMART_TABS = true - } - - private fun doTypeTest(ch: Char, beforeText: String, afterText: String, settingsModifier: ((Project) -> Unit)? = null) { - doTypeTest(ch.toString(), beforeText, afterText, settingsModifier) - } - - private fun doTypeTest(text: String, beforeText: String, afterText: String, settingsModifier: ((Project) -> Unit)? = null) { - try { - if (settingsModifier != null) { - settingsModifier(project) - } - - configureFromFileText("a.kt", beforeText.trimMargin()) - for (ch in text) { - EditorTestUtil.performTypingAction(editor, ch) - } - checkResultByText(afterText.trimMargin()) - } finally { - if (settingsModifier != null) { - CodeStyle.getSettings(project).clearCodeStyleSettings() - } - } - } - - - private fun doLtGtTestNoAutoClose(initText: String) { - doLtGtTest(initText, false) - } - - private fun doLtGtTest(initText: String, shouldCloseBeInsert: Boolean) { - configureFromFileText("a.kt", initText) - - EditorTestUtil.performTypingAction(editor, '<') - checkResultByText(if (shouldCloseBeInsert) initText.replace("", "<>") else initText.replace("", "<")) - - EditorTestUtil.performTypingAction(editor, EditorTestUtil.BACKSPACE_FAKE_CHAR) - checkResultByText(initText) - } - - private fun doLtGtTest(initText: String) { - doLtGtTest(initText, true) - } - - companion object { - private val ENABLE_KOTLIN_OFFICIAL_CODE_STYLE: (Project) -> Unit = { - val settings = ktCodeStyleSettings(it)?.all ?: error("No Settings") - KotlinStyleGuideCodeStyle.apply(settings) - } - } -}