aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-10-13 20:43:11 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-10-13 20:48:51 -0700
commit8ea558bd8245097a05dfa8600f765c670b0bad5e (patch)
tree94c72a0ba67ac5dc7c0049ea5c606a25d3bb40e3 /org.eclipse.jgit.test/tst/org/eclipse/jgit/diff
parentabac15e45e460af92d66f2cd9bffaf45f74da024 (diff)
downloadjgit-8ea558bd8245097a05dfa8600f765c670b0bad5e.tar.gz
jgit-8ea558bd8245097a05dfa8600f765c670b0bad5e.zip
Fix RawTextComparator reduceCommonStartEnd at empty lines
When an empty line was inserted at the beginning of the common end part of a RawText the comparator incorrectly considered it to be common, which meant the DiffAlgorithm would later not even have it be part of the region it examines. This would cause JGit to skip a line of insertion, which later confused Gerrit Code Review when it tried to match up the pre and post RawText files for a difference that had this type of insertion. Define two new unit tests to check for this insertion of a blank line condition and correct for it by removing the LF from the common region when the condition is detected. Change-Id: I2108570eb2929803b9a56f9fb9c400c758e7156b Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/diff')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
index 395fb7fed9..e18d1c4eb9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
@@ -134,6 +134,25 @@ public class RawTextTest extends TestCase {
assertEquals(new Edit(2, 3, 2, 3), e);
}
+ public void testComparatorReduceCommonStartEnd_EmptyLine()
+ throws UnsupportedEncodingException {
+ RawText a;
+ RawText b;
+ Edit e;
+
+ a = new RawText("R\n y\n".getBytes("UTF-8"));
+ b = new RawText("S\n\n y\n".getBytes("UTF-8"));
+ e = new Edit(0, 2, 0, 3);
+ e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
+ assertEquals(new Edit(0, 1, 0, 2), e);
+
+ a = new RawText("S\n\n y\n".getBytes("UTF-8"));
+ b = new RawText("R\n y\n".getBytes("UTF-8"));
+ e = new Edit(0, 3, 0, 2);
+ e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
+ assertEquals(new Edit(0, 2, 0, 1), e);
+ }
+
private static RawText t(String text) {
StringBuilder r = new StringBuilder();
for (int i = 0; i < text.length(); i++) {