[JGIT PATCH 09/12] Add test cases for parsing "\ No newline at end of file" style patches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../tst/org/spearce/jgit/patch/PatchTest.java      |   68 ++++++++++++++++++++
 .../jgit/patch/testParse_AddNoNewline.patch        |   20 ++++++
 .../jgit/patch/testParse_FixNoNewline.patch        |   20 ++++++
 3 files changed, 108 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
index c81356b..13eab5f 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
@@ -228,6 +228,74 @@ assertTrue(fh.getNewName().startsWith(
 		assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine());
 	}
 
+	public void testParse_FixNoNewline() throws IOException {
+		final Patch p = parseTestPatchFile();
+		assertEquals(1, p.getFiles().size());
+		assertTrue(p.getErrors().isEmpty());
+
+		final FileHeader f = p.getFiles().get(0);
+
+		assertEquals("a", f.getNewName());
+		assertEquals(252, f.startOffset);
+
+		assertEquals("2e65efe", f.getOldId().name());
+		assertEquals("f2ad6c7", f.getNewId().name());
+		assertSame(FileHeader.PatchType.UNIFIED, f.getPatchType());
+		assertSame(FileMode.REGULAR_FILE, f.getOldMode());
+		assertSame(FileMode.REGULAR_FILE, f.getNewMode());
+		assertEquals(1, f.getHunks().size());
+		{
+			final HunkHeader h = f.getHunks().get(0);
+			assertSame(f, h.getFileHeader());
+			assertEquals(317, h.startOffset);
+			assertEquals(1, h.getOldImage().getStartLine());
+			assertEquals(1, h.getOldImage().getLineCount());
+			assertEquals(1, h.getNewStartLine());
+			assertEquals(1, h.getNewLineCount());
+
+			assertEquals(0, h.getLinesContext());
+			assertEquals(1, h.getOldImage().getLinesAdded());
+			assertEquals(1, h.getOldImage().getLinesDeleted());
+			assertSame(f.getOldId(), h.getOldImage().getId());
+
+			assertEquals(363, h.endOffset);
+		}
+	}
+
+	public void testParse_AddNoNewline() throws IOException {
+		final Patch p = parseTestPatchFile();
+		assertEquals(1, p.getFiles().size());
+		assertTrue(p.getErrors().isEmpty());
+
+		final FileHeader f = p.getFiles().get(0);
+
+		assertEquals("a", f.getNewName());
+		assertEquals(256, f.startOffset);
+
+		assertEquals("f2ad6c7", f.getOldId().name());
+		assertEquals("c59d9b6", f.getNewId().name());
+		assertSame(FileHeader.PatchType.UNIFIED, f.getPatchType());
+		assertSame(FileMode.REGULAR_FILE, f.getOldMode());
+		assertSame(FileMode.REGULAR_FILE, f.getNewMode());
+		assertEquals(1, f.getHunks().size());
+		{
+			final HunkHeader h = f.getHunks().get(0);
+			assertSame(f, h.getFileHeader());
+			assertEquals(321, h.startOffset);
+			assertEquals(1, h.getOldImage().getStartLine());
+			assertEquals(1, h.getOldImage().getLineCount());
+			assertEquals(1, h.getNewStartLine());
+			assertEquals(1, h.getNewLineCount());
+
+			assertEquals(0, h.getLinesContext());
+			assertEquals(1, h.getOldImage().getLinesAdded());
+			assertEquals(1, h.getOldImage().getLinesDeleted());
+			assertSame(f.getOldId(), h.getOldImage().getId());
+
+			assertEquals(367, h.endOffset);
+		}
+	}
+
 	private Patch parseTestPatchFile() throws IOException {
 		final String patchFile = getName() + ".patch";
 		final InputStream in = getClass().getResourceAsStream(patchFile);
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch
new file mode 100644
index 0000000..3060952
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch
@@ -0,0 +1,20 @@
+From ca4719a4b2d93a469f61d1ddfb3e39ecbabfcd69 Mon Sep 17 00:00:00 2001
+From: Shawn O. Pearce <sop@xxxxxxxxxx>
+Date: Fri, 12 Dec 2008 12:35:14 -0800
+Subject: [PATCH] introduce no lf again
+
+---
+ a |    2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/a b/a
+index f2ad6c7..c59d9b6 100644
+--- a/a
++++ b/a
+@@ -1 +1 @@
+-c
++d
+\ No newline at end of file
+-- 
+1.6.1.rc2.306.ge5d5e
+
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch
new file mode 100644
index 0000000..e8af2e7
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch
@@ -0,0 +1,20 @@
+From 1beb3ec1fe68ff18b0287396096442e12c34787a Mon Sep 17 00:00:00 2001
+From: Shawn O. Pearce <sop@xxxxxxxxxx>
+Date: Fri, 12 Dec 2008 12:29:45 -0800
+Subject: [PATCH] make c and add lf
+
+---
+ a |    2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/a b/a
+index 2e65efe..f2ad6c7 100644
+--- a/a
++++ b/a
+@@ -1 +1 @@
+-a
+\ No newline at end of file
++c
+-- 
+1.6.1.rc2.306.ge5d5e
+
-- 
1.6.1.rc2.306.ge5d5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux