From fde752be4c32c519c59d9fd4de033882b68a9399 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Mon, 29 Jun 2015 21:48:21 +0300 Subject: [PATCH] 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 --- .../intellij/testFramework/ExpectedHighlightingData.java | 7 +++++-- .../testFramework/fixtures/CodeInsightTestFixture.java | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index 460c83c7d818..58a076c503ea 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -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); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 7c48c2aabbdc..6d316f16be16 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -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. + *

+ * 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.