diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractEnterHandlerTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractEnterHandlerTest.kt index eaa957d9550b..cf48c589cff5 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractEnterHandlerTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/AbstractEnterHandlerTest.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// 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.formatter import com.intellij.injected.editor.EditorWindow @@ -62,7 +62,8 @@ abstract class AbstractEnterHandlerTest : KotlinLightPlatformCodeInsightTestCase doNewlineTest( originalFile.path, afterFilePath, withoutCustomLineIndentProvider = withoutCustomLineIndentProvider, - ignoreFormatter = ignoreFormatter + ignoreFormatter = ignoreFormatter, + isInvertedTest = inverted, ) } ) @@ -72,10 +73,11 @@ abstract class AbstractEnterHandlerTest : KotlinLightPlatformCodeInsightTestCase beforeFilePath: String, afterFilePath: String, withoutCustomLineIndentProvider: Boolean, - ignoreFormatter: Boolean + ignoreFormatter: Boolean, + isInvertedTest: Boolean, ) { KotlinLineIndentProvider.useFormatter = true - typeAndCheck(beforeFilePath, afterFilePath, "with FormatterBasedLineIndentProvider", ignoreFormatter) + typeAndCheck(beforeFilePath, afterFilePath, "with FormatterBasedLineIndentProvider", ignoreFormatter, isInvertedTest) KotlinLineIndentProvider.useFormatter = false if (!withoutCustomLineIndentProvider) { @@ -100,7 +102,13 @@ abstract class AbstractEnterHandlerTest : KotlinLightPlatformCodeInsightTestCase ) } - private fun typeAndCheck(beforeFilePath: String, afterFilePath: String, errorMessage: String, invertResult: Boolean = false) { + private fun typeAndCheck( + beforeFilePath: String, + afterFilePath: String, + errorMessage: String, + invertResult: Boolean = false, + isInvertedTest: Boolean = false, + ) { configureByFile(beforeFilePath) executeAction(IdeActions.ACTION_EDITOR_ENTER) val editor = editor.safeAs()?.delegate ?: editor @@ -114,7 +122,7 @@ abstract class AbstractEnterHandlerTest : KotlinLightPlatformCodeInsightTestCase } if (invertResult) - Assert.assertTrue("Remove // IGNORE_FORMATTER", result.isFailure) + Assert.assertTrue("Remove // IGNORE_FORMATTER", isInvertedTest || result.isFailure) else result.getOrThrow() } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/EnterHandlerTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/EnterHandlerTestGenerated.java index ec0f2cecc9a4..e90c408ea07d 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/EnterHandlerTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/formatter/EnterHandlerTestGenerated.java @@ -844,21 +844,11 @@ public abstract class EnterHandlerTestGenerated extends AbstractEnterHandlerTest runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt"); } - @TestMetadata("InBinaryExpressionUnfinishedInIfInv.after.kt") - public void testInBinaryExpressionUnfinishedInIfInv() throws Exception { - runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt"); - } - @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt") public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.kt"); } - @TestMetadata("InBinaryExpressionsBeforeCloseParenthesisInv.after.kt") - public void testInBinaryExpressionsBeforeCloseParenthesisInv() throws Exception { - runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt"); - } - @TestMetadata("InExpressionsParentheses.after.kt") public void testInExpressionsParentheses() throws Exception { runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParentheses.after.kt"); @@ -1981,6 +1971,16 @@ public abstract class EnterHandlerTestGenerated extends AbstractEnterHandlerTest runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinished.after.inv.kt"); } + @TestMetadata("InBinaryExpressionUnfinishedInIf.after.inv.kt") + public void testInBinaryExpressionUnfinishedInIf() throws Exception { + runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt"); + } + + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt") + public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { + runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt"); + } + @TestMetadata("InExpressionsParenthesesBeforeOperand.after.inv.kt") public void testInExpressionsParenthesesBeforeOperand() throws Exception { runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParenthesesBeforeOperand.after.inv.kt"); diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt similarity index 82% rename from plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt rename to plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt index bc3d7901520d..42d85fec79c3 100644 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt +++ b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt @@ -1,6 +1,6 @@ fun test() { if (true && - ) + ) } // SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt index 44c1913ec7aa..bc3d7901520d 100644 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt +++ b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt @@ -1,6 +1,7 @@ fun test() { if (true && - ) + ) } -// SET_TRUE: CONTINUATION_INDENT_IN_IF_CONDITIONS +// SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS +// IGNORE_FORMATTER \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.kt index 05cd5cd18244..51de63d789d2 100644 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.kt +++ b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.kt @@ -2,4 +2,5 @@ fun test() { if (true &&) } -// SET_TRUE: CONTINUATION_INDENT_IN_IF_CONDITIONS +// SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS +// IGNORE_FORMATTER \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.kt deleted file mode 100644 index 51de63d789d2..000000000000 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.kt +++ /dev/null @@ -1,6 +0,0 @@ -fun test() { - if (true &&) -} - -// SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS -// IGNORE_FORMATTER \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt new file mode 100644 index 000000000000..2d34cb14c075 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt @@ -0,0 +1,5 @@ +val somelong = 3 + 4 - (3 + + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION +// IGNORE_FORMATTER \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt deleted file mode 100644 index b0e68aa74eae..000000000000 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt +++ /dev/null @@ -1,4 +0,0 @@ -val somelong = 3 + 4 - (3 + - ) - -// SET_FALSE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.kt b/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.kt deleted file mode 100644 index 7198bb8cdd8c..000000000000 --- a/plugins/kotlin/idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.kt +++ /dev/null @@ -1,3 +0,0 @@ -val somelong = 3 + 4 - (3 + ) - -// SET_FALSE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceTypingIndentationTestGenerated.java b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceTypingIndentationTestGenerated.java index 769cb5d50c8b..54d84271103c 100644 --- a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceTypingIndentationTestGenerated.java +++ b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceTypingIndentationTestGenerated.java @@ -844,21 +844,11 @@ public abstract class PerformanceTypingIndentationTestGenerated extends Abstract runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt"); } - @TestMetadata("InBinaryExpressionUnfinishedInIfInv.after.kt") - public void testInBinaryExpressionUnfinishedInIfInv() throws Exception { - runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt"); - } - @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt") public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.kt"); } - @TestMetadata("InBinaryExpressionsBeforeCloseParenthesisInv.after.kt") - public void testInBinaryExpressionsBeforeCloseParenthesisInv() throws Exception { - runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt"); - } - @TestMetadata("InExpressionsParentheses.after.kt") public void testInExpressionsParentheses() throws Exception { runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParentheses.after.kt"); @@ -1981,6 +1971,16 @@ public abstract class PerformanceTypingIndentationTestGenerated extends Abstract runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinished.after.inv.kt"); } + @TestMetadata("InBinaryExpressionUnfinishedInIf.after.inv.kt") + public void testInBinaryExpressionUnfinishedInIf() throws Exception { + runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt"); + } + + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt") + public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { + runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt"); + } + @TestMetadata("InExpressionsParenthesesBeforeOperand.after.inv.kt") public void testInExpressionsParenthesesBeforeOperand() throws Exception { runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParenthesesBeforeOperand.after.inv.kt");