diff options
author | Tomasz Zarna | 2009-02-16 14:08:18 +0000 |
---|---|---|
committer | Tomasz Zarna | 2009-02-16 14:08:18 +0000 |
commit | 2319b0ec89e225ba7a08fe3454c4fb25ba36109a (patch) | |
tree | 9d89473147aa75d86751bb2a2876ca744ffd0e13 /tests/org.eclipse.compare.tests | |
parent | eca2abcdee727582362b9a8012ae91d1690376ce (diff) | |
download | eclipse.platform.team-2319b0ec89e225ba7a08fe3454c4fb25ba36109a.tar.gz eclipse.platform.team-2319b0ec89e225ba7a08fe3454c4fb25ba36109a.tar.xz eclipse.platform.team-2319b0ec89e225ba7a08fe3454c4fb25ba36109a.zip |
bug 183238: [Apply Patch] API to get IHunks from IFilePatch and select which of them to apply
Diffstat (limited to 'tests/org.eclipse.compare.tests')
3 files changed, 85 insertions, 2 deletions
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt b/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt new file mode 100644 index 000000000..135627bcc --- /dev/null +++ b/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt @@ -0,0 +1,24 @@ +[a] +[b] +[c] +[c1] +[c2] +[d] +[e] +[f] +[g] +[h] +[i1] +[j] +[k] +[l] +[m] +[n] +[p] +[q] +[r] +[s] +[t] +[u] +[v] +[w] diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt b/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt new file mode 100644 index 000000000..fe0831c4a --- /dev/null +++ b/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt @@ -0,0 +1,25 @@ +--- old.txt 2005-05-07 00:16:20.000000000 +0200 ++++ new.txt 2005-05-07 00:16:32.000000000 +0200 +@@ -3,2 +3,4 @@ + [c] ++[c1] ++[c2] + [d] +@@ -8,3 +10,3 @@ + [h] +-[i] ++[i1] + [j] +@@ -14,3 +16,2 @@ + [n] +-[o] + [p] +@@ -19,2 +20,3 @@ + [s] ++[s1] + [t] +@@ -29,2 +32,3 @@ + [yy] ++[xx] + [yy] +
\ No newline at end of file diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java index d86d20546..8791ef8f6 100644 --- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -46,6 +46,8 @@ import org.eclipse.compare.internal.patch.WorkspacePatcher; import org.eclipse.compare.patch.ApplyPatchOperation; import org.eclipse.compare.patch.IFilePatch; import org.eclipse.compare.patch.IFilePatchResult; +import org.eclipse.compare.patch.IHunk; +import org.eclipse.compare.patch.IHunkFilter; import org.eclipse.compare.patch.PatchConfiguration; import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.ResourcesPlugin; @@ -53,6 +55,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; @@ -189,7 +192,38 @@ public class PatchTest extends TestCase { public void testContext3Patch() throws CoreException, IOException { patch("context.txt", "patch_context3.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - + + public void testHunkFilter() throws CoreException, IOException { + IStorage patchStorage = new StringStorage("patch_hunkFilter.txt"); + IStorage expStorage = new StringStorage("context.txt"); + IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage); + assertEquals(1, patches.length); + IHunk[] hunks = patches[0].getHunks(); + assertEquals(5, hunks.length); + PatchConfiguration pc = new PatchConfiguration(); + final IHunk toFilterOut = hunks[3]; + pc.addHunkFilter(new IHunkFilter() { + public boolean select(IHunk hunk) { + return hunk != toFilterOut; + } + }); + IFilePatchResult result = patches[0].apply(expStorage, pc, + new NullProgressMonitor()); + IHunk[] rejects = result.getRejects(); + assertEquals(2, rejects.length); + boolean aFiltered = pc.getHunkFilters()[0].select(rejects[0]); + boolean bFiltered = pc.getHunkFilters()[0].select(rejects[1]); + assertTrue((aFiltered && !bFiltered) || (!aFiltered && bFiltered)); + + InputStream actual = result.getPatchedContents(); + + LineReader lr = new LineReader(getReader("exp_hunkFilter.txt")); + List inLines = lr.readLines(); + String expected = LineReader.createString(false, inLines); + + assertEquals(expected, asString(actual)); + } + public void testContext3PatchWithHeader() throws CoreException, IOException { patch("context.txt", "patch_context3_header.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ IStorage patchStorage = new StringStorage("patch_context3_header.txt"); |