Skip to content
Open
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 @@ -113,7 +113,7 @@ public VerifyChunk verifyChunk(List<T> target, int fuzz, int position) throws Pa
int lastIndex = size() - fuzz;
int last = position + size() - 1;

if (position + fuzz > target.size() || last - fuzz > target.size()) {
if (position + fuzz > target.size() || last - fuzz >= target.size()) {
return VerifyChunk.POSITION_OUT_OF_TARGET;
}
for (int i = startIndex; i < lastIndex; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ void verifyChunk() throws PatchFailedException {
VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET, chunk.verifyChunk(toCharList("prefix suffix"), 1, 7));
}

@Test
void verifyChunkAtTheEndOfTheTarget() throws PatchFailedException {
// chunk covers target indices 7..10, so it needs a target of at least 11
Chunk<Character> chunk = new Chunk<>(7, toCharList("test"));

assertEquals(VerifyChunk.OK, chunk.verifyChunk(toCharList("prefix test"), 0, 7));
assertEquals(VerifyChunk.POSITION_OUT_OF_TARGET, chunk.verifyChunk(toCharList("prefix tes"), 0, 7));
assertEquals(VerifyChunk.POSITION_OUT_OF_TARGET, chunk.verifyChunk(toCharList("prefix te"), 0, 7));
}

private List<Character> toCharList(String str) {
return str.chars().mapToObj(x -> (char) x).collect(Collectors.toList());
}
Expand Down
Loading