diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-01-22 17:00:32 +0100 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-03-26 19:53:37 +0100 |
commit | a187d12dd9d44d4af8ae5c7e9ec4923222c2f249 (patch) | |
tree | a700ee3a0e7a97b00380da7d3d12076738d58138 /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java | |
parent | a171360292cedde6f05a40069e36946a8045a6a1 (diff) | |
download | jgit-a187d12dd9d44d4af8ae5c7e9ec4923222c2f249.tar.gz jgit-a187d12dd9d44d4af8ae5c7e9ec4923222c2f249.zip |
CommitConfig: add support for core.commentChar
Provide access to the core.commentChar git config, and provide a
utility method to determine an unused comment character if the setting
is "auto".
Bug: 579325
Change-Id: I1ec7e4deffea6ac5929a8538a624d73bb59e4ecc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java index d95d7814e4..7066f9d422 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java @@ -11,7 +11,10 @@ package org.eclipse.jgit.lib; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.CommitConfig.CleanupMode; @@ -169,6 +172,82 @@ public class CommitConfigTest { CommitConfig.cleanText(message, CleanupMode.SCISSORS, '#')); } + @Test + public void testCommentCharDefault() throws Exception { + CommitConfig cfg = parse(""); + assertEquals('#', cfg.getCommentChar()); + assertFalse(cfg.isAutoCommentChar()); + } + + @Test + public void testCommentCharAuto() throws Exception { + CommitConfig cfg = parse("[core]\n\tcommentChar = auto\n"); + assertEquals('#', cfg.getCommentChar()); + assertTrue(cfg.isAutoCommentChar()); + } + + @Test + public void testCommentCharEmpty() throws Exception { + CommitConfig cfg = parse("[core]\n\tcommentChar =\n"); + assertEquals('#', cfg.getCommentChar()); + } + + @Test + public void testCommentCharInvalid() throws Exception { + CommitConfig cfg = parse("[core]\n\tcommentChar = \" \"\n"); + assertEquals('#', cfg.getCommentChar()); + } + + @Test + public void testCommentCharNonAscii() throws Exception { + CommitConfig cfg = parse("[core]\n\tcommentChar = รถ\n"); + assertEquals('#', cfg.getCommentChar()); + } + + @Test + public void testCommentChar() throws Exception { + CommitConfig cfg = parse("[core]\n\tcommentChar = _\n"); + assertEquals('_', cfg.getCommentChar()); + } + + @Test + public void testDetermineCommentChar() throws Exception { + String text = "A commit message\n\nBody\n"; + assertEquals('#', CommitConfig.determineCommentChar(text)); + } + + @Test + public void testDetermineCommentChar2() throws Exception { + String text = "A commit message\n\nBody\n\n# Conflicts:\n#\tfoo.txt\n"; + char ch = CommitConfig.determineCommentChar(text); + assertNotEquals('#', ch); + assertTrue(ch > ' ' && ch < 127); + } + + @Test + public void testDetermineCommentChar3() throws Exception { + String text = "A commit message\n\n;Body\n\n# Conflicts:\n#\tfoo.txt\n"; + char ch = CommitConfig.determineCommentChar(text); + assertNotEquals('#', ch); + assertNotEquals(';', ch); + assertTrue(ch > ' ' && ch < 127); + } + + @Test + public void testDetermineCommentChar4() throws Exception { + String text = "A commit message\n\nBody\n\n # Conflicts:\n\t #\tfoo.txt\n"; + char ch = CommitConfig.determineCommentChar(text); + assertNotEquals('#', ch); + assertTrue(ch > ' ' && ch < 127); + } + + @Test + public void testDetermineCommentChar5() throws Exception { + String text = "A commit message\n\nBody\n\n#a\n;b\n@c\n!d\n$\n%\n^\n&\n|\n:"; + char ch = CommitConfig.determineCommentChar(text); + assertEquals(0, ch); + } + private static CommitConfig parse(String content) throws ConfigInvalidException { Config c = new Config(); |