From 4f5c3d138776848691e2b3809130f4cc6cfafcf4 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 20 Jan 2020 16:34:40 +0300 Subject: [PATCH] Allow rendering extra tags for lineMarkers in tests --- .../kotlin/test/KotlinTestUtils.java | 2 +- .../kotlin/test/TagsTestDataUtil.java | 22 ++++++++++++++----- .../GradleMultiplatformHighlightingTest.kt | 4 +++- .../LambdaReturnValueHintsTest.kt | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) 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 0df6b713214..487b0183172 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -446,7 +446,7 @@ public class KotlinTestUtils { tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")); } - String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText()); + String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText(), (TagsTestDataUtil.TagInfo t) -> null); assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java index cd38d1e8341..8ddb73f60e3 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/TagsTestDataUtil.java @@ -27,19 +27,20 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; public class TagsTestDataUtil { public static String insertInfoTags(List lineMarkers, boolean withDescription, String text) { List lineMarkerPoints = toLineMarkerTagPoints(lineMarkers, withDescription); - return insertTagsInText(lineMarkerPoints, text); + return insertTagsInText(lineMarkerPoints, text, (TagInfo t) -> null); } public static String insertInfoTags(List highlights, String text) { List highlightPoints = toHighlightTagPoints(highlights); - return insertTagsInText(highlightPoints, text); + return insertTagsInText(highlightPoints, text, (TagInfo t) -> null); } public static String generateTextWithCaretAndSelection(@NotNull Editor editor) { @@ -50,10 +51,10 @@ public class TagsTestDataUtil { points.add(new TagInfo(editor.getSelectionModel().getSelectionEnd(), false, "selection")); } - return insertTagsInText(points, editor.getDocument().getText()); + return insertTagsInText(points, editor.getDocument().getText(), (TagInfo t) -> null); } - public static String insertTagsInText(List tags, String text) { + public static String insertTagsInText(List tags, String text, Function computeExtraAttributes) { StringBuilder builder = new StringBuilder(text); // Need to sort tags for inserting them in reverse order to have valid offsets for yet not inserted tags. @@ -65,12 +66,21 @@ public class TagsTestDataUtil { String tagText; if (point.isStart) { String attributesString = point.getAttributesString(); + String extraAttributes = computeExtraAttributes.apply(point); + + String allAttributes; + if (extraAttributes != null) { + allAttributes = attributesString + " " + extraAttributes; + } else { + allAttributes = attributesString; + } + String closeSuffix = point.isClosed ? "/" : ""; if (attributesString.isEmpty()) { tagText = String.format("<%s%s>", point.getName(), closeSuffix); } else { - tagText = String.format("<%s %s%s>", point.getName(), attributesString, closeSuffix); + tagText = String.format("<%s %s%s>", point.getName(), allAttributes, closeSuffix); } } else { @@ -111,7 +121,7 @@ public class TagsTestDataUtil { protected final boolean isStart; protected final boolean isClosed; protected final boolean isFixed; - protected final Data data; + public final Data data; public TagInfo(int offset, boolean start, Data data) { this(offset, start, false, false, data); diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt index fc043a849f4..3ef924c71d5 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt @@ -108,13 +108,15 @@ abstract class GradleDaemonAnalyzerTestCase( val highlightsTags: List> = TagsTestDataUtil.toHighlightTagPoints(filteredHighlights) val allTags = lineMarkersTags + highlightsTags - val actualTextWithTags = TagsTestDataUtil.insertTagsInText(allTags, text) + val actualTextWithTags = TagsTestDataUtil.insertTagsInText(allTags, text) { renderAdditionalAttributeForTag(it) } val physicalFileWithExpectedTestData = file.testDataFileByUserData KotlinTestUtils.assertEqualsToFile(physicalFileWithExpectedTestData, actualTextWithTags) } protected open fun performAdditionalChecksAfterHighlighting(editor: Editor) { } + + protected open fun renderAdditionalAttributeForTag(tag: TagInfo<*>): String? = null } internal fun checkFiles( diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt index 44318e6aca4..2dfdeb7b421 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt @@ -62,7 +62,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { val expectedText = run { val tags = if (editor.caretModel.offset > 0) listOf(CaretTag(editor)) else emptyList() - TagsTestDataUtil.insertTagsInText(tags, editor.document.text) + TagsTestDataUtil.insertTagsInText(tags, editor.document.text) { null } } // Clean test file from the hints tags @@ -92,7 +92,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { tags.addAll(collectActualLineExtensionsTags()) - TagsTestDataUtil.insertTagsInText(tags, editor.document.text) + TagsTestDataUtil.insertTagsInText(tags, editor.document.text) { null } } Assert.assertEquals(expectedText, actualText)