Search in sources :

Example 1 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.

the class FileDocumentManagerImplTest method testConvertSeparators.

public void testConvertSeparators() throws Exception {
    final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest");
    Document document = myDocumentManager.getDocument(file);
    assertNotNull(file.toString(), document);
    assertEquals("test\ntest", document.getText());
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) Document(com.intellij.openapi.editor.Document)

Example 2 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.

the class FileDocumentManagerImplTest method testContentChanged_doNotReloadChangedDocumentOnSave.

public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
    final MockVirtualFile file = new MockVirtualFile("test.txt", "test") {

        @Override
        public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
            long oldStamp = getModificationStamp();
            setModificationStamp(LocalTimeCounter.currentTime());
            myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
        }
    };
    myReloadFromDisk = Boolean.FALSE;
    final Document document = myDocumentManager.getDocument(file);
    assertNotNull(file.toString(), document);
    WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, "old "));
    long documentStamp = document.getModificationStamp();
    file.setContent(null, "xxx", false);
    myDocumentManager.saveAllDocuments();
    assertEquals("old test", document.getText());
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
    assertEquals("old test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
    assertEquals(documentStamp, document.getModificationStamp());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) Document(com.intellij.openapi.editor.Document)

Example 3 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleFrameworkDetectorTest method createSuitableFilePattern_withInvalidFilename_doesNotMatch.

@Test
public void createSuitableFilePattern_withInvalidFilename_doesNotMatch() {
    // unaccepted file name pattern, although correct content.
    MockVirtualFile invalidNameFile = new MockVirtualFile("myApp.yaml");
    FileContent wrongFile = new FileContentImpl(invalidNameFile, VALID_APP_ENGINE_FLEX_YAML_CONTENT, System.currentTimeMillis());
    assertThat(pattern.accepts(wrongFile)).isFalse();
}
Also used : FileContent(com.intellij.util.indexing.FileContent) MockVirtualFile(com.intellij.mock.MockVirtualFile) FileContentImpl(com.intellij.util.indexing.FileContentImpl) Test(org.junit.Test)

Example 4 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleFrameworkDetectorTest method createSuitableFilePattern_appYaml_withValidContent_matches.

@Test
public void createSuitableFilePattern_appYaml_withValidContent_matches() {
    MockVirtualFile validAppEngineFlexFile = new MockVirtualFile("app.yaml");
    FileContent validAppEngineFlexFileContent = new FileContentImpl(validAppEngineFlexFile, VALID_APP_ENGINE_FLEX_YAML_CONTENT, System.currentTimeMillis());
    assertThat(pattern.accepts(validAppEngineFlexFileContent)).isTrue();
}
Also used : FileContent(com.intellij.util.indexing.FileContent) MockVirtualFile(com.intellij.mock.MockVirtualFile) FileContentImpl(com.intellij.util.indexing.FileContentImpl) Test(org.junit.Test)

Example 5 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleFrameworkDetectorTest method createSuitableFilePattern_appYml_withValidContent_matches.

@Test
public void createSuitableFilePattern_appYml_withValidContent_matches() {
    MockVirtualFile validAppEngineFlexFile = new MockVirtualFile("app.yml");
    FileContent validAppEngineFlexFileContent = new FileContentImpl(validAppEngineFlexFile, VALID_APP_ENGINE_FLEX_YAML_CONTENT, System.currentTimeMillis());
    assertThat(pattern.accepts(validAppEngineFlexFileContent)).isTrue();
}
Also used : FileContent(com.intellij.util.indexing.FileContent) MockVirtualFile(com.intellij.mock.MockVirtualFile) FileContentImpl(com.intellij.util.indexing.FileContentImpl) Test(org.junit.Test)

Aggregations

MockVirtualFile (com.intellij.mock.MockVirtualFile)15 Document (com.intellij.openapi.editor.Document)7 FileContent (com.intellij.util.indexing.FileContent)5 FileContentImpl (com.intellij.util.indexing.FileContentImpl)5 Test (org.junit.Test)5 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 MockPsiFile (com.intellij.mock.MockPsiFile)1 MockPsiManager (com.intellij.mock.MockPsiManager)1 MockVirtualLink (com.intellij.mock.MockVirtualLink)1 Disposable (com.intellij.openapi.Disposable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)1 PsiClass (com.intellij.psi.PsiClass)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1