Allow rendering extra tags for lineMarkers in tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<LineMarkerInfo> lineMarkers, boolean withDescription, String text) {
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = toLineMarkerTagPoints(lineMarkers, withDescription);
|
||||
|
||||
return insertTagsInText(lineMarkerPoints, text);
|
||||
return insertTagsInText(lineMarkerPoints, text, (TagInfo t) -> null);
|
||||
}
|
||||
|
||||
public static String insertInfoTags(List<HighlightInfo> highlights, String text) {
|
||||
List<HighlightTagPoint> 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<String>(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<? extends TagInfo> tags, String text) {
|
||||
public static String insertTagsInText(List<? extends TagInfo> tags, String text, Function<TagInfo, String> 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);
|
||||
|
||||
+3
-1
@@ -108,13 +108,15 @@ abstract class GradleDaemonAnalyzerTestCase(
|
||||
val highlightsTags: List<TagInfo<*>> = 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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user