diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-09-02 11:28:33 -0400 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2010-09-02 11:28:33 -0400 |
commit | 097406ba5e5e8de229e71d2d1fe8a9991d3c3cdf (patch) | |
tree | dc76b64adf92e85978a1d057c86e9bacafebcd73 /org.eclipse.jgit.test | |
parent | df0c9309c5518b173f5e836344515e9cf7b7fe5b (diff) | |
parent | df8adefe86934cbd25982527780b5eed9a1feae1 (diff) | |
download | jgit-097406ba5e5e8de229e71d2d1fe8a9991d3c3cdf.tar.gz jgit-097406ba5e5e8de229e71d2d1fe8a9991d3c3cdf.zip |
Merge "Correct diff header formatting"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java index 92d4fa114f..d7a10e4b15 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java @@ -77,6 +77,76 @@ public class DiffFormatterTest extends RepositoryTestCase { df.setAbbreviationLength(8); } + public void testCreateFileHeader_Add() throws Exception { + ObjectId adId = blob("a\nd\n"); + DiffEntry ent = DiffEntry.add("FOO", adId); + FileHeader fh = df.createFileHeader(ent); + + String diffHeader = "diff --git a/FOO b/FOO\n" // + + "new file mode " + REGULAR_FILE + "\n" + + "index " + + ObjectId.zeroId().abbreviate(8).name() + + ".." + + adId.abbreviate(8).name() + "\n" // + + "--- /dev/null\n"// + + "+++ b/FOO\n"; + assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer())); + + assertEquals(0, fh.getStartOffset()); + assertEquals(fh.getBuffer().length, fh.getEndOffset()); + assertEquals(FileHeader.PatchType.UNIFIED, fh.getPatchType()); + + assertEquals(1, fh.getHunks().size()); + + HunkHeader hh = fh.getHunks().get(0); + assertEquals(1, hh.toEditList().size()); + + EditList el = hh.toEditList(); + assertEquals(1, el.size()); + + Edit e = el.get(0); + assertEquals(0, e.getBeginA()); + assertEquals(0, e.getEndA()); + assertEquals(0, e.getBeginB()); + assertEquals(2, e.getEndB()); + assertEquals(Edit.Type.INSERT, e.getType()); + } + + public void testCreateFileHeader_Delete() throws Exception { + ObjectId adId = blob("a\nd\n"); + DiffEntry ent = DiffEntry.delete("FOO", adId); + FileHeader fh = df.createFileHeader(ent); + + String diffHeader = "diff --git a/FOO b/FOO\n" // + + "deleted file mode " + REGULAR_FILE + "\n" + + "index " + + adId.abbreviate(8).name() + + ".." + + ObjectId.zeroId().abbreviate(8).name() + "\n" // + + "--- a/FOO\n"// + + "+++ /dev/null\n"; + assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer())); + + assertEquals(0, fh.getStartOffset()); + assertEquals(fh.getBuffer().length, fh.getEndOffset()); + assertEquals(FileHeader.PatchType.UNIFIED, fh.getPatchType()); + + assertEquals(1, fh.getHunks().size()); + + HunkHeader hh = fh.getHunks().get(0); + assertEquals(1, hh.toEditList().size()); + + EditList el = hh.toEditList(); + assertEquals(1, el.size()); + + Edit e = el.get(0); + assertEquals(0, e.getBeginA()); + assertEquals(2, e.getEndA()); + assertEquals(0, e.getBeginB()); + assertEquals(0, e.getEndB()); + assertEquals(Edit.Type.DELETE, e.getType()); + } + public void testCreateFileHeader_Modify() throws Exception { ObjectId adId = blob("a\nd\n"); ObjectId abcdId = blob("a\nb\nc\nd\n"); |