diff options
Diffstat (limited to 'platform/platform-tests')
9 files changed, 309 insertions, 58 deletions
diff --git a/platform/platform-tests/testSrc/com/intellij/codeInsight/actions/ReformatOnlyVcsChangedTextTest.java b/platform/platform-tests/testSrc/com/intellij/codeInsight/actions/ReformatOnlyVcsChangedTextTest.java index 476bd66ddde4..d66988ab2ef5 100644 --- a/platform/platform-tests/testSrc/com/intellij/codeInsight/actions/ReformatOnlyVcsChangedTextTest.java +++ b/platform/platform-tests/testSrc/com/intellij/codeInsight/actions/ReformatOnlyVcsChangedTextTest.java @@ -163,6 +163,28 @@ public class ReformatOnlyVcsChangedTextTest extends LightPlatformTestCase { ); } + public void testModificationCRLF() throws IOException { + doTest( + "public class B {\r\n" + + " int a = 3;\r\n" + + " String text;\r\n" + + " Object last = null;\r\n" + + " Object first = null;\r\n" + + " Object second = null;\r\n" + + "}", + + "public class B {\r\n" + + " int a = 33;\r\n" + + " String text;\r\n" + + " Object last = new Object();\r\n" + + " Object first = null;\r\n" + + " Object second = new Object();\r\n" + + "}", + + line(1, 1), line(3,3), line(5,5) + ); + } + public void testReformatFiles() throws IOException { ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory); diff --git a/platform/platform-tests/testSrc/com/intellij/execution/process/AnsiEscapeDecoderTest.java b/platform/platform-tests/testSrc/com/intellij/execution/process/AnsiEscapeDecoderTest.java index 32ec00d1a733..df0acc766dc7 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/process/AnsiEscapeDecoderTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/process/AnsiEscapeDecoderTest.java @@ -3,47 +3,60 @@ package com.intellij.execution.process; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.testFramework.PlatformTestCase; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.junit.Assert; +import java.util.Arrays; import java.util.List; public class AnsiEscapeDecoderTest extends PlatformTestCase { public void testTextWithoutColors() throws Exception { AnsiEscapeDecoder decoder = new AnsiEscapeDecoder(); - decoder.escapeText("", ProcessOutputTypes.STDOUT, createExpectedAcceptor(ContainerUtil.newArrayList( + decoder.escapeText("", ProcessOutputTypes.STDOUT, createExpectedAcceptor( Pair.create("", ProcessOutputTypes.STDOUT) - ))); - decoder.escapeText("simple text", ProcessOutputTypes.STDOUT, createExpectedAcceptor(ContainerUtil.newArrayList( + )); + decoder.escapeText("simple text", ProcessOutputTypes.STDOUT, createExpectedAcceptor( Pair.create("simple text", ProcessOutputTypes.STDOUT) - ))); + )); } public void testSingleColoredChunk() throws Exception { AnsiEscapeDecoder decoder = new AnsiEscapeDecoder(); - decoder.escapeText("Chrome 35.0.1916 (Linux): Executed 0 of 1\u001B[32m SUCCESS\u001B[39m (0 secs / 0 secs)\n", ProcessOutputTypes.STDOUT, createExpectedAcceptor(ContainerUtil.newArrayList( + decoder.escapeText("Chrome 35.0.1916 (Linux): Executed 0 of 1\u001B[32m SUCCESS\u001B[39m (0 secs / 0 secs)\n", ProcessOutputTypes.STDOUT, createExpectedAcceptor( Pair.create("Chrome 35.0.1916 (Linux): Executed 0 of 1", ProcessOutputTypes.STDOUT), Pair.create(" SUCCESS", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[32m")), Pair.create(" (0 secs / 0 secs)\n", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[39m")) - ))); + )); } public void testCompoundEscSeq() throws Exception { AnsiEscapeDecoder decoder = new AnsiEscapeDecoder(); - decoder.escapeText("E\u001B[41m\u001B[37mE\u001B[0mE", ProcessOutputTypes.STDOUT, createExpectedAcceptor(ContainerUtil.newArrayList( + decoder.escapeText("E\u001B[41m\u001B[37mE\u001B[0mE", ProcessOutputTypes.STDOUT, createExpectedAcceptor( Pair.create("E", ProcessOutputTypes.STDOUT), Pair.create("E", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[41;37m")), Pair.create("E", ProcessOutputTypes.STDOUT) - ))); + )); } - private static AnsiEscapeDecoder.ColoredChunksAcceptor createExpectedAcceptor(@NotNull final List<Pair<String, Key>> expected) { + public void testOtherEscSeq() throws Exception { + AnsiEscapeDecoder decoder = new AnsiEscapeDecoder(); + decoder.escapeText("Plain\u001B[32mGreen\u001B[39mNormal\u001B[1A\u001B[2K\u001B[31mRed\u001B[39m", + ProcessOutputTypes.STDOUT, + createExpectedAcceptor( + Pair.create("Plain", ProcessOutputTypes.STDOUT), + Pair.create("Green", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[32m")), + Pair.create("Normal", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[39m")), + Pair.create("Red", ColoredOutputTypeRegistry.getInstance().getOutputKey("\u001B[31m")) + ) + ); + } + + private static AnsiEscapeDecoder.ColoredChunksAcceptor createExpectedAcceptor(@NotNull final Pair<String, Key>... expected) { return new AnsiEscapeDecoder.ColoredChunksAcceptor() { @Override public void coloredChunksAvailable(List<Pair<String, Key>> chunks) { - Assert.assertEquals(expected, chunks); + Assert.assertEquals(Arrays.asList(expected), chunks); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java b/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java index 3fad6d619b72..8e0a0b1e9aa3 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/ActivityMonitorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,15 @@ */ package com.intellij.ide; -import com.intellij.mock.MockApplication; import com.intellij.mock.MockProject; import com.intellij.mock.MockProjectEx; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.application.impl.ModalityStateEx; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.BusyObject; -import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,28 +34,12 @@ import org.jetbrains.annotations.Nullable; * Time: 10:04 AM * To change this template use File | Settings | File Templates. */ -public class ActivityMonitorTest extends UsefulTestCase { +public class ActivityMonitorTest extends LightPlatformTestCase { private UiActivityMonitorImpl myMonitor; - private ModalityState myCurrentState; @Override protected void setUp() throws Exception { super.setUp(); - myCurrentState = ModalityState.NON_MODAL; - final ModalityStateEx any = new ModalityStateEx(); - Extensions.registerAreaClass("IDEA_PROJECT", null); - ApplicationManager.setApplication(new MockApplication(getTestRootDisposable()) { - @NotNull - @Override - public ModalityState getCurrentModalityState() { - return myCurrentState; - } - - @Override - public ModalityState getAnyModalityState() { - return any; - } - }, getTestRootDisposable()); myMonitor = new UiActivityMonitorImpl(); myMonitor.setActive(true); disposeOnTearDown(myMonitor); @@ -150,19 +133,23 @@ public class ActivityMonitorTest extends UsefulTestCase { myMonitor.addActivity(new UiActivity("non_modal_1"), ModalityState.NON_MODAL); assertBusy(null); - myCurrentState = new ModalityStateEx(new Object[] {"dialog"}); - assertReady(null); + LaterInvocator.enterModal("dialog"); + try { + assertReady(null); - myMonitor.addActivity(new UiActivity("non_modal2"), ModalityState.NON_MODAL); - assertReady(null); + myMonitor.addActivity(new UiActivity("non_modal2"), ModalityState.NON_MODAL); + assertReady(null); - myMonitor.addActivity(new UiActivity("modal_1"), new ModalityStateEx(new Object[] {"dialog"})); - assertBusy(null); + myMonitor.addActivity(new UiActivity("modal_1"), new ModalityStateEx(new Object[] {"dialog"})); + assertBusy(null); - myMonitor.addActivity(new UiActivity("modal_2"), new ModalityStateEx(new Object[] {"dialog", "popup"})); - assertBusy(null); + myMonitor.addActivity(new UiActivity("modal_2"), new ModalityStateEx(new Object[] {"dialog", "popup"})); + assertBusy(null); + } + finally { + LaterInvocator.leaveModal("dialog"); + } - myCurrentState = ModalityState.NON_MODAL; assertBusy(null); } @@ -172,8 +159,13 @@ public class ActivityMonitorTest extends UsefulTestCase { myMonitor.addActivity(new UiActivity("non_modal_1"), ModalityState.any()); assertBusy(null); - myCurrentState = new ModalityStateEx(new Object[] {"dialog"}); - assertBusy(null); + try { + LaterInvocator.enterModal("dialog"); + assertBusy(null); + } + finally { + LaterInvocator.leaveModal("dialog"); + } } public void testUiActivity() throws Exception { @@ -183,11 +175,12 @@ public class ActivityMonitorTest extends UsefulTestCase { assertFalse(new UiActivity("root", "folder2").isSameOrGeneralFor(new UiActivity("anotherRoot"))); } - private void assertReady(@Nullable Project key, UiActivity ... activities) { + private void assertReady(@Nullable Project key, @NotNull UiActivity ... activities) { + UIUtil.dispatchAllInvocationEvents(); BusyObject.Impl busy = (BusyObject.Impl)(key != null ? myMonitor.getBusy(key, activities) : myMonitor.getBusy(activities)); assertTrue("Must be READY, but was: BUSY", busy.isReady()); - final boolean[] done = new boolean[] {false}; + final boolean[] done = {false}; busy.getReady(this).doWhenDone(new Runnable() { @Override public void run() { @@ -198,9 +191,9 @@ public class ActivityMonitorTest extends UsefulTestCase { assertTrue(done[0]); } - private void assertBusy(@Nullable Project key, UiActivity ... activities) { + private void assertBusy(@Nullable Project key, @NotNull UiActivity ... activities) { + UIUtil.dispatchAllInvocationEvents(); BusyObject.Impl busy = (BusyObject.Impl)(key != null ? myMonitor.getBusy(key, activities) : myMonitor.getBusy(activities)); assertFalse("Must be BUSY, but was: READY", busy.isReady()); } - } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/ApplicationStoreTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/ApplicationStoreTest.java new file mode 100644 index 000000000000..cfbd5a12f146 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/ApplicationStoreTest.java @@ -0,0 +1,153 @@ +package com.intellij.openapi.components.impl; + +import com.intellij.application.options.PathMacrosImpl; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.components.*; +import com.intellij.openapi.components.impl.stores.*; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.testFramework.LightPlatformLangTestCase; +import com.intellij.util.xmlb.XmlSerializerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; + +public class ApplicationStoreTest extends LightPlatformLangTestCase { + private File testAppConfig; + private MyComponentStore componentStore; + + @Override + public void setUp() throws Exception { + super.setUp(); + + String testAppConfigPath = System.getProperty("test.app.config.path"); + if (testAppConfigPath == null) { + testAppConfig = FileUtil.createTempDirectory("testAppSettings", null); + } + else { + testAppConfig = new File(FileUtil.expandUserHome(testAppConfigPath)); + } + FileUtil.delete(testAppConfig); + + componentStore = new MyComponentStore(testAppConfig.getAbsolutePath()); + } + + @Override + public void tearDown() throws Exception { + try { + Disposer.dispose(componentStore); + componentStore = null; + } + finally { + try { + super.tearDown(); + } + finally { + FileUtil.delete(testAppConfig); + } + } + } + + public void testStreamProviderSaveIfSeveralStoragesConfigured() throws Exception { + SeveralStoragesConfigured component = new SeveralStoragesConfigured(); + componentStore.initComponent(component, false); + StoreUtil.doSave(componentStore); + } + + class MyComponentStore extends ComponentStoreImpl implements Disposable { + private final StateStorageManager stateStorageManager; + + MyComponentStore(@NotNull final String testAppConfigPath) { + TrackingPathMacroSubstitutor macroSubstitutor = new ApplicationPathMacroManager().createTrackingSubstitutor(); + stateStorageManager = new StateStorageManagerImpl(macroSubstitutor, "application", this, ApplicationManager.getApplication().getPicoContainer()) { + @Override + protected StorageData createStorageData(String storageSpec) { + return new FileBasedStorage.FileStorageData("application"); + } + + @Nullable + @Override + protected String getOldStorageSpec(Object component, final String componentName, final StateStorageOperation operation) { + return null; + } + + @Override + protected String getVersionsFilePath() { + return testAppConfigPath + "/options/appComponentVersions.xml"; + } + + @Override + protected TrackingPathMacroSubstitutor getMacroSubstitutor(@NotNull final String fileSpec) { + if (fileSpec.equals(StoragePathMacros.APP_CONFIG + "/" + PathMacrosImpl.EXT_FILE_NAME + ".xml")) { + return null; + } + return super.getMacroSubstitutor(fileSpec); + } + }; + + stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.APP_CONFIG), testAppConfigPath); + } + + @Override + public void load() throws IOException, StateStorageException { + } + + @NotNull + @Override + public StateStorageManager getStateStorageManager() { + return stateStorageManager; + } + + @Override + public void dispose() { + } + + @Nullable + @Override + protected StateStorage getDefaultsStorage() { + return null; + } + } + + static class SeveralStoragesConfiguredStorageChooser implements StateStorageChooser<SeveralStoragesConfigured> { + @Override + public Storage[] selectStorages(Storage[] storages, SeveralStoragesConfigured component, StateStorageOperation operation) { + if (operation == StateStorageOperation.WRITE) { + for (Storage storage : storages) { + if (storage.file().equals(StoragePathMacros.APP_CONFIG + "/proxy.settings.xml")) { + return new Storage[]{storage}; + } + } + } + return storages; + } + } + + @State( + name = "HttpConfigurable", + storages = { + // we use two storages due to backward compatibility, see http://crucible.labs.intellij.net/cru/CR-IC-5142 + @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml"), + @Storage(file = StoragePathMacros.APP_CONFIG + "/proxy.settings.xml") + }, + storageChooser = SeveralStoragesConfiguredStorageChooser.class + ) + static class SeveralStoragesConfigured implements PersistentStateComponent<SeveralStoragesConfigured> { + public String foo = "defaultValue"; + + @Nullable + @Override + public SeveralStoragesConfigured getState() { + foo = "newValue"; + return this; + } + + @Override + public void loadState(SeveralStoragesConfigured state) { + XmlSerializerUtil.copyBean(state, this); + } + } +} diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/StateStorageManagerImplTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/StateStorageManagerImplTest.java index a4e3024a60d0..76c673626b26 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/StateStorageManagerImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/components/impl/StateStorageManagerImplTest.java @@ -23,6 +23,7 @@ import com.intellij.openapi.components.impl.stores.StateStorageManagerImpl; import com.intellij.openapi.components.impl.stores.StorageData; import com.intellij.openapi.util.Disposer; import com.intellij.testFramework.LightPlatformLangTestCase; +import org.jetbrains.annotations.Nullable; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -43,6 +44,7 @@ public class StateStorageManagerImplTest extends LightPlatformLangTestCase { throw new UnsupportedOperationException("Method createStorageData not implemented in " + getClass()); } + @Nullable @Override protected String getOldStorageSpec(Object component, String componentName, StateStorageOperation operation) throws StateStorageException { throw new UnsupportedOperationException("Method getOldStorageSpec not implemented in " + getClass()); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java index f494f565acf1..b128eb5d3ec2 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java @@ -56,6 +56,13 @@ public abstract class HeavyFileEditorManagerTestCase extends CodeInsightFixtureT } @Override + protected void tearDown() throws Exception { + myManager = null; + + super.tearDown(); + } + + @Override protected String getBasePath() { return "/platform/platform-tests/testData/fileEditorManager"; } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java index 96d85c122624..54a2865ad444 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java @@ -22,20 +22,19 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.KeyboardShortcut; import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.util.Clock; -import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.testFramework.LightPlatformLangTestCase; import javax.swing.*; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -public class ModifierKeyDoubleClickHandlerTest extends LightPlatformTestCase { +public class ModifierKeyDoubleClickHandlerTest extends LightPlatformLangTestCase { private static final String MY_SHIFT_SHIFT_ACTION = "ModifierKeyDoubleClickHandlerTest.action1"; private static final String MY_SHIFT_KEY_ACTION = "ModifierKeyDoubleClickHandlerTest.action2"; private static final String MY_SHIFT_SHIFT_KEY_ACTION = "ModifierKeyDoubleClickHandlerTest.action3"; - public static final KeyboardShortcut SHIFT_KEY_SHORTCUT = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, - InputEvent.SHIFT_MASK), - null); + private static final KeyboardShortcut SHIFT_KEY_SHORTCUT = + new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, InputEvent.SHIFT_MASK), null); private final JComponent myComponent = new JPanel(); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index 66c10c26b528..1a0d9c37388e 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -396,8 +396,8 @@ public class LocalFileSystemTest extends PlatformLangTestCase { PersistentFS.getInstance().findRoot("", myFS); fail("should fail by assertion in PersistentFsImpl.findRoot()"); } - catch (AssertionError e) { - String message = e.getMessage(); + catch (Throwable t) { + String message = t.getMessage(); assertTrue(message, message.startsWith("Invalid root")); } } diff --git a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java index b1ab5117dba9..693c23766d62 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/impl/PsiDocumentManagerImplTest.java @@ -25,11 +25,13 @@ import com.intellij.openapi.editor.impl.event.DocumentEventImpl; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ex.ProjectManagerEx; +import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; +import com.intellij.psi.*; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.testFramework.LeakHunter; import com.intellij.testFramework.LightVirtualFile; @@ -40,6 +42,7 @@ import com.intellij.util.concurrency.Semaphore; import com.intellij.util.ui.UIUtil; import java.io.File; +import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; public class PsiDocumentManagerImplTest extends PlatformLangTestCase { @@ -394,4 +397,63 @@ public class PsiDocumentManagerImplTest extends PlatformLangTestCase { }); assertTrue(commitThread.isEnabled()); } + + public void testFileChangesToText() throws IOException { + VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc")); + PsiFile psiFile = getPsiManager().findFile(vFile); + Document document = getPsiDocumentManager().getDocument(psiFile); + + rename(vFile, "a.xml"); + assertFalse(psiFile.isValid()); + assertNotSame(psiFile, getPsiManager().findFile(vFile)); + psiFile = getPsiManager().findFile(vFile); + + assertSame(document, FileDocumentManager.getInstance().getDocument(vFile)); + assertSame(document, getPsiDocumentManager().getDocument(psiFile)); + } + + public void testFileChangesToBinary() throws IOException { + VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc")); + PsiFile psiFile = getPsiManager().findFile(vFile); + Document document = getPsiDocumentManager().getDocument(psiFile); + + rename(vFile, "a.zip"); + assertFalse(psiFile.isValid()); + psiFile = getPsiManager().findFile(vFile); + assertInstanceOf(psiFile, PsiBinaryFile.class); + + assertNoFileDocumentMapping(vFile, psiFile, document); + assertEquals("abc", document.getText()); + } + + public void testFileBecomesTooLarge() throws Exception { + VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc")); + PsiFile psiFile = getPsiManager().findFile(vFile); + Document document = getPsiDocumentManager().getDocument(psiFile); + + makeFileTooLarge(vFile); + assertFalse(psiFile.isValid()); + psiFile = getPsiManager().findFile(vFile); + assertInstanceOf(psiFile, PsiLargeFile.class); + + assertNoFileDocumentMapping(vFile, psiFile, document); + assertEquals("abc", document.getText()); + } + + private void assertNoFileDocumentMapping(VirtualFile vFile, PsiFile psiFile, Document document) { + assertNull(FileDocumentManager.getInstance().getDocument(vFile)); + assertNull(FileDocumentManager.getInstance().getFile(document)); + assertNull(getPsiDocumentManager().getPsiFile(document)); + assertNull(getPsiDocumentManager().getDocument(psiFile)); + } + + private void makeFileTooLarge(final VirtualFile vFile) throws Exception { + WriteCommandAction.runWriteCommandAction(myProject, new ThrowableComputable<Object, Exception>() { + @Override + public Object compute() throws Exception { + VfsUtil.saveText(vFile, StringUtil.repeat("a", FileUtil.LARGE_FOR_CONTENT_LOADING + 1)); + return null; + } + }); + } } |