test highlighting in multiple files
[fedora-idea.git] / testFramework / src / com / intellij / testFramework / fixtures / CodeInsightTestFixture.java
blobc0e9ef8906099c8d0adbf9d25a39151bf6e91dc6
1 /*
2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.testFramework.fixtures;
19 import com.intellij.codeInsight.completion.CompletionType;
20 import com.intellij.codeInsight.intention.IntentionAction;
21 import com.intellij.codeInsight.lookup.LookupElement;
22 import com.intellij.codeInspection.InspectionToolProvider;
23 import com.intellij.codeInspection.LocalInspectionTool;
24 import com.intellij.openapi.editor.Document;
25 import com.intellij.openapi.editor.Editor;
26 import com.intellij.openapi.editor.markup.GutterIconRenderer;
27 import com.intellij.openapi.fileTypes.FileType;
28 import com.intellij.openapi.vfs.VirtualFile;
29 import com.intellij.psi.PsiElement;
30 import com.intellij.psi.PsiFile;
31 import com.intellij.psi.PsiManager;
32 import com.intellij.psi.PsiReference;
33 import com.intellij.usageView.UsageInfo;
34 import org.jetbrains.annotations.NonNls;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
38 import java.io.IOException;
39 import java.util.Collection;
40 import java.util.List;
42 /**
44 * @see IdeaTestFixtureFactory#createCodeInsightFixture(IdeaProjectTestFixture)
46 * @author Dmitry Avdeev
48 public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
50 @NonNls String CARET_MARKER = "<caret>";
51 @NonNls String SELECTION_START_MARKER = "<selection>";
52 @NonNls String SELECTION_END_MARKER = "</selection>";
54 @NonNls String ERROR_MARKER = "error";
55 @NonNls String WARNING_MARKER = "warning";
56 @NonNls String INFORMATION_MARKER = "weak_warning";
57 @NonNls String SERVER_PROBLEM_MARKER = "server_problem";
58 @NonNls String INFO_MARKER = "info";
59 @NonNls String END_LINE_HIGHLIGHT_MARKER = "EOLError";
60 @NonNls String END_LINE_WARNING_MARKER = "EOLWarning";
62 Editor getEditor();
64 PsiFile getFile();
66 void setTestDataPath(@NonNls String dataPath);
68 String getTestDataPath();
70 String getTempDirPath();
72 TempDirTestFixture getTempDirFixture();
74 VirtualFile copyFileToProject(@NonNls String sourceFilePath, @NonNls String targetPath) throws IOException;
76 VirtualFile copyDirectoryToProject(@NonNls String sourceFilePath, @NonNls String targetPath) throws IOException;
78 VirtualFile copyFileToProject(@NonNls String sourceFilePath) throws IOException;
80 /**
81 * Enables inspections for highlighting tests.
82 * Should be called BEFORE {@link #setUp()}. And do not forget to call {@link #tearDown()}
84 * @param inspections inspections to be enabled in highliting tests.
85 * @see #enableInspections(com.intellij.codeInspection.InspectionToolProvider[])
87 void enableInspections(LocalInspectionTool... inspections);
89 void enableInspections(Class<? extends LocalInspectionTool>... inspections);
91 void disableInspections(LocalInspectionTool... inspections);
93 /**
94 * Enable all inspections provided by given providers.
96 * @param providers providers to be enabled.
97 * @see #enableInspections(com.intellij.codeInspection.LocalInspectionTool[])
99 void enableInspections(InspectionToolProvider... providers);
102 * Runs highliting test for the given files.
103 * Checks for {@link #ERROR_MARKER} markers by default.
105 * @param checkWarnings enables {@link #WARNING_MARKER} support.
106 * @param checkInfos enables {@link #INFO_MARKER} support.
107 * @param checkWeakWarnings enables {@link #INFORMATION_MARKER} support.
108 * @param filePaths the first file is tested only; the others are just copied along the first.
110 * @return highlighting duration in milliseconds.
111 * @throws Throwable any exception thrown during highlighting.
113 long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NonNls String... filePaths) throws Throwable;
115 long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NonNls String... filePaths) throws Throwable;
117 long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NonNls VirtualFile... files) throws Throwable;
120 * Check highlighting of file already loaded by configure* methods
121 * @param checkWarnings
122 * @param checkInfos
123 * @param checkWeakWarnings
124 * @return
125 * @throws Throwable
127 long checkHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) throws Throwable;
129 long checkHighlighting() throws Throwable;
132 * Runs highliting test for the given files.
133 * The same as {@link #testHighlighting(boolean, boolean, boolean, String...)} with all options set.
135 * @param filePaths the first file is tested only; the others are just copied along with the first.
137 * @return highlighting duration in milliseconds
138 * @throws Throwable any exception thrown during highlighting
140 long testHighlighting(@NonNls String... filePaths) throws Throwable;
142 long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, VirtualFile file) throws Throwable;
144 * Finds the reference in position marked by {@link #CARET_MARKER}.
146 * @param filePaths
147 * @return null if no reference found.
148 * @throws Throwable any exception.
150 * @see #getReferenceAtCaretPositionWithAssertion(String...)
152 @Nullable
153 PsiReference getReferenceAtCaretPosition(@NonNls String... filePaths) throws Throwable;
156 * Finds the reference in position marked by {@link #CARET_MARKER}.
157 * Asserts that the reference exists.
159 * @param filePaths
160 * @return founded reference
161 * @throws Throwable any exception
163 * @see #getReferenceAtCaretPosition(String...)
165 @NotNull
166 PsiReference getReferenceAtCaretPositionWithAssertion(@NonNls String... filePaths) throws Throwable;
169 * Collects available intentions in the whole file or at caret position if {@link #CARET_MARKER} presents.
171 * @param filePaths the first file is tested only; the others are just copied along with the first.
172 * @return available intentions.
173 * @throws Throwable any exception.
175 @NotNull
176 List<IntentionAction> getAvailableIntentions(@NonNls String... filePaths) throws Throwable;
178 @NotNull
179 List<IntentionAction> getAvailableIntentions() throws Throwable;
182 * Returns all intentions whose text contains hint
183 * @param hint
184 * @return
185 * @throws Throwable
187 List<IntentionAction> filterAvailableIntentions(@NotNull String hint) throws Throwable;
189 IntentionAction findSingleIntention(@NotNull String hint) throws Throwable;
191 IntentionAction getAvailableIntention(final String intentionName, final String... filePaths) throws Throwable;
194 * Launches the given action. Use {@link #checkResultByFile(String)} to check the result.
196 * @param action the action to be launched.
197 * @throws Throwable any exception.
199 void launchAction(@NotNull IntentionAction action) throws Throwable;
201 void configureByFile(@NonNls String file) throws Throwable;
203 void configureByFiles(@NonNls String... files) throws Throwable;
205 PsiFile configureByText(FileType fileType, @NonNls String text) throws Throwable;
208 * Compares current file against the given one.
210 * @param expectedFile file to check against.
211 * @throws Throwable any exception.
213 void checkResultByFile(@NonNls String expectedFile) throws Throwable;
215 void checkResultByFile(@NonNls String expectedFile, boolean ignoreWhitespaces) throws Throwable;
218 * Compares two files.
220 * @param filePath file to be checked.
221 * @param expectedFile file to check against.
222 * @param ignoreWhitespaces set to true to ignore differences in whitespaces.
223 * @throws Throwable any exception.
225 void checkResultByFile(@NonNls String filePath, @NonNls String expectedFile, boolean ignoreWhitespaces) throws Throwable;
227 void testCompletion(@NonNls String[] filesBefore, @NonNls String fileAfter) throws Throwable;
230 * Runs basic completion in caret position in fileBefore.
231 * Implies that there is only one completion variant and it was inserted automatically, and checks the result file text with fileAfter
232 * @param fileBefore
233 * @param fileAfter
234 * @param additionalFiles
235 * @throws Throwable
237 void testCompletion(@NonNls String fileBefore, @NonNls String fileAfter, final String... additionalFiles) throws Throwable;
240 * Runs basic completion in caret position in fileBefore.
241 * Checks that lookup is shown and it contains items with given lookup strings
242 * @param fileBefore
243 * @param items most probably will contain > 1 items
244 * @throws Throwable
246 void testCompletionVariants(@NonNls String fileBefore, @NonNls String... items) throws Throwable;
249 * Launches renaming refactoring and checks the result.
251 * @param fileBefore original file path. Use {@link #CARET_MARKER} to mark the element to rename.
252 * @param fileAfter result file to be checked against.
253 * @param newName new name for the element.
254 * @param additionalFiles
255 * @throws Throwable any exception.
256 * @see #testRename(String, String, String, String[])
258 void testRename(@NonNls String fileBefore, @NonNls String fileAfter, @NonNls String newName, final String... additionalFiles) throws Throwable;
260 void testRename(String fileAfter, String newName) throws Throwable;
262 Collection<UsageInfo> testFindUsages(@NonNls String... fileNames) throws Throwable;
264 void moveFile(@NonNls String filePath, @NonNls String to, final String... additionalFiles) throws Throwable;
267 * Returns gutter renderer at the caret position.
268 * Use {@link #CARET_MARKER} to mark the element to check.
270 * @param filePath file path
271 * @return gutter renderer at the caret position.
272 * @throws Throwable any exception.
274 @Nullable
275 GutterIconRenderer findGutter(@NonNls String filePath) throws Throwable;
277 PsiManager getPsiManager();
279 @Nullable LookupElement[] completeBasic();
281 @Nullable LookupElement[] complete(CompletionType type);
283 void checkResult(final String text) throws IOException;
285 Document getDocument(PsiFile file);
287 void setFileContext(@Nullable PsiElement context);
289 @NotNull
290 Collection<GutterIconRenderer> findAllGutters(String filePath) throws Throwable;
292 void type(final char c);
294 void performEditorAction(String actionId);
296 int configureFromTempProjectFile(String filePath) throws IOException;
298 void configureFromExistingVirtualFile(VirtualFile f) throws IOException;
300 PsiFile addFileToProject(@NonNls String relativePath, @NonNls String fileText) throws IOException;
302 List<String> getCompletionVariants(String fileBefore) throws Throwable;
304 @Nullable
305 LookupElement[] getLookupElements();
307 VirtualFile findFileInTempDir(String filePath);
309 @Nullable
310 List<String> getLookupElementStrings();
312 void renameElementAtCaret(String newName) throws Throwable;
314 void allowTreeAccessForFile(VirtualFile file);