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 @@ -285,6 +285,12 @@ private int transformDeltaIntoDiffRow(
}

switch (delta.getType()) {
case EQUAL:
for (String line : orig.getLines()) {
String processed = processEqualities(line);
diffRows.add(buildDiffRow(Tag.EQUAL, processed, processed));
}
break;
case INSERT:
for (String line : rev.getLines()) {
diffRows.add(buildDiffRow(Tag.INSERT, "", line));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.Patch;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -89,4 +91,34 @@ public void testEqualitiesProcessedButInlineDiffStillPresent() {
// Option 3 does NOT modify inline equalities
assertTrue(row.getOldLine().startsWith("hello "), "Equal (unchanged) inline segment should remain unchanged");
}

@Test
public void testEqualDeltaIsReportedAsEqualWithoutInlineDiffs() {
List<String> original = Arrays.asList("same", "before");
List<String> revised = Arrays.asList("same", "after");
Patch<String> patch = DiffUtils.diff(original, revised, true);

List<DiffRow> rows =
DiffRowGenerator.create().showInlineDiffs(false).build().generateDiffRows(original, patch);

assertEquals(2, rows.size());
assertEquals(DiffRow.Tag.EQUAL, rows.get(0).getTag());
assertEquals("same", rows.get(0).getOldLine());
assertEquals(DiffRow.Tag.CHANGE, rows.get(1).getTag());
}

@Test
public void testEqualDeltaIsReportedAsEqualWithInlineDiffs() {
List<String> original = Arrays.asList("same", "before");
List<String> revised = Arrays.asList("same", "after");
Patch<String> patch = DiffUtils.diff(original, revised, true);

List<DiffRow> rows =
DiffRowGenerator.create().showInlineDiffs(true).build().generateDiffRows(original, patch);

assertEquals(2, rows.size());
assertEquals(DiffRow.Tag.EQUAL, rows.get(0).getTag());
assertEquals("same", rows.get(0).getNewLine());
assertEquals(DiffRow.Tag.CHANGE, rows.get(1).getTag());
}
}