diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt new file mode 100644 index 00000000000..9db63a476b8 --- /dev/null +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightTestCase.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2020 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.test + +import com.intellij.testFramework.LightPlatformCodeInsightTestCase + +abstract class KotlinLightPlatformCodeInsightTestCase : LightPlatformCodeInsightTestCase() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java deleted file mode 100644 index eb5bb58994d..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java +++ /dev/null @@ -1,68 +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.formatter; - -import com.intellij.application.options.CodeStyle; -import com.intellij.openapi.editor.CaretModel; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.testFramework.EditorTestUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -import java.io.File; - -@SuppressWarnings("deprecation") -public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeInsightTestCase { - public void doNewlineTest(String afterFilePath) throws Exception { - doNewlineTest(afterFilePath, false); - } - - public void doNewlineTestWithInvert(String afterInvFilePath) throws Exception { - doNewlineTest(afterInvFilePath, true); - } - - public void doNewlineTest(String afterFilePath, boolean inverted) throws Exception { - String testFileName = afterFilePath.substring(0, afterFilePath.indexOf(".")); - String testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf(".")); - - String originFilePath = testFileName + testFileExtension; - String originalFileText = FileUtil.loadFile(new File(originFilePath), true); - - try { - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, CodeStyle.getSettings(getProject_())); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doNewlineTest(originFilePath, afterFilePath); - } - finally { - CodeStyle.getSettings(getProject_()).clearCodeStyleSettings(); - } - } - - private void doNewlineTest(String beforeFilePath, String afterFilePath) { - configureByFile(beforeFilePath); - type('\n'); - - CaretModel caretModel = getEditor().getCaretModel(); - int offset = caretModel.getOffset(); - String actualTextWithCaret = new StringBuilder(getEditor().getDocument().getText()).insert(offset, EditorTestUtil.CARET_TAG).toString(); - - KotlinTestUtils.assertEqualsToFile(new File(afterFilePath), actualTextWithCaret); - } - - @NotNull - @Override - protected String getTestDataPath() { - return ""; - } -} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.kt b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.kt new file mode 100644 index 00000000000..cbef735b5c5 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.kt @@ -0,0 +1,49 @@ +/* + * 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.formatter + +import com.intellij.application.options.CodeStyle +import com.intellij.openapi.util.io.FileUtil +import com.intellij.testFramework.EditorTestUtil +import org.jetbrains.kotlin.idea.test.KotlinLightPlatformCodeInsightTestCase +import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File + +abstract class AbstractTypingIndentationTestBase : KotlinLightPlatformCodeInsightTestCase() { + fun doNewlineTestWithInvert(afterInvFilePath: String) { + doNewlineTest(afterInvFilePath, true) + } + + @JvmOverloads + fun doNewlineTest(afterFilePath: String, inverted: Boolean = false) { + val testFileName = afterFilePath.substring(0, afterFilePath.indexOf(".")) + val testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf(".")) + val originFilePath = testFileName + testFileExtension + val originalFileText = FileUtil.loadFile(File(originFilePath), true) + try { + val configurator = FormatSettingsUtil.createConfigurator(originalFileText, CodeStyle.getSettings(project)) + if (!inverted) { + configurator.configureSettings() + } else { + configurator.configureInvertedSettings() + } + + doNewlineTest(originFilePath, afterFilePath) + } finally { + CodeStyle.getSettings(project).clearCodeStyleSettings() + } + } + + private fun doNewlineTest(beforeFilePath: String, afterFilePath: String) { + configureByFile(beforeFilePath) + type('\n') + val caretModel = editor.caretModel + val offset = caretModel.offset + val actualTextWithCaret = StringBuilder(editor.document.text).insert(offset, EditorTestUtil.CARET_TAG).toString() + KotlinTestUtils.assertEqualsToFile(File(afterFilePath), actualTextWithCaret) + } + + override fun getTestDataPath(): String = "" +} \ No newline at end of file