Skip to content

Commit

Permalink
added unit tests findReplaceLogic#selectAndReplace
Browse files Browse the repository at this point in the history
These tests test findReplaceLogic#selectAndReplace, in particular what
happens when the search before replace results in edge-cases, like "no
result was found" or "the result was only found after wrapping".
  • Loading branch information
Wittmaxi authored and HeikoKlare committed May 6, 2024
1 parent 80adab7 commit 17e35c4
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,35 @@ public void onlySelectAndReplacesIfFindSuccessfulOnCustomTarget() {
verify((IFindReplaceTargetExtension3) mockedTarget, never()).replaceSelection(anyString(), anyBoolean());
}

@Test
public void testCanReplaceAfterWrap() {
TextViewer textViewer= setupTextViewer(LINE_STRING + lineSeparator() + LINE_STRING);
textViewer.setSelectedRange(LINE_STRING_LENGTH + lineSeparator().length(), 0);
IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(textViewer);
findReplaceLogic.activate(SearchOptions.FORWARD);
findReplaceLogic.activate(SearchOptions.WRAP);
findReplaceLogic.performSelectAndReplace(LINE_STRING, "");
assertThat(textViewer.getTextWidget().getText(), is(LINE_STRING + lineSeparator()));
findReplaceLogic.performSelectAndReplace(LINE_STRING, "");
assertThat(textViewer.getTextWidget().getText(), is(lineSeparator()));
}

@Test
public void testDontSelectAndReplaceIfFindNotSuccessful() {
String setupString= "ABCD" + lineSeparator() + LINE_STRING;
TextViewer textViewer= setupTextViewer(setupString);
textViewer.setSelectedRange(0, 4);
IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(textViewer);
findReplaceLogic.activate(SearchOptions.FORWARD);
findReplaceLogic.activate(SearchOptions.WRAP);
findReplaceLogic.performSelectAndReplace("NOTFOUND", "");
// ensure nothing was replaced
assertThat(textViewer.getTextWidget().getText(), is(setupString));
// ensure the selection was not overridden
assertThat(findReplaceLogic.getTarget().getSelection().x, is(0));
assertThat(findReplaceLogic.getTarget().getSelection().y, is(4));
}

private void expectStatusEmpty(IFindReplaceLogic findReplaceLogic) {
assertThat(findReplaceLogic.getStatus(), instanceOf(NoStatus.class));
}
Expand Down

0 comments on commit 17e35c4

Please sign in to comment.