Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork215
Fix: Ensure equalities processed via new processEqualities hook (Fixes #219)#224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+128 −2
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
38 changes: 36 additions & 2 deletionsjava-diff-utils/src/main/java/com/github/difflib/text/DiffRowGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletionsjava-diff-utils/src/test/java/com/github/difflib/text/DiffRowGeneratorEqualitiesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package com.github.difflib.text; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
| public class DiffRowGeneratorEqualitiesTest { | ||
| @Test | ||
| public void testDefaultEqualityProcessingLeavesTextUnchanged() { | ||
| DiffRowGenerator generator = | ||
| DiffRowGenerator.create().showInlineDiffs(false).build(); | ||
| List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("hello world"), Arrays.asList("hello world")); | ||
| assertEquals(1, rows.size()); | ||
| assertEquals("hello world", rows.get(0).getOldLine()); | ||
| assertEquals("hello world", rows.get(0).getNewLine()); | ||
| assertEquals(DiffRow.Tag.EQUAL, rows.get(0).getTag()); | ||
| } | ||
| @Test | ||
| public void testCustomEqualityProcessingIsApplied() { | ||
| DiffRowGenerator generator = DiffRowGenerator.create() | ||
| .showInlineDiffs(false) | ||
| .processEqualities(text -> "[" + text + "]") | ||
| .build(); | ||
| List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("A", "B"), Arrays.asList("A", "B")); | ||
| assertEquals(2, rows.size()); | ||
| assertEquals("[A]", rows.get(0).getOldLine()); | ||
| assertEquals("[B]", rows.get(1).getOldLine()); | ||
| } | ||
| /** | ||
| * Verifies that processEqualities can be used to HTML-escape unchanged | ||
| * lines while still working together with the default HTML-oriented | ||
| * lineNormalizer. | ||
| */ | ||
| @Test | ||
| public void testHtmlEscapingEqualitiesWorksWithDefaultNormalizer() { | ||
| DiffRowGenerator generator = DiffRowGenerator.create() | ||
| .showInlineDiffs(true) | ||
| .inlineDiffByWord(true) | ||
| .processEqualities(s -> s.replace("<", "<").replace(">", ">")) | ||
| .build(); | ||
| // both lines are equal -> Tag.EQUAL, processEqualities is invoked | ||
| List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("hello <world>"), Arrays.asList("hello <world>")); | ||
| DiffRow row = rows.get(0); | ||
| assertTrue(row.getOldLine().contains("<world>")); | ||
| assertTrue(row.getNewLine().contains("<world>")); | ||
| } | ||
| /** | ||
| * Ensures equalities are processed while inline diff markup is still | ||
| * present somewhere in the line. | ||
| */ | ||
| @Test | ||
| public void testEqualitiesProcessedButInlineDiffStillPresent() { | ||
| DiffRowGenerator generator = DiffRowGenerator.create() | ||
| .showInlineDiffs(true) | ||
| .inlineDiffByWord(true) | ||
| .processEqualities(s -> "(" + s + ")") | ||
| .build(); | ||
| List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("hello world"), Arrays.asList("hello there")); | ||
| DiffRow row = rows.get(0); | ||
| System.out.println("OLD = " + row.getOldLine()); | ||
| System.out.println("NEW = " + row.getNewLine()); | ||
| // Row must be CHANGE | ||
| assertEquals(DiffRow.Tag.CHANGE, row.getTag()); | ||
| // Inline diff markup must appear | ||
| assertTrue( | ||
| row.getOldLine().contains("span") || row.getNewLine().contains("span"), | ||
| "Expected inline <span> diff markup in old or new line"); | ||
| // Equalities inside CHANGE row must NOT be wrapped by processEqualities | ||
| // Option 3 does NOT modify inline equalities | ||
| assertTrue(row.getOldLine().startsWith("hello "), "Equal (unchanged) inline segment should remain unchanged"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.