Rewrite GradleDaemonAnalyzerTest
Previously, GradleDaemonAnalyzer reused common IJ infrastructure for highlighting tests (see DaemonAnalyzerTеstCase, ExpectedHighlightingData and such). Unfortunately, this infrastructure had several flaws, mainly around checking expected highlighting against actual one: - overlapping line markers lead to crash (fixed in 193+) - no way to sanitize descriptions of line markers (important for cases where description returns HTML-formatted text, which makes testdata completely unreadable and also drives parser insane) - thrown FileNotFoundException doesn't have a physical file with expected testdata attached, which makes browsing diff a little less convenient (no way to apply changes to expected file) - no easy way to plug-in with additional after-highlighting checks This commit fixes it by overriding doCheckResult and providing custom checking of highlighting/line markers, based on TagsTestDataUtil. Because we don't rely on IJ-checking anymore, we also remove weird hoops with removing/adding testdata markup in checkFiles. Also this commit adds strings sanitization in TagsTestDataUtil, removing HTML-tags and line breaks, so that description of tag is always one-liner with plain text.
This commit is contained in:
@@ -21,28 +21,23 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TagsTestDataUtil {
|
||||
public static String insertInfoTags(List<LineMarkerInfo> lineMarkers, boolean withDescription, String text) {
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = Lists.newArrayList();
|
||||
for (LineMarkerInfo markerInfo : lineMarkers) {
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.startOffset, true, markerInfo, withDescription));
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.endOffset, false, markerInfo, withDescription));
|
||||
}
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = toLineMarkerTagPoints(lineMarkers, withDescription);
|
||||
|
||||
return insertTagsInText(lineMarkerPoints, text);
|
||||
}
|
||||
|
||||
public static String insertInfoTags(List<HighlightInfo> highlights, String text) {
|
||||
List<HighlightTagPoint> highlightPoints = Lists.newArrayList();
|
||||
for (HighlightInfo highlight : highlights) {
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.startOffset, true, highlight));
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.endOffset, false, highlight));
|
||||
}
|
||||
List<HighlightTagPoint> highlightPoints = toHighlightTagPoints(highlights);
|
||||
|
||||
return insertTagsInText(highlightPoints, text);
|
||||
}
|
||||
@@ -88,6 +83,29 @@ public class TagsTestDataUtil {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<LineMarkerTagPoint> toLineMarkerTagPoints(
|
||||
Collection<LineMarkerInfo> lineMarkers,
|
||||
boolean withDescription
|
||||
) {
|
||||
List<LineMarkerTagPoint> lineMarkerPoints = Lists.newArrayList();
|
||||
for (LineMarkerInfo markerInfo : lineMarkers) {
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.startOffset, true, markerInfo, withDescription));
|
||||
lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.endOffset, false, markerInfo, withDescription));
|
||||
}
|
||||
return lineMarkerPoints;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<HighlightTagPoint> toHighlightTagPoints(Collection<HighlightInfo> highlights) {
|
||||
List<HighlightTagPoint> highlightPoints = Lists.newArrayList();
|
||||
for (HighlightInfo highlight : highlights) {
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.startOffset, true, highlight));
|
||||
highlightPoints.add(new HighlightTagPoint(highlight.endOffset, false, highlight));
|
||||
}
|
||||
return highlightPoints;
|
||||
}
|
||||
|
||||
public static class TagInfo<Data> implements Comparable<TagInfo<?>> {
|
||||
protected final int offset;
|
||||
protected final boolean isStart;
|
||||
@@ -144,7 +162,7 @@ public class TagsTestDataUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static class HighlightTagPoint extends TagInfo<HighlightInfo> {
|
||||
public static class HighlightTagPoint extends TagInfo<HighlightInfo> {
|
||||
private final HighlightInfo highlightInfo;
|
||||
|
||||
private HighlightTagPoint(int offset, boolean start, HighlightInfo info) {
|
||||
@@ -165,9 +183,10 @@ public class TagsTestDataUtil {
|
||||
public String getAttributesString() {
|
||||
if (isStart) {
|
||||
if (highlightInfo.getDescription() != null) {
|
||||
return String.format("textAttributesKey=\"%s\" descr=%s",
|
||||
highlightInfo.forcedTextAttributesKey,
|
||||
highlightInfo.getDescription());
|
||||
return String.format("descr=\"%s\" textAttributesKey=\"%s\"",
|
||||
sanitizeLineBreaks(highlightInfo.getDescription()),
|
||||
highlightInfo.forcedTextAttributesKey
|
||||
);
|
||||
}
|
||||
else {
|
||||
return String.format("textAttributesKey=\"%s\"", highlightInfo.forcedTextAttributesKey);
|
||||
@@ -179,7 +198,7 @@ public class TagsTestDataUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static class LineMarkerTagPoint extends TagInfo<LineMarkerInfo> {
|
||||
public static class LineMarkerTagPoint extends TagInfo<LineMarkerInfo> {
|
||||
private final boolean withDescription;
|
||||
|
||||
public LineMarkerTagPoint(int offset, boolean start, LineMarkerInfo info, boolean withDescription) {
|
||||
@@ -196,7 +215,17 @@ public class TagsTestDataUtil {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getAttributesString() {
|
||||
return withDescription ? String.format("descr=\"%s\"", data.getLineMarkerTooltip()) : "descr=\"*\"";
|
||||
return withDescription ? String.format("descr=\"%s\"", sanitizeLineMarkerTooltip(data.getLineMarkerTooltip())) : "descr=\"*\"";
|
||||
}
|
||||
}
|
||||
|
||||
private static @NotNull String sanitizeLineMarkerTooltip(@Nullable String originalText) {
|
||||
if (originalText == null) return "null";
|
||||
String noHtmlTags = StringUtil.removeHtmlTags(originalText);
|
||||
return sanitizeLineBreaks(noHtmlTags);
|
||||
}
|
||||
|
||||
private static String sanitizeLineBreaks(String originalText) {
|
||||
return StringUtil.replace(originalText, "\n", " ");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user