diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 673fa64e1b3..10454b96087 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.intellij.openapi.Disposable; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -634,8 +635,17 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - String actualText = editor.getDocument().getText(); - String afterText = new StringBuilder(actualText).insert(editor.getCaretModel().getOffset(), "").toString(); + Caret caret = editor.getCaretModel().getCurrentCaret(); + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + String afterText = TagsTestDataUtil.insertTagsInText( + Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), + new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), + new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), + editor.getDocument().getText() + ); assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 index 90ee151869e..2784341e34f 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.intellij.openapi.Disposable; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -629,8 +630,17 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - String actualText = editor.getDocument().getText(); - String afterText = new StringBuilder(actualText).insert(editor.getCaretModel().getOffset(), "").toString(); + Caret caret = editor.getCaretModel().getCurrentCaret(); + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + String afterText = TagsTestDataUtil.insertTagsInText( + Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), + new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), + new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), + editor.getDocument().getText() + ); assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 index 8f464669754..2f85a9eb28e 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.intellij.openapi.Disposable; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -629,8 +630,17 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - String actualText = editor.getDocument().getText(); - String afterText = new StringBuilder(actualText).insert(editor.getCaretModel().getOffset(), "").toString(); + Caret caret = editor.getCaretModel().getCurrentCaret(); + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + String afterText = TagsTestDataUtil.insertTagsInText( + Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), + new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), + new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), + editor.getDocument().getText() + ); assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 index 70ef3cec62a..f64ab09cb87 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.intellij.openapi.Disposable; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -629,8 +630,17 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - String actualText = editor.getDocument().getText(); - String afterText = new StringBuilder(actualText).insert(editor.getCaretModel().getOffset(), "").toString(); + Caret caret = editor.getCaretModel().getCurrentCaret(); + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + String afterText = TagsTestDataUtil.insertTagsInText( + Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), + new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), + new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), + editor.getDocument().getText() + ); assertEqualsToFile(expectedFile, afterText); } diff --git a/idea/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java similarity index 100% rename from idea/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java rename to compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java diff --git a/idea/testData/joinLines/addSemicolon/FunctionCallsWithMutlineSeparator.kt.after b/idea/testData/joinLines/addSemicolon/FunctionCallsWithMutlineSeparator.kt.after index cc22964a57b..c275afac094 100644 --- a/idea/testData/joinLines/addSemicolon/FunctionCallsWithMutlineSeparator.kt.after +++ b/idea/testData/joinLines/addSemicolon/FunctionCallsWithMutlineSeparator.kt.after @@ -1,4 +1,4 @@ fun foo() { - println() + println() println() } diff --git a/idea/testData/joinLines/removeBraces/FunctionWithOneLineReturn.kt.after b/idea/testData/joinLines/removeBraces/FunctionWithOneLineReturn.kt.after index a4647ee6f2d..9bd02297bfe 100644 --- a/idea/testData/joinLines/removeBraces/FunctionWithOneLineReturn.kt.after +++ b/idea/testData/joinLines/removeBraces/FunctionWithOneLineReturn.kt.after @@ -1 +1 @@ -fun foo(): Int = 1 \ No newline at end of file +fun foo(): Int = 1 diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index aaeee33defb..37c381a8ca9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -16,9 +16,6 @@ package org.jetbrains.kotlin.idea; -import com.google.common.collect.Lists; -import com.intellij.openapi.editor.Caret; -import com.intellij.openapi.editor.Editor; import com.intellij.rt.execution.junit.FileComparisonFailure; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.CodeInsightTestUtil; @@ -26,7 +23,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TagsTestDataUtil; import java.io.File; @@ -183,21 +179,6 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase { } private void wrapToFileComparisonFailure(String failedFilePath) { - Editor editor = myFixture.getEditor(); - - Caret caret = editor.getCaretModel().getCurrentCaret(); - int selectionStart = caret.getSelectionStart(); - int selectionEnd = caret.getSelectionEnd(); - - String actualText = TagsTestDataUtil.insertTagsInText( - Lists.newArrayList( - new TagsTestDataUtil.TagInfo(caret.getOffset(), true, "caret"), - new TagsTestDataUtil.TagInfo(selectionStart, true, "selection"), - new TagsTestDataUtil.TagInfo(selectionEnd, false, "selection")), - editor.getDocument().getText() - ); - - KotlinTestUtils.assertEqualsToFile(new File(failedFilePath), actualText); + KotlinTestUtils.assertEqualsToFile(new File(failedFilePath), myFixture.getEditor()); } - }