From 0e6e1b6552c8ac2be872f5c1928713c210045a69 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 10 Jul 2026 10:25:10 +0200 Subject: [PATCH] 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> --- .../findandreplace/FindReplaceLogicTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java index 94b1e805d25..463b81d9f6c 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java @@ -719,6 +719,19 @@ public void testWholeWordSearchAvailable() { assertFalse(isConsideredWholeWord.test("")); } + @Test + public void testWholeWordRemainsAvailableWhenUnavailableRegexIsActivated() { + IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(null); + findReplaceLogic.setFindString("word"); + assertFalse(findReplaceLogic.isAvailable(SearchOptions.REGEX)); // null target has no regex support + assertTrue(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD)); + + findReplaceLogic.activate(SearchOptions.REGEX); + + // Activating an unavailable option has no effective impact, so whole-word must remain available + assertTrue(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD)); + } + @Test public void testReplaceInScopeStaysInScope() { TextViewer textViewer= setupTextViewer(LINE_STRING + lineSeparator() + LINE_STRING + lineSeparator() + LINE_STRING);