summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-09-01 23:09:48 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-09-03 23:55:46 -0700
commitfe8fe13349bb46ae690cfea6d3e57bfdac2301e4 (patch)
tree8c4740ab796a0ce909d5cfbbb3cf46329cf39bd6 /org.eclipse.jgit.test
parent596c3f668b184e41b147aab6260c23189e521c09 (diff)
downloadjgit-fe8fe13349bb46ae690cfea6d3e57bfdac2301e4.tar.gz
jgit-fe8fe13349bb46ae690cfea6d3e57bfdac2301e4.zip
Add helper methods to Edit
Exposing isEmpty, getLengthA, getLengthB make it easier to examine the state of an edit and work with it from higher level code. The before and after cut routines make it easy to split an edit that contains another edit, such as to decompose a REPLACE that contains a common sequence within it. Change-Id: Id63d6476a7a6b23acb7ab237d414a0a1a7200290 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
index 6f3d21e558..598e6d2b67 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
@@ -61,6 +61,8 @@ public class EditTest extends TestCase {
assertEquals(1, e.getEndA());
assertEquals(3, e.getBeginB());
assertEquals(3, e.getEndB());
+ assertTrue("is empty", e.isEmpty());
+ assertSame(Edit.Type.EMPTY, e.getType());
}
public void testSwap() {
@@ -75,21 +77,34 @@ public class EditTest extends TestCase {
public void testType_Insert() {
final Edit e = new Edit(1, 1, 1, 2);
assertSame(Edit.Type.INSERT, e.getType());
+ assertFalse("not empty", e.isEmpty());
+ assertEquals(0, e.getLengthA());
+ assertEquals(1, e.getLengthB());
}
public void testType_Delete() {
final Edit e = new Edit(1, 2, 1, 1);
assertSame(Edit.Type.DELETE, e.getType());
+ assertFalse("not empty", e.isEmpty());
+ assertEquals(1, e.getLengthA());
+ assertEquals(0, e.getLengthB());
}
public void testType_Replace() {
final Edit e = new Edit(1, 2, 1, 4);
assertSame(Edit.Type.REPLACE, e.getType());
+ assertFalse("not empty", e.isEmpty());
+ assertEquals(1, e.getLengthA());
+ assertEquals(3, e.getLengthB());
}
public void testType_Empty() {
- assertSame(Edit.Type.EMPTY, new Edit(1, 1, 2, 2).getType());
+ final Edit e = new Edit(1, 1, 2, 2);
+ assertSame(Edit.Type.EMPTY, e.getType());
assertSame(Edit.Type.EMPTY, new Edit(1, 2).getType());
+ assertTrue("is empty", e.isEmpty());
+ assertEquals(0, e.getLengthA());
+ assertEquals(0, e.getLengthB());
}
public void testToString() {
@@ -143,4 +158,12 @@ public class EditTest extends TestCase {
e.extendB();
assertEquals(new Edit(1, 2, 1, 3), e);
}
+
+ public void testBeforeAfterCuts() {
+ final Edit whole = new Edit(1, 8, 2, 9);
+ final Edit mid = new Edit(4, 5, 3, 6);
+
+ assertEquals(new Edit(1, 4, 2, 3), whole.before(mid));
+ assertEquals(new Edit(5, 8, 6, 9), whole.after(mid));
+ }
}