Improve handling of escaped attributes inside test data markers

* Unescape quotes preceded with single backslash inside "descr" attribute
* Escape them back in the "actual" text when comparing results
This commit is contained in:
Mikhail Golubev
2015-07-01 14:31:28 +03:00
parent fa397cc82c
commit fde752be4c
2 changed files with 9 additions and 2 deletions
@@ -290,6 +290,7 @@ public class ExpectedHighlightingData {
}
if (descr != null) {
descr = descr.replaceAll("\\\\\\\\\"", "\""); // replace: \\" to ", doesn't check symbol before sequence \\"
descr = descr.replaceAll("\\\\\"", "\"");
}
HighlightInfoType type = WHATEVER;
@@ -554,8 +555,10 @@ public class ExpectedHighlightingData {
}
sb.insert(0, text.substring(info.startOffset, endPos));
String str = "<" + severity + " descr=\"" + info.getDescription() + "\"";
if (showAttributesKeys) str += " textAttributesKey=\"" + info.forcedTextAttributesKey + "\"";
String str = "<" + severity + " descr=\"" + StringUtil.escapeQuotes(String.valueOf(info.getDescription())) + "\"";
if (showAttributesKeys) {
str += " textAttributesKey=\"" + info.forcedTextAttributesKey + "\"";
}
str += ">";
sb.insert(0, str);
@@ -41,6 +41,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiReference;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.ExpectedHighlightingData;
import com.intellij.testFramework.HighlightTestInfo;
import com.intellij.testFramework.TestDataFile;
import com.intellij.usageView.UsageInfo;
@@ -246,6 +247,9 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
/**
* Runs highlighting test for the given files.
* Checks for {@link #ERROR_MARKER} markers by default.
* <p/>
* Double quotes in "descr" attribute of markers must be escaped by either one or two backslashes
* (see {@link ExpectedHighlightingData#extractExpectedHighlightsSet(Document)}).
*
* @param checkWarnings enables {@link #WARNING_MARKER} support.
* @param checkInfos enables {@link #INFO_MARKER} support.