Search in sources :

Example 1 with ExpectedHighlightingData

use of com.intellij.testFramework.ExpectedHighlightingData in project intellij-community by JetBrains.

the class HighlightingTestBase method doCustomHighlighting.

protected void doCustomHighlighting(boolean checkWeakWarnings, Boolean includeExternalToolPass) {
    final PsiFile file = myTestFixture.getFile();
    final Document doc = myTestFixture.getEditor().getDocument();
    ExpectedHighlightingData data = new ExpectedHighlightingData(doc, true, checkWeakWarnings, false, file);
    data.init();
    PsiDocumentManager.getInstance(myTestFixture.getProject()).commitAllDocuments();
    Collection<HighlightInfo> highlights1 = doHighlighting(includeExternalToolPass);
    data.checkResult(highlights1, doc.getText());
}
Also used : ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Example 2 with ExpectedHighlightingData

use of com.intellij.testFramework.ExpectedHighlightingData in project intellij-plugins by JetBrains.

the class SwfHighlightingTest method testLineMarkersInSwf.

@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithLineMarkers })
public void testLineMarkersInSwf() throws Exception {
    final String testName = getTestName(false);
    myAfterCommitRunnable = () -> FlexTestUtils.addLibrary(myModule, "lib", getTestDataPath() + getBasePath() + "/", testName + ".swc", null, null);
    // actual test data is in library.swf; this file is here just because we need any file
    configureByFile("/" + testName + ".as");
    VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".swc");
    vFile = JarFileSystem.getInstance().getJarRootForLocalFile(vFile).findChild("library.swf");
    myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    myFile = myPsiManager.findFile(vFile);
    ((EditorImpl) myEditor).setCaretActive();
    vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".as");
    final String verificationText = StreamUtil.convertSeparators(VfsUtilCore.loadText(vFile));
    checkHighlighting(new ExpectedHighlightingData(new DocumentImpl(verificationText), false, false, true, myFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 3 with ExpectedHighlightingData

use of com.intellij.testFramework.ExpectedHighlightingData in project kotlin by JetBrains.

the class AbstractLineMarkersTest method doTest.

public void doTest(String path) {
    try {
        String fileText = FileUtil.loadFile(new File(path));
        ConfigLibraryUtil.configureLibrariesByDirective(myFixture.getModule(), PlatformTestUtil.getCommunityPath(), fileText);
        myFixture.configureByFile(path);
        Project project = myFixture.getProject();
        Document document = myFixture.getEditor().getDocument();
        ExpectedHighlightingData data = new ExpectedHighlightingData(document, false, false, false, myFixture.getFile());
        data.init();
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        myFixture.doHighlighting();
        List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
        try {
            data.checkLineMarkers(markers, document.getText());
            // the latter doesn't throw assertion error when some line markers are expected, but none are present.
            if (FileUtil.loadFile(new File(path)).contains("<lineMarker") && markers.isEmpty()) {
                throw new AssertionError("Some line markers are expected, but nothing is present at all");
            }
        } catch (AssertionError error) {
            try {
                String actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, myFixture.getFile().getText());
                KotlinTestUtils.assertEqualsToFile(new File(path), actualTextWithTestData);
            } catch (FileComparisonFailure failure) {
                throw new FileComparisonFailure(error.getMessage() + "\n" + failure.getMessage(), failure.getExpected(), failure.getActual(), failure.getFilePath());
            }
        }
        assertNavigationElements(markers);
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
Also used : Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) Document(com.intellij.openapi.editor.Document) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 4 with ExpectedHighlightingData

use of com.intellij.testFramework.ExpectedHighlightingData in project intellij-plugins by JetBrains.

the class ActionScriptHighlightingTest method testBadResolveOfSuperclass.

public void testBadResolveOfSuperclass() throws Exception {
    final Module module2 = doCreateRealModuleIn("module2", myProject, FlexModuleType.getInstance());
    final Ref<VirtualFile> fileFromModule2 = new Ref<>();
    final Ref<Sdk> sdk1 = new Ref<>();
    final Ref<Sdk> sdk2 = new Ref<>();
    myAfterCommitRunnable = () -> {
        sdk1.set(FlexTestUtils.createSdk(getTestDataPath() + BASE_PATH + "fake_sdk", "4.0.0"));
        {
            SdkModificator m = sdk1.get().getSdkModificator();
            m.removeAllRoots();
            m.addRoot(sdk1.get().getHomeDirectory().findChild("common_root"), OrderRootType.CLASSES);
            m.addRoot(sdk1.get().getHomeDirectory().findChild("flex_root"), OrderRootType.CLASSES);
            m.commitChanges();
        }
        sdk2.set(FlexTestUtils.createSdk(getTestDataPath() + BASE_PATH + "fake_sdk", "4.0.0"));
        {
            SdkModificator m = sdk2.get().getSdkModificator();
            m.removeAllRoots();
            m.addRoot(sdk2.get().getHomeDirectory().findChild("common_root"), OrderRootType.CLASSES);
            m.addRoot(sdk2.get().getHomeDirectory().findChild("air_root"), OrderRootType.CLASSES);
            m.commitChanges();
        }
        fileFromModule2.set(copyFileToModule(module2, getTestDataPath() + BASE_PATH + getTestName(false) + "2.as"));
    };
    configureByFile(BASE_PATH + getTestName(false) + "1.as");
    FlexTestUtils.modifyConfigs(myProject, e -> {
        FlexTestUtils.setSdk(e.getConfigurations(myModule)[0], sdk1.get());
        FlexTestUtils.setSdk(e.getConfigurations(module2)[0], sdk2.get());
    });
    checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(), true, true, false, myFile));
    myFile = PsiManager.getInstance(myProject).findFile(fileFromModule2.get());
    myEditor = createEditor(fileFromModule2.get());
    checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(), true, true, false, myFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 5 with ExpectedHighlightingData

use of com.intellij.testFramework.ExpectedHighlightingData in project intellij-plugins by JetBrains.

the class ActionScriptHighlightingInTextFieldTest method doTestForEditorTextField.

private void doTestForEditorTextField(JSExpressionCodeFragment fragment) throws Exception {
    myFile = fragment;
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(fragment);
    final JSEditorTextField editorTextField = new JSEditorTextField(myProject, document);
    // initialize editor
    editorTextField.addNotify();
    myEditor = editorTextField.getEditor();
    try {
        checkHighlighting(new ExpectedHighlightingData(editorTextField.getDocument(), true, true, true, myFile));
    } finally {
        editorTextField.removeNotify();
        UIUtil.dispatchAllInvocationEvents();
    }
}
Also used : ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) Document(com.intellij.openapi.editor.Document) JSEditorTextField(com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)

Aggregations

ExpectedHighlightingData (com.intellij.testFramework.ExpectedHighlightingData)10 Document (com.intellij.openapi.editor.Document)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 HighlightTestInfo (com.intellij.testFramework.HighlightTestInfo)2 File (java.io.File)2 IOException (java.io.IOException)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 JSEditorTextField (com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Module (com.intellij.openapi.module.Module)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 Ref (com.intellij.openapi.util.Ref)1