mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
2 Basic Find tests
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
--- FIND MODEL ---
|
||||
myStringToFind =a
|
||||
myStringToReplace =
|
||||
isReplaceState =false
|
||||
isWholeWordsOnly =false
|
||||
isInStringLiterals =false
|
||||
isInComments =false
|
||||
isFromCursor =true
|
||||
isForward =true
|
||||
isGlobal =true
|
||||
isRegularExpressions =false
|
||||
isCaseSensitive =false
|
||||
isMultipleFiles =false
|
||||
isPromptOnReplace =true
|
||||
isReplaceAll =false
|
||||
isOpenNewTab =false
|
||||
isOpenInNewTabEnabled =false
|
||||
isOpenNewTabVisible =false
|
||||
isProjectScope =true
|
||||
directoryName =null
|
||||
isWithSubdirectories =true
|
||||
fileFilter =null
|
||||
moduleName =null
|
||||
customScopeName =null
|
||||
|
||||
--
|
||||
|
||||
[[<a>]]b
|
||||
--
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,null,0,ROUNDED_BOX,java.awt.Color[r=0,g=0,b=0],null]
|
||||
------------
|
||||
@@ -0,0 +1,101 @@
|
||||
--- FIND MODEL ---
|
||||
myStringToFind =a
|
||||
myStringToReplace =
|
||||
isReplaceState =false
|
||||
isWholeWordsOnly =false
|
||||
isInStringLiterals =false
|
||||
isInComments =false
|
||||
isFromCursor =true
|
||||
isForward =true
|
||||
isGlobal =true
|
||||
isRegularExpressions =false
|
||||
isCaseSensitive =false
|
||||
isMultipleFiles =false
|
||||
isPromptOnReplace =true
|
||||
isReplaceAll =false
|
||||
isOpenNewTab =false
|
||||
isOpenInNewTabEnabled =false
|
||||
isOpenNewTabVisible =false
|
||||
isProjectScope =true
|
||||
directoryName =null
|
||||
isWithSubdirectories =true
|
||||
fileFilter =null
|
||||
moduleName =null
|
||||
customScopeName =null
|
||||
|
||||
--
|
||||
|
||||
[[<a>]]
|
||||
[a]b
|
||||
--
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,null,0,ROUNDED_BOX,java.awt.Color[r=0,g=0,b=0],null]
|
||||
RangeHighlighter: (2,3); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
------------
|
||||
--- FIND MODEL ---
|
||||
myStringToFind =ab
|
||||
myStringToReplace =
|
||||
isReplaceState =false
|
||||
isWholeWordsOnly =false
|
||||
isInStringLiterals =false
|
||||
isInComments =false
|
||||
isFromCursor =true
|
||||
isForward =true
|
||||
isGlobal =true
|
||||
isRegularExpressions =false
|
||||
isCaseSensitive =false
|
||||
isMultipleFiles =false
|
||||
isPromptOnReplace =true
|
||||
isReplaceAll =false
|
||||
isOpenNewTab =false
|
||||
isOpenInNewTabEnabled =false
|
||||
isOpenNewTabVisible =false
|
||||
isProjectScope =true
|
||||
directoryName =null
|
||||
isWithSubdirectories =true
|
||||
fileFilter =null
|
||||
moduleName =null
|
||||
customScopeName =null
|
||||
|
||||
--
|
||||
|
||||
a
|
||||
[[<ab>]]
|
||||
--
|
||||
RangeHighlighter: (2,4); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
RangeHighlighter: (2,4); layer:5999; tooltip: null : [null,null,0,ROUNDED_BOX,java.awt.Color[r=0,g=0,b=0],null]
|
||||
------------
|
||||
--- FIND MODEL ---
|
||||
myStringToFind =a
|
||||
myStringToReplace =
|
||||
isReplaceState =false
|
||||
isWholeWordsOnly =false
|
||||
isInStringLiterals =false
|
||||
isInComments =false
|
||||
isFromCursor =true
|
||||
isForward =true
|
||||
isGlobal =true
|
||||
isRegularExpressions =false
|
||||
isCaseSensitive =false
|
||||
isMultipleFiles =false
|
||||
isPromptOnReplace =true
|
||||
isReplaceAll =false
|
||||
isOpenNewTab =false
|
||||
isOpenInNewTabEnabled =false
|
||||
isOpenNewTabVisible =false
|
||||
isProjectScope =true
|
||||
directoryName =null
|
||||
isWithSubdirectories =true
|
||||
fileFilter =null
|
||||
moduleName =null
|
||||
customScopeName =null
|
||||
|
||||
--
|
||||
|
||||
[[<a>]]
|
||||
[a]b
|
||||
--
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
RangeHighlighter: (0,1); layer:5999; tooltip: null : [null,null,0,ROUNDED_BOX,java.awt.Color[r=0,g=0,b=0],null]
|
||||
RangeHighlighter: (2,3); layer:5999; tooltip: null : [null,java.awt.Color[r=255,g=255,b=0],0,BOXED,null,java.awt.Color[r=0,g=255,b=0]]
|
||||
------------
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.intellij.find;
|
||||
|
||||
import com.intellij.find.impl.FindResultImpl;
|
||||
import com.intellij.find.impl.livePreview.LivePreview;
|
||||
import com.intellij.find.impl.livePreview.LivePreviewController;
|
||||
import com.intellij.find.impl.livePreview.SearchResults;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class FindInEditorTest extends LightCodeInsightTestCase {
|
||||
|
||||
@@ -29,6 +29,8 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
||||
private SearchResults mySearchResults;
|
||||
private FindModel myFindModel;
|
||||
|
||||
private ByteArrayOutputStream myOutputStream;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -40,6 +42,9 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
||||
myLivePreviewController.updateInBackground(myFindModel, true);
|
||||
}
|
||||
});
|
||||
|
||||
myOutputStream = new ByteArrayOutputStream();
|
||||
LivePreview.ourTestOutput = new PrintStream(myOutputStream);
|
||||
}
|
||||
|
||||
private void initFind() {
|
||||
@@ -48,12 +53,24 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
||||
myLivePreviewController.on();
|
||||
}
|
||||
|
||||
public void test1() throws Exception {
|
||||
configureFromFileText("file.txt", "abc");
|
||||
public void testBasicFind() throws Exception {
|
||||
configureFromFileText("file.txt", "ab");
|
||||
initFind();
|
||||
myFindModel.setStringToFind("a");
|
||||
type("a");
|
||||
List<FindResult> occurrences = mySearchResults.getOccurrences();
|
||||
assertContainsElements(occurrences, new FindResultImpl(0, 1));
|
||||
checkResults();
|
||||
}
|
||||
|
||||
public void testEmacsLikeFallback() throws Exception {
|
||||
configureFromFileText("file.txt", "a\nab");
|
||||
initFind();
|
||||
myFindModel.setStringToFind("a");
|
||||
myFindModel.setStringToFind("ab");
|
||||
myFindModel.setStringToFind("a");
|
||||
checkResults();
|
||||
}
|
||||
|
||||
private void checkResults() {
|
||||
String name = getTestName(false);
|
||||
assertSameLinesWithFile(getTestDataPath() + "/find/findInEditor/" + name + ".gold", myOutputStream.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,10 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
updateExcludeStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFinished() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editorChanged(SearchResults sr, Editor oldEditor) { }
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.find.FindModel;
|
||||
import com.intellij.find.FindResult;
|
||||
import com.intellij.ide.IdeTooltipManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
@@ -37,20 +38,21 @@ import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.ui.popup.BalloonBuilder;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.PositionTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LivePreview extends DocumentAdapter implements ReplacementView.Delegate, SearchResults.SearchResultsListener,
|
||||
SelectionListener {
|
||||
@@ -68,6 +70,8 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
private static final Object YES = new Object();
|
||||
private static final Key<Object> SEARCH_MARKER = Key.create("LivePreview.SEARCH_MARKER");
|
||||
|
||||
public static PrintStream ourTestOutput;
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionEvent e) {
|
||||
updateInSelectionHighlighters();
|
||||
@@ -126,6 +130,65 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpState() {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
dumpEditorMarkupAndSelection(ourTestOutput);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpEditorMarkupAndSelection(PrintStream dumpStream) {
|
||||
dumpStream.println(mySearchResults.getFindModel());
|
||||
dumpStream.println("--");
|
||||
|
||||
Editor editor = mySearchResults.getEditor();
|
||||
|
||||
RangeHighlighter[] highlighters = editor.getMarkupModel().getAllHighlighters();
|
||||
List<Pair<Integer, Character>> ranges = new ArrayList<Pair<Integer, Character>>();
|
||||
for (RangeHighlighter highlighter : highlighters) {
|
||||
ranges.add(new Pair<Integer, Character>(highlighter.getStartOffset(), '['));
|
||||
ranges.add(new Pair<Integer, Character>(highlighter.getEndOffset(), ']'));
|
||||
}
|
||||
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
|
||||
ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionStart(), '<'));
|
||||
ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionEnd(), '>'));
|
||||
|
||||
ranges.add(new Pair<Integer, Character>(-1, '\n'));
|
||||
ranges.add(new Pair<Integer, Character>(editor.getDocument().getTextLength()+1, '\n'));
|
||||
ContainerUtil.sort(ranges, new Comparator<Pair<Integer, Character>>() {
|
||||
@Override
|
||||
public int compare(Pair<Integer, Character> pair, Pair<Integer, Character> pair2) {
|
||||
int res = pair.first - pair2.first;
|
||||
if (res == 0) {
|
||||
|
||||
Character c1 = pair.second;
|
||||
Character c2 = pair2.second;
|
||||
if (c1 == '<' && c2 == '[') {
|
||||
return 1;
|
||||
} else if (c1 == '[' && c2 == '<') {
|
||||
return -1;
|
||||
}
|
||||
return c1.compareTo(c2);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
});
|
||||
|
||||
Document document = editor.getDocument();
|
||||
for (int i = 0; i < ranges.size()-1; ++i) {
|
||||
Pair<Integer, Character> pair = ranges.get(i);
|
||||
Pair<Integer, Character> pair1 = ranges.get(i + 1);
|
||||
dumpStream.print(pair.second + document.getText(TextRange.create(Math.max(pair.first, 0), Math.min(pair1.first, document.getTextLength() ))));
|
||||
}
|
||||
dumpStream.println("\n--");
|
||||
|
||||
for (RangeHighlighter highlighter : highlighters) {
|
||||
dumpStream.println(highlighter + " : " + highlighter.getTextAttributes());
|
||||
}
|
||||
dumpStream.println("------------");
|
||||
}
|
||||
|
||||
private void clearUnusedHightlighters() {
|
||||
Set<RangeHighlighter> unused = new com.intellij.util.containers.HashSet<RangeHighlighter>();
|
||||
for (RangeHighlighter highlighter : myHighlighters) {
|
||||
@@ -150,6 +213,11 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
updateCursorHighlighting(toChangeSelection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFinished() {
|
||||
dumpState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editorChanged(SearchResults sr, Editor oldEditor) {
|
||||
removeFromEditor();
|
||||
|
||||
@@ -125,6 +125,11 @@ public class LivePreviewController implements LivePreview.Delegate, FindUtil.Rep
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFinished() {
|
||||
|
||||
}
|
||||
|
||||
public void moveCursor(SearchResults.Direction direction) {
|
||||
if (direction == SearchResults.Direction.UP) {
|
||||
mySearchResults.prevOccurrence();
|
||||
|
||||
@@ -152,6 +152,7 @@ public class SearchResults implements DocumentListener {
|
||||
void editorChanged(SearchResults sr, Editor oldEditor);
|
||||
void cursorMoved(boolean toChangeSelection);
|
||||
|
||||
void updateFinished();
|
||||
}
|
||||
public void addListener(SearchResultsListener srl) {
|
||||
myListeners.add(srl);
|
||||
@@ -356,6 +357,13 @@ public class SearchResults implements DocumentListener {
|
||||
if (oldCursorRange == null || myCursor == null || !myCursor.equals(oldCursorRange)) {
|
||||
notifyCursorMoved(toChangeSelection);
|
||||
}
|
||||
dumpIfNeeded();
|
||||
}
|
||||
|
||||
private void dumpIfNeeded() {
|
||||
for (SearchResultsListener listener : myListeners) {
|
||||
listener.updateFinished();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExcluded() {
|
||||
|
||||
Reference in New Issue
Block a user