diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java index d439cc48f1e..ad117b7ad4d 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java @@ -15,6 +15,7 @@ import static org.eclipse.ui.internal.findandreplace.FindReplaceTestUtil.waitForFocus; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -29,7 +30,10 @@ import org.eclipse.text.tests.Accessor; +import org.eclipse.jface.viewers.ISelection; + import org.eclipse.jface.text.IFindReplaceTarget; +import org.eclipse.jface.text.IMultiTextSelection; import org.eclipse.jface.text.TextViewer; import org.eclipse.ui.internal.findandreplace.FindReplaceUITest; @@ -227,6 +231,49 @@ public void testSearchTermStoredInHistoryAfterSearchBackward() { assertEquals("foo", dialog.getFindText()); } + @Test + public void testReplaceDoesNothingIfSearchStringIsEmpty() { + // The overlay refuses replace operations as long as the search string is + // empty; the document must remain unchanged. + initializeTextViewerWithFindReplaceUI("text text"); + OverlayAccess dialog= getDialog(); + dialog.setReplaceText("replacement"); + + dialog.performReplace(); + assertThat(getTextViewer().getDocument().get(), is("text text")); + + dialog.performReplaceAll(); + assertThat(getTextViewer().getDocument().get(), is("text text")); + } + + @Test + public void testSelectAllSelectsAllOccurrences() { + initializeTextViewerWithFindReplaceUI("foo bar foo bar foo"); + OverlayAccess dialog= getDialog(); + dialog.setFindText("foo"); + + dialog.pressSelectAll(); + + ISelection selection= getTextViewer().getSelection(); + assertThat(selection, is(instanceOf(IMultiTextSelection.class))); + assertEquals(3, ((IMultiTextSelection) selection).getRegions().length); + } + + @Test + public void testSearchTermStoredInHistoryAfterSelectAll() { + // Selecting all occurrences must persist the search term to history just + // like the other search operations. + initializeTextViewerWithFindReplaceUI("foo bar foo"); + OverlayAccess dialog= getDialog(); + dialog.setFindText("foo"); + dialog.pressSelectAll(); + + dialog.setFindText(""); + dialog.simulateKeyboardInteractionInFindInputField(SWT.ARROW_DOWN, false); + + assertEquals("foo", dialog.getFindText()); + } + @Test public void testSearchInSelectionButtonIsInverseOfGlobalOption() { // The searchInSelection button is the inverse of the GLOBAL option: diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java index c8fc1769901..1b0c0d70150 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java @@ -53,6 +53,8 @@ class OverlayAccess implements IFindReplaceUIAccess { private final ToolItem searchBackward; + private final ToolItem selectAll; + private final ToolItem openReplaceDialog; private HistoryTextWrapper replace; @@ -74,6 +76,7 @@ class OverlayAccess implements IFindReplaceUIAccess { inSelection= widgetExtractor.findToolItem("searchInSelection"); searchForward= widgetExtractor.findToolItem("searchForward"); searchBackward= widgetExtractor.findToolItem("searchBackward"); + selectAll= widgetExtractor.findToolItem("selectAll"); openReplaceDialog= widgetExtractor.findToolItem("replaceToggle"); extractReplaceWidgets(); } @@ -227,6 +230,10 @@ public void selectFindHistoryEntry(int index) { } } + public void pressSelectAll() { + selectAll.notifyListeners(SWT.Selection, null); + } + public void pressSearch(boolean forward) { if (forward) { searchForward.notifyListeners(SWT.Selection, null);