GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — first test with conflict output · zaslight/java-diff-utils@8d38e10

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java-diff-utils/src/test/java/com/github/difflib/patch
    • PatchTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java-diff-utils/src/test/java/com/github/difflib/patch/PatchTest.java‎

Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/patch/PatchTest.java
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.junit.jupiter.api.Test;
1515

1616
import com.github.difflib.DiffUtils;
17+
import java.util.ArrayList;
1718

1819
public class PatchTest {
1920

@@ -78,4 +79,48 @@ public void testPatch_Serializable() throws IOException, ClassNotFoundException
7879
}
7980

8081
}
82+
83+
@Test
84+
public void testPatch_Change_withExceptionProcessor() {
85+
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
86+
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
87+
88+
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to);
89+
90+
changeTest_from.set(2, "CDC");
91+
92+
patch.withConflictOutput(new ConflictOutput<String>() {
93+
@Override
94+
public void processConflict(VerifyChunk verifyChunk, AbstractDelta<String> delta, List<String> result) throws PatchFailedException {
95+
if (result.size() > delta.getSource().getPosition()) {
96+
List<String> orgData = new ArrayList<>();
97+
98+
for (int i = 0; i < delta.getSource().size(); i++) {
99+
orgData.add(result.get(delta.getSource().getPosition()));
100+
result.remove(delta.getSource().getPosition());
101+
}
102+
103+
orgData.add(0, "<<<<<< HEAD");
104+
orgData.add("======");
105+
orgData.addAll(delta.getSource().getLines());
106+
orgData.add(">>>>>>> PATCH");
107+
108+
result.addAll(delta.getSource().getPosition(), orgData);
109+
110+
} else {
111+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
112+
}
113+
}
114+
});
115+
116+
try {
117+
List<String> data = DiffUtils.patch(changeTest_from, patch);
118+
assertEquals(9, data.size());
119+
120+
assertEquals(Arrays.asList("aaa", "<<<<<< HEAD", "bbb", "CDC", "======", "bbb", "ccc", ">>>>>>> PATCH", "ddd"), data);
121+
122+
} catch (PatchFailedException e) {
123+
fail(e.getMessage());
124+
}
125+
}
81126
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.