Skip to content

Commit 0e6e1b6

Browse files
HeikoKlareCopilot
andcommitted
Find/replace: add test for whole-word availability with inactive regex support
Whole-word search and regex mode are mutually exclusive when regex is effectively active. However, activating regex mode on a target that does not support regex has no effective impact -- the option is activated but not available, so it must not restrict other options like whole-word search. This is already the correct behavior: the availability check for whole-word uses isAvailableAndActive(REGEX), which requires both availability and activation, so merely activating regex on a non-capable target leaves whole-word unaffected. A test is added to explicitly document and protect this invariant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f66c97d commit 0e6e1b6

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,19 @@ public void testWholeWordSearchAvailable() {
719719
assertFalse(isConsideredWholeWord.test(""));
720720
}
721721

722+
@Test
723+
public void testWholeWordRemainsAvailableWhenUnavailableRegexIsActivated() {
724+
IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(null);
725+
findReplaceLogic.setFindString("word");
726+
assertFalse(findReplaceLogic.isAvailable(SearchOptions.REGEX)); // null target has no regex support
727+
assertTrue(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD));
728+
729+
findReplaceLogic.activate(SearchOptions.REGEX);
730+
731+
// Activating an unavailable option has no effective impact, so whole-word must remain available
732+
assertTrue(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD));
733+
}
734+
722735
@Test
723736
public void testReplaceInScopeStaysInScope() {
724737
TextViewer textViewer= setupTextViewer(LINE_STRING + lineSeparator() + LINE_STRING + lineSeparator() + LINE_STRING);

0 commit comments

Comments
 (0)