Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d38e10

Browse files
committed
first test with conflict output
1 parent8880ec5 commit8d38e10

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
importorg.junit.jupiter.api.Test;
1515

1616
importcom.github.difflib.DiffUtils;
17+
importjava.util.ArrayList;
1718

1819
publicclassPatchTest {
1920

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

8081
}
82+
83+
@Test
84+
publicvoidtestPatch_Change_withExceptionProcessor() {
85+
finalList<String>changeTest_from =Arrays.asList("aaa","bbb","ccc","ddd");
86+
finalList<String>changeTest_to =Arrays.asList("aaa","bxb","cxc","ddd");
87+
88+
finalPatch<String>patch =DiffUtils.diff(changeTest_from,changeTest_to);
89+
90+
changeTest_from.set(2,"CDC");
91+
92+
patch.withConflictOutput(newConflictOutput<String>() {
93+
@Override
94+
publicvoidprocessConflict(VerifyChunkverifyChunk,AbstractDelta<String>delta,List<String>result)throwsPatchFailedException {
95+
if (result.size() >delta.getSource().getPosition()) {
96+
List<String>orgData =newArrayList<>();
97+
98+
for (inti =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+
thrownewUnsupportedOperationException("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 (PatchFailedExceptione) {
123+
fail(e.getMessage());
124+
}
125+
}
81126
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp