← 输入框|github.com|刷新
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public List<T> applyFuzzy(List<T> target, int maxFuzz) throws PatchFailedExcepti
int patchPosition = findPositionFuzzy(ctx, delta);
if (0 <= patchPosition) {
delta.applyFuzzyToAt(ctx.result, ctx.currentFuzz, patchPosition);
lastPatchDelta = patchPosition - delta.getSource().getPosition();
lastPatchDelta = patchPosition
- delta.getSource().getPosition()
+ delta.getTarget().size()
- delta.getSource().size();
ctx.lastPatchEnd = delta.getSource().last() + lastPatchDelta;
} else {
conflictOutput.processConflict(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET, delta, ctx.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
*/
public class PatchWithMyerDiffTest {

@Test
public void fuzzyApplyAfterShrinkingChange() throws PatchFailedException {
List<String> source = Arrays.asList("a", "b", "c", "d", "e");
List<String> target = Arrays.asList("x", "d", "y");
Patch<String> patch = DiffUtils.diff(source, target);
assertEquals(target, patch.applyFuzzy(source, 0));
assertEquals(
Arrays.asList("prefix", "x", "d", "y"),
patch.applyFuzzy(Arrays.asList("prefix", "a", "b", "c", "d", "e"), 0));
}

@Test
public void fuzzyApplyDoesNotMatchNewlyInsertedLines() throws PatchFailedException {
Patch<String> patch = new Patch<>();
patch.addDelta(new ChangeDelta<>(new Chunk<>(0, Arrays.asList("a")), new Chunk<>(0, Arrays.asList("x", "c"))));
patch.addDelta(new ChangeDelta<>(new Chunk<>(2, Arrays.asList("c")), new Chunk<>(3, Arrays.asList("y"))));
assertEquals(Arrays.asList("x", "c", "b", "y"), patch.applyFuzzy(Arrays.asList("a", "b", "c"), 0));
}

@Test
public void testPatch_Change_withExceptionProcessor() {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
Expand Down
Loading