Convert AbstractTypingIndentationTestBase to Kotlin

This commit is contained in:
Dmitry Gridin
2020-04-14 14:06:47 +07:00
parent cbd5d29457
commit 97a8bde64d
3 changed files with 59 additions and 68 deletions
@@ -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()
@@ -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 "";
}
}
@@ -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 = ""
}