diff options
author | Kalyan Prasad Tatavarthi | 2018-07-30 09:45:56 +0000 |
---|---|---|
committer | Kalyan Prasad Tatavarthi | 2018-07-30 09:48:18 +0000 |
commit | c8c61ceaae40fb7480be6c7f29082aea579b47b5 (patch) | |
tree | 8c613595c7605f0ae1c081e7b0f23aa75141f09b /org.eclipse.search.tests | |
parent | e18255b8f790682a2a9e9778cfcbf52de4f9c859 (diff) | |
download | eclipse.platform.text-c8c61ceaae40fb7480be6c7f29082aea579b47b5.tar.gz eclipse.platform.text-c8c61ceaae40fb7480be6c7f29082aea579b47b5.tar.xz eclipse.platform.text-c8c61ceaae40fb7480be6c7f29082aea579b47b5.zip |
Bug 109481 - [find/replace] replace doesn't work when using a regex withI20180730-2240I20180730-2000I20180730-0800
a lookahead or boundary matchers :- Reverting Changes as a result of
Bug 537377
Change-Id: I975d326e67f650bc2dddac6948775b3bb3fbdf5a
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
Diffstat (limited to 'org.eclipse.search.tests')
-rw-r--r-- | org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java | 57 |
1 files changed, 1 insertions, 56 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java index 675013fbb19..4496d61fb60 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,16 +9,13 @@ * IBM Corporation - initial API and implementation * Christian Walther (Indel AG) - Bug 399094, 402009: Add whole word option to file search * Terry Parker <tparker@google.com> (Google Inc.) - Bug 441016 - Speed up text search by parallelizing it using JobGroups - * Florian Ingerl <imelflorianingerl@gmail.com> - Bug 109481 - [find/replace] replace doesn't work when using a regex with a lookahead or boundary matchers *******************************************************************************/ package org.eclipse.search.tests.filesearch; import static org.junit.Assert.assertEquals; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Scanner; import java.util.regex.Pattern; import org.junit.After; @@ -27,8 +24,6 @@ import org.junit.ClassRule; import org.junit.Test; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -43,15 +38,10 @@ import org.eclipse.search.core.text.TextSearchRequestor; import org.eclipse.search.core.text.TextSearchScope; import org.eclipse.search.internal.core.text.PatternConstructor; import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.text.FileSearchQuery; -import org.eclipse.search.internal.ui.text.FileSearchResult; -import org.eclipse.search.internal.ui.text.ReplaceRefactoring; import org.eclipse.search.tests.ResourceHelper; import org.eclipse.search.tests.SearchTestPlugin; import org.eclipse.search.ui.text.FileTextSearchScope; -import org.eclipse.ltk.core.refactoring.Change; - public class FileSearchTests { private static class TestResult { @@ -533,50 +523,5 @@ public class FileSearchTests { assertEquals("Number of results in file", expectedCount, k); } - @Test - public void testReplaceWithLookarounds() throws CoreException, IOException { - IFolder folder= ResourceHelper.createFolder(fProject.getFolder("folder1")); - IFile file1= ResourceHelper.createFile(folder, "file1.txt", "1<2<3<4"); - IFile file2= ResourceHelper.createFile(folder, "file2.txt", "4<5<6<7"); - - FileSearchResult searchResult= performSearch(new String[] { "*.txt" }, "(?<=(\\d)\\<)\\d(?=\\<(\\d))"); - performReplace(searchResult, "$0=($1+$2)/2"); - - assertFileContent(file1, "1<2=(1+3)/2<3=(2+4)/2<4"); - assertFileContent(file2, "4<5=(4+6)/2<6=(5+7)/2<7"); - } - - @Test - public void testReplaceRetainCase() throws CoreException, IOException { - IFolder folder= ResourceHelper.createFolder(fProject.getFolder("folder1")); - IFile file1= ResourceHelper.createFile(folder, "file1.txt", "FOO"); - - FileSearchResult searchResult= performSearch(new String[] { "*.txt" }, "FOO"); - performReplace(searchResult, "xyz\\Cbar\\Cfar"); - - assertFileContent(file1, "xyzBARFAR"); - } - - private FileSearchResult performSearch(String[] fileNamePatterns, String pattern) { - FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] { fProject }, fileNamePatterns, false); - FileSearchQuery query= new FileSearchQuery(pattern, true, true, scope); - query.run(null); - return (FileSearchResult) query.getSearchResult(); - } - private void performReplace(FileSearchResult searchResult, String replacementText) throws OperationCanceledException, CoreException { - ReplaceRefactoring refactoring= new ReplaceRefactoring(searchResult, null); - refactoring.setReplaceString(replacementText); - refactoring.checkInitialConditions(null); - refactoring.checkFinalConditions(null); - Change change= refactoring.createChange(null); - change.perform(new NullProgressMonitor()); - } - - private void assertFileContent(IFile file, String expected) throws CoreException { - try (Scanner scanner= new Scanner(file.getContents())) { - scanner.useDelimiter("\\A"); - assertEquals(expected, scanner.next()); - } - } } |