mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
show expected FILE on the left of the diff view to be able to apply changes from actual right in the file
This commit is contained in:
+1
-1
@@ -106,6 +106,6 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
collectionsClass = (PsiClass)collectionsClass.getNavigationElement();
|
||||
final String text = collectionsClass.getContainingFile().getText();
|
||||
configureFromFileText("Collections.java", text.replaceAll("\r","\n"));
|
||||
doTestConfiguredFile(false, false);
|
||||
doTestConfiguredFile(false, false, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
backspace();
|
||||
backspace();
|
||||
doTestConfiguredFile(true, false);
|
||||
doTestConfiguredFile(true, false, null);
|
||||
}
|
||||
public void testNativeConversion() throws Exception {
|
||||
configureFromFileText("x.properties","a=<caret>v");
|
||||
@@ -99,7 +99,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase {
|
||||
configureByFile(BASE_PATH + "/" + "MultipleRanges.xml");
|
||||
type("US-ASCII");
|
||||
|
||||
doTestConfiguredFile(true, false);
|
||||
doTestConfiguredFile(true, false, null);
|
||||
}
|
||||
|
||||
private void doTest(@NonNls String filePath) throws Exception {
|
||||
@@ -110,7 +110,7 @@ public class LossyEncodingTest extends LightDaemonAnalyzerTestCase {
|
||||
EncodingManager.getInstance().setNative2AsciiForPropertiesFiles(null, true);
|
||||
configureByFile(BASE_PATH + "/" + "NativeEncoding.properties");
|
||||
|
||||
doTestConfiguredFile(true, false);
|
||||
doTestConfiguredFile(true, false, null);
|
||||
}
|
||||
|
||||
public static final String THREE_NOTORIOUS_RUSSIAN_LETTERS = "\u0416\u041e\u041f";
|
||||
|
||||
@@ -44,27 +44,27 @@ public class JavaSOEOnReparseTest extends LightDaemonAnalyzerTestCase {
|
||||
getEditor().getDocument().replaceString(pos, pos + 2, HUGE_EXPR);
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}});
|
||||
doTestConfiguredFile(false, false);
|
||||
doTestConfiguredFile(false, false, null);
|
||||
|
||||
// modify huge binary expression (1)
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() {
|
||||
getEditor().getDocument().insertString(pos, "\".\"+");
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}});
|
||||
doTestConfiguredFile(false, false);
|
||||
doTestConfiguredFile(false, false, null);
|
||||
|
||||
// modify huge binary expression (2)
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() {
|
||||
getEditor().getDocument().replaceString(pos, pos + 4, "");
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}});
|
||||
doTestConfiguredFile(false, false);
|
||||
doTestConfiguredFile(false, false, null);
|
||||
|
||||
// replace huge binary expression with small one
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() {
|
||||
getEditor().getDocument().replaceString(pos, pos + HUGE_EXPR.length(), "\".\"");
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}});
|
||||
doTestConfiguredFile(false, false);
|
||||
doTestConfiguredFile(false, false, null);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-6
@@ -34,6 +34,7 @@ import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -75,17 +76,22 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos, filePath);
|
||||
}
|
||||
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos, String filePath) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(getEditor().getDocument(),checkWarnings, checkInfos);
|
||||
checkHighlighting(data);
|
||||
checkHighlighting(data, composeLocalPath(filePath));
|
||||
}
|
||||
|
||||
private void checkHighlighting(ExpectedHighlightingData data) {
|
||||
@Nullable
|
||||
private String composeLocalPath(String filePath) {
|
||||
return filePath != null ? getTestDataPath() + "/" + filePath : null;
|
||||
}
|
||||
|
||||
private void checkHighlighting(ExpectedHighlightingData data, String filePath) {
|
||||
data.init();
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
@@ -97,7 +103,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
data.checkResult(infos, getEditor().getDocument().getText());
|
||||
data.checkResult(infos, getEditor().getDocument().getText(), filePath);
|
||||
}
|
||||
|
||||
protected HighlightTestInfo testFile(@NonNls @NotNull String filePath) {
|
||||
@@ -109,7 +115,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
if (checkSymbolNames) data.checkSymbolNames();
|
||||
|
||||
checkHighlighting(data);
|
||||
checkHighlighting(data, composeLocalPath(path));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
+4
@@ -30,6 +30,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -84,6 +85,9 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
quickFixTestCase.afterActionCompleted(testName, contents);
|
||||
}
|
||||
}
|
||||
catch (FileComparisonFailure e){
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
fail(testName);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework" exported="" />
|
||||
<orderEntry type="module" module-name="relaxng" exported="" scope="TEST" />
|
||||
<orderEntry type="module" module-name="junit_rt" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
+10
-2
@@ -40,6 +40,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.util.ConstantFunction;
|
||||
import com.intellij.util.Function;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -407,6 +408,10 @@ public class ExpectedHighlightingData {
|
||||
}
|
||||
|
||||
public void checkResult(Collection<HighlightInfo> infos, String text) {
|
||||
checkResult(infos, text, null);
|
||||
}
|
||||
|
||||
public void checkResult(Collection<HighlightInfo> infos, String text, String filePath) {
|
||||
String fileName = myFile == null ? "" : myFile.getName() + ": ";
|
||||
String failMessage = "";
|
||||
|
||||
@@ -460,11 +465,11 @@ public class ExpectedHighlightingData {
|
||||
}
|
||||
|
||||
if (failMessage.length() > 0) {
|
||||
compareTexts(infos, text, failMessage);
|
||||
compareTexts(infos, text, failMessage, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void compareTexts(Collection<HighlightInfo> infos, String text, String failMessage) {
|
||||
private void compareTexts(Collection<HighlightInfo> infos, String text, String failMessage, String filePath) {
|
||||
final ArrayList<HighlightInfo> list = new ArrayList<HighlightInfo>(infos);
|
||||
Collections.sort(list, new Comparator<HighlightInfo>() { // by start offset descending then by end offset ascending
|
||||
@Override
|
||||
@@ -513,6 +518,9 @@ public class ExpectedHighlightingData {
|
||||
}
|
||||
sb.insert(0, text.substring(0, end));
|
||||
|
||||
if (filePath != null && !myText.equals(sb.toString())) {
|
||||
throw new FileComparisonFailure(failMessage, myText, sb.toString(), filePath);
|
||||
}
|
||||
Assert.assertEquals(failMessage + "\n", myText, sb.toString());
|
||||
Assert.fail(failMessage);
|
||||
}
|
||||
|
||||
+20
-4
@@ -47,6 +47,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -289,7 +290,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
} catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
checkResultByText(message, StringUtil.convertLineSeparators(fileText), ignoreTrailingSpaces);
|
||||
checkResultByText(message, StringUtil.convertLineSeparators(fileText), ignoreTrailingSpaces, getTestDataPath() + "/" + filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,16 +298,26 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
* @param fileText
|
||||
*/
|
||||
protected void checkResultByText(@NonNls String fileText) {
|
||||
checkResultByText(null, fileText, false);
|
||||
checkResultByText(null, fileText, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as checkResultByFile but text is provided directly.
|
||||
* @param message - this check specific message. Added to text, caret position, selection checking. May be null
|
||||
* @param fileText
|
||||
* @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
|
||||
*/
|
||||
protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces) {
|
||||
checkResultByText(message, fileText, ignoreTrailingSpaces, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as checkResultByFile but text is provided directly.
|
||||
* @param message - this check specific message. Added to text, caret position, selection checking. May be null
|
||||
* @param fileText
|
||||
* @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
|
||||
*/
|
||||
protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces) {
|
||||
protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces, final String filePath) {
|
||||
bringRealEditorBack();
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@@ -346,7 +357,12 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
String newFileText = document.getText();
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
assertEquals(getMessage("Text mismatch", message), newFileText, myFile.getText());
|
||||
String fileText = myFile.getText();
|
||||
String failMessage = getMessage("Text mismatch", message);
|
||||
if (filePath != null && !newFileText.equals(fileText)) {
|
||||
throw new FileComparisonFailure(failMessage, newFileText, fileText, filePath);
|
||||
}
|
||||
assertEquals(failMessage, newFileText, fileText);
|
||||
|
||||
checkCaretPosition(caretMarker, newFileText, message);
|
||||
checkSelection(selStartMarker, selEndMarker, newFileText, message);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<orderEntry type="library" exported="" scope="TEST" name="Mocks" level="project" />
|
||||
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="relaxng" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="junit_rt" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user