mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (test)
- Groovy tests moved to corresponding module - assertions cleaned - parasitic exceptions suppressed
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -25,6 +25,8 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
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.VirtualFile;
|
||||
@@ -51,22 +53,31 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author: MYakovlev
|
||||
* Date: Oct 17, 2002
|
||||
* Time: 7:53:31 PM
|
||||
/**
|
||||
* @author MYakovlev
|
||||
* @since Oct 17, 2002
|
||||
*/
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
protected VirtualFile[] mySourceDirs;
|
||||
private FindManager myFindManager;
|
||||
private VirtualFile[] mySourceDirs;
|
||||
|
||||
public void testFindString() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFindManager = FindManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFindManager = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testFindString() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}";
|
||||
FindResult findResult = findManager.findString(text, 0, findModel);
|
||||
FindResult findResult = myFindManager.findString(text, 0, findModel);
|
||||
assertTrue(findResult.isStringFound());
|
||||
|
||||
findModel = new FindModel();
|
||||
@@ -77,7 +88,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setMultipleFiles(false);
|
||||
findModel.setProjectScope(true);
|
||||
|
||||
findResult = findManager.findString(text, 40, findModel);
|
||||
findResult = myFindManager.findString(text, 40, findModel);
|
||||
assertFalse(findResult.isStringFound());
|
||||
|
||||
findModel = new FindModel();
|
||||
@@ -89,7 +100,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setProjectScope(true);
|
||||
findModel.setForward(false);
|
||||
|
||||
findResult = findManager.findString(text, 40, findModel);
|
||||
findResult = myFindManager.findString(text, 40, findModel);
|
||||
assertTrue(findResult.isStringFound());
|
||||
|
||||
findModel = new FindModel();
|
||||
@@ -100,7 +111,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setMultipleFiles(false);
|
||||
findModel.setProjectScope(true);
|
||||
|
||||
findResult = findManager.findString(text, 0, findModel);
|
||||
findResult = myFindManager.findString(text, 0, findModel);
|
||||
assertTrue(findResult.isStringFound());
|
||||
|
||||
findModel = new FindModel();
|
||||
@@ -112,7 +123,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setProjectScope(true);
|
||||
|
||||
final FindResult[] findResultArr = new FindResult[1];
|
||||
findInNewThread(findModel, findManager, text, 0, findResultArr);
|
||||
findInNewThread(findModel, myFindManager, text, 0, findResultArr);
|
||||
new WaitFor(30 *1000){
|
||||
@Override
|
||||
protected boolean condition() {
|
||||
@@ -139,9 +150,9 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
return findThread;
|
||||
}
|
||||
|
||||
public void testFindUsages() throws Exception{
|
||||
public void testFindUsages() {
|
||||
initProject("findManager", "src", "src1");
|
||||
final String projectDir = (PathManagerEx.getTestDataPath() + "/find/findManager").replace('/', File.separatorChar);
|
||||
String projectDir = FileUtil.toSystemDependentName(PathManagerEx.getTestDataPath() + "/find/findManager");
|
||||
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("done");
|
||||
@@ -154,7 +165,6 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setWithSubdirectories(true);
|
||||
checkFindUsages(12, findModel);
|
||||
|
||||
//findModel = new FindModel();
|
||||
findModel.setFromCursor(false);
|
||||
findModel.setGlobal(true);
|
||||
findModel.setMultipleFiles(true);
|
||||
@@ -165,13 +175,9 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
findModel.setWholeWordsOnly(true);
|
||||
checkFindUsages(5, findModel);
|
||||
// findModel.setForward(false);
|
||||
// findModel.setCaseSensitive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void checkFindUsages(int expectedResults, FindModel findModel) throws Exception{
|
||||
private void checkFindUsages(int expectedResults, FindModel findModel) {
|
||||
Collection<UsageInfo> usages = findUsages(findModel);
|
||||
assertEquals(expectedResults, usages.size());
|
||||
}
|
||||
@@ -184,9 +190,8 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void testFindWholeWordsInProperties() throws Exception {
|
||||
public void testFindWholeWordsInProperties() {
|
||||
initProject("findInPath", "src");
|
||||
|
||||
searchProperty("xx.yy");
|
||||
searchProperty(".yy");
|
||||
searchProperty("xx.");
|
||||
@@ -208,22 +213,31 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
if (!(usages.get(0).getFile() instanceof PsiJavaFile)) {
|
||||
Collections.swap(usages, 0, 1);
|
||||
}
|
||||
PsiElement element = usages.get(0).getElement();
|
||||
//assertTrue(element instanceof PsiJavaFile);
|
||||
PsiElement refElement = element.findElementAt(usages.get(0).getRangeInElement().getStartOffset()).getParent();
|
||||
|
||||
PsiElement refElement = getParentFromUsage(usages.get(0));
|
||||
assertTrue(refElement instanceof PsiLiteralExpression);
|
||||
assertEquals("xx.yy", ((PsiLiteralExpression)refElement).getValue());
|
||||
|
||||
VirtualFile file = mySourceDirs[0].findFileByRelativePath("x/dd.properties");
|
||||
assertNotNull(file);
|
||||
PropertiesFile propertiesFile = (PropertiesFile)PsiManager.getInstance(myProject).findFile(file);
|
||||
element = usages.get(1).getElement();
|
||||
//assertTrue(element instanceof PropertiesFile);
|
||||
refElement = element.findElementAt(usages.get(1).getRangeInElement().getStartOffset()).getParent();
|
||||
assertNotNull(propertiesFile);
|
||||
refElement = getParentFromUsage(usages.get(1));
|
||||
assertTrue(refElement instanceof IProperty);
|
||||
assertSame(propertiesFile.findPropertyByKey("xx.yy"), refElement);
|
||||
}
|
||||
|
||||
public void testFindInClassHierarchy() throws Exception {
|
||||
private static PsiElement getParentFromUsage(UsageInfo usage) {
|
||||
ProperTextRange range = usage.getRangeInElement();
|
||||
assertNotNull(range);
|
||||
PsiElement element = usage.getElement();
|
||||
assertNotNull(element);
|
||||
PsiElement elementAt = element.findElementAt(range.getStartOffset());
|
||||
assertNotNull(elementAt);
|
||||
return elementAt.getParent();
|
||||
}
|
||||
|
||||
public void testFindInClassHierarchy() {
|
||||
initProject("findInClassHierarchy", "src");
|
||||
|
||||
FindModel findModel = new FindModel();
|
||||
@@ -244,7 +258,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
public void testDollars() throws Exception {
|
||||
createFile(myModule, "A.java", "foo foo$ $foo");
|
||||
createFile(myModule, "A.txt", "foo foo$ $foo");
|
||||
|
||||
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setWholeWordsOnly(true);
|
||||
findModel.setFromCursor(false);
|
||||
@@ -260,15 +274,12 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
findModel.setStringToFind("$foo");
|
||||
assertSize(2, findUsages(findModel));
|
||||
|
||||
}
|
||||
|
||||
public void testReplaceRegexp() throws Throwable {
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testReplaceRegexp() {
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("bug(?=here)");
|
||||
findModel.setStringToReplace("x$0y");
|
||||
findModel.setStringToFind("bug_(?=here)");
|
||||
findModel.setStringToReplace("x_$0t");
|
||||
findModel.setWholeWordsOnly(false);
|
||||
findModel.setFromCursor(false);
|
||||
findModel.setGlobal(true);
|
||||
@@ -277,21 +288,19 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setRegularExpressions(true);
|
||||
findModel.setPromptOnReplace(false);
|
||||
|
||||
findManager.setFindNextModel(null);
|
||||
findManager.getFindInFileModel().copyFrom(findModel);
|
||||
myFindManager.setFindNextModel(null);
|
||||
myFindManager.getFindInFileModel().copyFrom(findModel);
|
||||
|
||||
String text = "bughere\n" + "bughere";
|
||||
String text = "bug_here\nbug_here";
|
||||
configureByText(FileTypes.PLAIN_TEXT, text);
|
||||
boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
|
||||
assertTrue(succ);
|
||||
assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));
|
||||
|
||||
assertEquals("xbugyhere\n" + "xbugyhere", getEditor().getDocument().getText());
|
||||
assertEquals("x_bug_there\nx_bug_there", getEditor().getDocument().getText());
|
||||
}
|
||||
public void testReplaceRegexp1() throws Throwable {
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testReplaceRegexp1() {
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("bug(?=here)");
|
||||
findModel.setStringToFind("bug_(?=here)");
|
||||
findModel.setStringToReplace("$0");
|
||||
findModel.setWholeWordsOnly(false);
|
||||
findModel.setFromCursor(false);
|
||||
@@ -301,20 +310,17 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setRegularExpressions(true);
|
||||
findModel.setPromptOnReplace(false);
|
||||
|
||||
findManager.setFindNextModel(null);
|
||||
findManager.getFindInFileModel().copyFrom(findModel);
|
||||
myFindManager.setFindNextModel(null);
|
||||
myFindManager.getFindInFileModel().copyFrom(findModel);
|
||||
|
||||
String text = "bughere\n" + "bughere";
|
||||
String text = "bug_here\nbug_here";
|
||||
configureByText(FileTypes.PLAIN_TEXT, text);
|
||||
boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
|
||||
assertTrue(succ);
|
||||
assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));
|
||||
|
||||
assertEquals(text, getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
public void testReplaceRegexpWithNewLine() throws Throwable {
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testReplaceRegexpWithNewLine() {
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("xxx");
|
||||
findModel.setStringToReplace("xxx\\n");
|
||||
@@ -326,18 +332,17 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setRegularExpressions(true);
|
||||
findModel.setPromptOnReplace(false);
|
||||
|
||||
findManager.setFindNextModel(null);
|
||||
findManager.getFindInFileModel().copyFrom(findModel);
|
||||
myFindManager.setFindNextModel(null);
|
||||
myFindManager.getFindInFileModel().copyFrom(findModel);
|
||||
|
||||
String text = "xxx";
|
||||
configureByText(FileTypes.PLAIN_TEXT, text);
|
||||
boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
|
||||
assertTrue(succ);
|
||||
assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));
|
||||
|
||||
assertEquals(text+"\n", getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
private void initProject(String folderName, final String... sourceDirs) throws Exception{
|
||||
private void initProject(String folderName, final String... sourceDirs) {
|
||||
final String testDir = JavaTestUtil.getJavaTestDataPath() + "/find/" + folderName;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable(){
|
||||
@Override
|
||||
@@ -345,11 +350,11 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
try{
|
||||
mySourceDirs = new VirtualFile[sourceDirs.length];
|
||||
for (int i = 0; i < sourceDirs.length; i++){
|
||||
String sourceDir = sourceDirs[i];
|
||||
mySourceDirs[i] = LocalFileSystem.getInstance().refreshAndFindFileByPath(new File(testDir + File.separatorChar + sourceDir).getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
String sourcePath = testDir + "/" + sourceDirs[i];
|
||||
mySourceDirs[i] = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourcePath));
|
||||
}
|
||||
VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(new File(testDir).getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
|
||||
VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(testDir));
|
||||
Sdk jdk = IdeaTestUtil.getMockJdk17();
|
||||
PsiTestUtil.removeAllRoots(myModule, jdk);
|
||||
PsiTestUtil.addContentRoot(myModule, projectDir);
|
||||
@@ -364,12 +369,10 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testReplaceAll() throws Throwable {
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testReplaceAll() throws FindManager.MalformedReplacementStringException {
|
||||
FindModel findModel = new FindModel();
|
||||
String toFind = "xxx";
|
||||
String toReplace = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
@SuppressWarnings("SpellCheckingInspection") String toReplace = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
findModel.setStringToFind(toFind);
|
||||
findModel.setStringToReplace(toReplace);
|
||||
findModel.setWholeWordsOnly(true);
|
||||
@@ -380,13 +383,14 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setRegularExpressions(false);
|
||||
findModel.setPromptOnReplace(false);
|
||||
|
||||
findManager.setFindNextModel(null);
|
||||
findManager.getFindInFileModel().copyFrom(findModel);
|
||||
myFindManager.setFindNextModel(null);
|
||||
myFindManager.getFindInFileModel().copyFrom(findModel);
|
||||
|
||||
String text = StringUtil.repeat(toFind + "\n",6);
|
||||
configureByText(FileTypes.PLAIN_TEXT, text);
|
||||
|
||||
List<Usage> usages = FindUtil.findAll(getProject(), myEditor, findModel);
|
||||
assertNotNull(usages);
|
||||
for (Usage usage : usages) {
|
||||
ReplaceInProjectManager.getInstance(getProject()).replaceUsage(usage, findModel, Collections.<Usage>emptySet(), false);
|
||||
}
|
||||
@@ -394,9 +398,10 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
assertEquals(newText, getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
public void testFindInFileUnderLibraryUnderProject() throws Exception {
|
||||
public void testFindInFileUnderLibraryUnderProject() {
|
||||
initProject("libUnderProject", "src");
|
||||
PsiTestUtil.addLibrary(myModule, "lib", JavaTestUtil.getJavaTestDataPath() + "/find/libUnderProject/lib", new String[]{""}, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
String libDir = JavaTestUtil.getJavaTestDataPath() + "/find/libUnderProject/lib";
|
||||
PsiTestUtil.addLibrary(myModule, "lib", libDir, new String[]{""}, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
|
||||
FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("TargetWord");
|
||||
@@ -411,7 +416,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
assertSize(2, findUsages(findModel));
|
||||
}
|
||||
|
||||
public void testLocalScopeSearchPerformance() throws Throwable {
|
||||
public void testLocalScopeSearchPerformance() throws Exception {
|
||||
final int fileCount = 3000;
|
||||
final int lineCount = 500;
|
||||
TempDirTestFixture fixture = new LightTempDirTestFixtureImpl();
|
||||
@@ -426,6 +431,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
VirtualFile file = fixture.createFile("target.txt", sampleText);
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
assertNotNull(psiFile);
|
||||
final FindModel findModel = new FindModel();
|
||||
findModel.setStringToFind("TargetWord");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
@@ -451,38 +457,28 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testFindInCommentsAndLiterals() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInCommentsAndLiterals() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
String text = "\"done done done\" /* done done done */";
|
||||
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(findManager, findModel, text);
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(myFindManager, findModel, text);
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(findManager, findModel, text);
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(myFindManager, findModel, text);
|
||||
}
|
||||
|
||||
public void testFindInJavaDocs() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInJavaDocs() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
String text = "/** done done done */";
|
||||
|
||||
findModel.setInCommentsOnly(true);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text);
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text);
|
||||
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "groovy");
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text);
|
||||
}
|
||||
|
||||
public void testFindInCommentsProperlyWorksWithOffsets() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInCommentsProperlyWorksWithOffsets() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
String prefix = "/*";
|
||||
@@ -491,72 +487,45 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
findModel.setInCommentsOnly(true);
|
||||
LightVirtualFile file = new LightVirtualFile("A.java", text);
|
||||
|
||||
FindResult findResult = findManager.findString(text, prefix.length(), findModel, file);
|
||||
FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file);
|
||||
assertTrue(findResult.isStringFound());
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
findResult = findManager.findString(text, prefix.length(), findModel, file);
|
||||
findResult = myFindManager.findString(text, prefix.length(), findModel, file);
|
||||
assertTrue(findResult.isStringFound());
|
||||
}
|
||||
|
||||
public void testFindInUserFileType() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInUserFileType() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
String text = "\"done done\"; 'done'; // done\n" +
|
||||
"/* done\n" +
|
||||
"done */";
|
||||
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(findManager, findModel, text, "cs");
|
||||
FindManagerTestUtils.runFindInCommentsAndLiterals(myFindManager, findModel, text, "cs");
|
||||
}
|
||||
|
||||
public void testFindInLiteralToSkipQuotes() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInLiteralToSkipQuotes() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("^done$");
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
|
||||
String text = "\"done\"; 'done'; 'done' \"done2\"";
|
||||
|
||||
findModel.setInStringLiteralsOnly(true);
|
||||
findModel.setInCommentsOnly(false);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "java");
|
||||
|
||||
text = "def n = \"\"\"done\"\"\"\n def n = /done/\n def n = \"done\"\n def n = \"done2\"";
|
||||
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "groovy");
|
||||
|
||||
text = "\"\"; \"done\"; 'done'; 'done' \"done2\"";
|
||||
String text = "\"done\"; 'done'; 'done' \"done2\"";
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java");
|
||||
|
||||
findModel.setStringToFind("done");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
findModel.setRegularExpressions(false);
|
||||
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "java");
|
||||
text = "\"\"; \"done\"; 'done'; 'done' \"done2\"";
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java");
|
||||
}
|
||||
|
||||
public void testFindInShellCommentsOfGroovy() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
|
||||
String text = "#! done done done\n";
|
||||
|
||||
findModel.setInCommentsOnly(true);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "groovy");
|
||||
}
|
||||
|
||||
public void testFindInJavaDoc() throws Exception{
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
|
||||
public void testFindInJavaDoc() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("do ne");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
|
||||
String text = "/** do ne do ne do ne */";
|
||||
|
||||
findModel.setInCommentsOnly(true);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "java");
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "java");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,36 +139,41 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return configureByFile(vFile, projectFile);
|
||||
}
|
||||
|
||||
protected PsiFile configureByText(@NotNull FileType fileType, @NonNls final String text) throws Exception {
|
||||
protected PsiFile configureByText(@NotNull FileType fileType, @NonNls final String text) {
|
||||
return configureByText(fileType, text, null);
|
||||
}
|
||||
|
||||
protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls final String text, @Nullable String _extension) throws Exception {
|
||||
final String extension = _extension == null ? fileType.getDefaultExtension():_extension;
|
||||
protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls final String text, @Nullable String _extension) {
|
||||
try {
|
||||
final String extension = _extension == null ? fileType.getDefaultExtension():_extension;
|
||||
|
||||
File dir = createTempDirectory();
|
||||
final File tempFile = FileUtil.createTempFile(dir, "aaa", "." + extension, true);
|
||||
final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Exception {
|
||||
fileTypeManager.associateExtension(fileType, extension);
|
||||
}
|
||||
}.execute();
|
||||
File dir = createTempDirectory();
|
||||
final File tempFile = FileUtil.createTempFile(dir, "aaa", "." + extension, true);
|
||||
final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Exception {
|
||||
fileTypeManager.associateExtension(fileType, extension);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
|
||||
assert vFile != null;
|
||||
VfsUtil.saveText(vFile, text);
|
||||
|
||||
final VirtualFile vdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
|
||||
|
||||
PsiTestUtil.addSourceRoot(myModule, vdir);
|
||||
|
||||
configureByExistingFile(vFile);
|
||||
|
||||
assertEquals(fileType, myFile.getVirtualFile().getFileType());
|
||||
return myFile;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
|
||||
assert vFile != null;
|
||||
VfsUtil.saveText(vFile, text);
|
||||
|
||||
final VirtualFile vdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
|
||||
|
||||
PsiTestUtil.addSourceRoot(myModule, vdir);
|
||||
|
||||
configureByExistingFile(vFile);
|
||||
|
||||
assertEquals(fileType, myFile.getVirtualFile().getFileType());
|
||||
return myFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+17
-5
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.find;
|
||||
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
@@ -8,10 +23,7 @@ public class FindManagerTestUtils {
|
||||
runFindInCommentsAndLiterals(findManager, findModel, text, "java");
|
||||
}
|
||||
|
||||
static void runFindInCommentsAndLiterals(FindManager findManager,
|
||||
FindModel findModel,
|
||||
String text,
|
||||
String ext) {
|
||||
public static void runFindInCommentsAndLiterals(FindManager findManager, FindModel findModel, String text, String ext) {
|
||||
findModel.setInStringLiteralsOnly(true);
|
||||
findModel.setInCommentsOnly(false);
|
||||
runFindForwardAndBackward(findManager, findModel, text, ext);
|
||||
@@ -21,7 +33,7 @@ public class FindManagerTestUtils {
|
||||
runFindForwardAndBackward(findManager, findModel, text, ext);
|
||||
}
|
||||
|
||||
static void runFindForwardAndBackward(FindManager findManager, FindModel findModel, String text) {
|
||||
public static void runFindForwardAndBackward(FindManager findManager, FindModel findModel, String text) {
|
||||
runFindForwardAndBackward(findManager, findModel, text, "java");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.find.FindManager;
|
||||
import com.intellij.find.FindManagerTestUtils;
|
||||
import com.intellij.find.FindModel;
|
||||
|
||||
public class GrFindManagerTest extends DaemonAnalyzerTestCase {
|
||||
private FindManager myFindManager;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFindManager = FindManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFindManager = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testFindInJavaDocs() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
String text = "/** done done done */";
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "groovy");
|
||||
}
|
||||
|
||||
public void testFindInLiteralToSkipQuotes() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("^done$");
|
||||
findModel.setRegularExpressions(true);
|
||||
findModel.setInStringLiteralsOnly(true);
|
||||
findModel.setInCommentsOnly(false);
|
||||
String text = "def n = \"\"\"done\"\"\"\n def n = /done/\n def n = \"done\"\n def n = \"done2\"";
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "groovy");
|
||||
}
|
||||
|
||||
public void testFindInShellCommentsOfGroovy() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
findModel.setWholeWordsOnly(true);
|
||||
findModel.setInCommentsOnly(true);
|
||||
String text = "#! done done done\n";
|
||||
FindManagerTestUtils.runFindForwardAndBackward(myFindManager, findModel, text, "groovy");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user