diff options
author | André de Oliveira <andre.oliveira@liferay.com> | 2014-09-10 16:02:05 -0300 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-03-27 20:42:49 -0400 |
commit | 3cd7d0d85a5fe6ba03f218898e866f06258b7405 (patch) | |
tree | 2c8ba29714cb14a38a35bc0a3fa2d4c71a582a8e /org.eclipse.jgit.test/tst | |
parent | a5c40a38622db55d323084f766f0bf50a5299765 (diff) | |
download | jgit-3cd7d0d85a5fe6ba03f218898e866f06258b7405.tar.gz jgit-3cd7d0d85a5fe6ba03f218898e866f06258b7405.zip |
Do not add a newline at the end if neither merged side had one
Bug: 390833
Change-Id: I29f7b79b241929877c93ac485c677487a91bb77b
Signed-off-by: André de Oliveira <andre.oliveira@liferay.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java | 60 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java | 6 |
2 files changed, 54 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java index 8a33425b1d..d4a3d62dad 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java @@ -51,11 +51,25 @@ import java.io.IOException; import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.lib.Constants; +import org.junit.Assume; import org.junit.Test; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.runner.RunWith; +@RunWith(Theories.class) public class MergeAlgorithmTest { MergeFormatter fmt=new MergeFormatter(); + private final boolean newlineAtEnd; + + @DataPoints + public static boolean[] newlineAtEndDataPoints = { false, true }; + + public MergeAlgorithmTest(boolean newlineAtEnd) { + this.newlineAtEnd = newlineAtEnd; + } + /** * Check for a conflict where the second text was changed similar to the * first one, but the second texts modification covers one more line. @@ -174,28 +188,55 @@ public class MergeAlgorithmTest { } @Test - public void testSeperateModifications() throws IOException { + public void testSeparateModifications() throws IOException { assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe")); } + @Test + public void testBlankLines() throws IOException { + assertEquals(t("aZc\nYe"), merge("abc\nde", "aZc\nde", "abc\nYe")); + } + /** * Test merging two contents which do one similar modification and one - * insertion is only done by one side. Between modification and insertion is - * a block which is common between the two contents and the common base + * insertion is only done by one side, in the middle. Between modification + * and insertion is a block which is common between the two contents and the + * common base * * @throws IOException */ @Test public void testTwoSimilarModsAndOneInsert() throws IOException { - assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ")); assertEquals(t("aBcDde"), merge("abcde", "aBcde", "aBcDde")); - assertEquals(t("IAJ"), merge("iA", "IA", "IAJ")); - assertEquals(t("IAAAJ"), merge("iA", "IA", "IAAAJ")); assertEquals(t("IAAAJCAB"), merge("iACAB", "IACAB", "IAAAJCAB")); assertEquals(t("HIAAAJCAB"), merge("HiACAB", "HIACAB", "HIAAAJCAB")); assertEquals(t("AGADEFHIAAAJCAB"), merge("AGADEFHiACAB", "AGADEFHIACAB", "AGADEFHIAAAJCAB")); + } + /** + * Test merging two contents which do one similar modification and one + * insertion is only done by one side, at the end. Between modification and + * insertion is a block which is common between the two contents and the + * common base + * + * @throws IOException + */ + @Test + public void testTwoSimilarModsAndOneInsertAtEnd() throws IOException { + Assume.assumeTrue(newlineAtEnd); + assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ")); + assertEquals(t("IAJ"), merge("iA", "IA", "IAJ")); + assertEquals(t("IAAAJ"), merge("iA", "IA", "IAAAJ")); + } + + @Test + public void testTwoSimilarModsAndOneInsertAtEndNoNewlineAtEnd() + throws IOException { + Assume.assumeFalse(newlineAtEnd); + assertEquals(t("I<A=AAJ>"), merge("iA", "IA", "IAAJ")); + assertEquals(t("I<A=AJ>"), merge("iA", "IA", "IAJ")); + assertEquals(t("I<A=AAAJ>"), merge("iA", "IA", "IAAAJ")); } /** @@ -225,7 +266,7 @@ public class MergeAlgorithmTest { return new String(bo.toByteArray(), Constants.CHARACTER_ENCODING); } - public static String t(String text) { + public String t(String text) { StringBuilder r = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); @@ -241,13 +282,14 @@ public class MergeAlgorithmTest { break; default: r.append(c); - r.append('\n'); + if (newlineAtEnd || i < text.length() - 1) + r.append('\n'); } } return r.toString(); } - public static RawText T(String text) { + public RawText T(String text) { return new RawText(Constants.encode(t(text))); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java index dd06168c30..478a93b770 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java @@ -184,7 +184,7 @@ public class ResolveMergerTest extends RepositoryTestCase { MergeResult mergeRes = git.merge().setStrategy(strategy) .include(masterCommit).call(); assertEquals(MergeStatus.MERGED, mergeRes.getMergeStatus()); - assertEquals("[d/1, mode:100644, content:1master\n2\n3side\n]", + assertEquals("[d/1, mode:100644, content:1master\n2\n3side]", indexState(CONTENT)); } @@ -561,7 +561,7 @@ public class ResolveMergerTest extends RepositoryTestCase { assertEquals(MergeStrategy.RECURSIVE, strategy); assertEquals(MergeResult.MergeStatus.MERGED, mergeResult.getMergeStatus()); - assertEquals("1master2\n2\n3side2\n", read("1")); + assertEquals("1master2\n2\n3side2", read("1")); } catch (JGitInternalException e) { assertEquals(MergeStrategy.RESOLVE, strategy); assertTrue(e.getCause() instanceof NoMergeBaseException); @@ -697,7 +697,7 @@ public class ResolveMergerTest extends RepositoryTestCase { assertEquals( "[0, mode:100644, content:master]" // + "[1, mode:100644, content:side]" // - + "[2, mode:100644, content:1master\n2\n3side\n]" // + + "[2, mode:100644, content:1master\n2\n3side]" // + "[3, mode:100644, stage:1, content:orig][3, mode:100644, stage:2, content:side][3, mode:100644, stage:3, content:master]" // + "[4, mode:100644, content:orig]", // indexState(CONTENT)); |