aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/patch_test.go
diff options
context:
space:
mode:
authornodivbyzero <nodivbyzero@gmail.com>2023-12-15 07:04:28 -0800
committernodivbyzero <nodivbyzero@gmail.com>2024-03-11 13:21:50 -0700
commitd058d588e5f7078c44ba42cfd7d2af61e58c2856 (patch)
tree62c74d11974519a5da5fa6483b6da06a47c3c0d4 /plumbing/object/patch_test.go
parent02bed284891e49ff594354101c897a29af3dbb43 (diff)
downloadgo-git-d058d588e5f7078c44ba42cfd7d2af61e58c2856.tar.gz
plumbing: no panic in printStat function. Fixes #177
Diffstat (limited to 'plumbing/object/patch_test.go')
-rw-r--r--plumbing/object/patch_test.go110
1 files changed, 110 insertions, 0 deletions
diff --git a/plumbing/object/patch_test.go b/plumbing/object/patch_test.go
index 2cff795..e0e63a5 100644
--- a/plumbing/object/patch_test.go
+++ b/plumbing/object/patch_test.go
@@ -45,3 +45,113 @@ func (s *PatchSuite) TestStatsWithSubmodules(c *C) {
c.Assert(err, IsNil)
c.Assert(p, NotNil)
}
+
+func (s *PatchSuite) TestFileStatsString(c *C) {
+ testCases := []struct {
+ description string
+ input FileStats
+ expected string
+ }{
+
+ {
+ description: "no files changed",
+ input: []FileStat{},
+ expected: "",
+ },
+ {
+ description: "one file touched - no changes",
+ input: []FileStat{
+ {
+ Name: "file1",
+ },
+ },
+ expected: " file1 | 0 \n",
+ },
+ {
+ description: "one file changed",
+ input: []FileStat{
+ {
+ Name: "file1",
+ Addition: 1,
+ },
+ },
+ expected: " file1 | 1 +\n",
+ },
+ {
+ description: "one file changed with one addition and one deletion",
+ input: []FileStat{
+ {
+ Name: ".github/workflows/git.yml",
+ Addition: 1,
+ Deletion: 1,
+ },
+ },
+ expected: " .github/workflows/git.yml | 2 +-\n",
+ },
+ {
+ description: "two files changed",
+ input: []FileStat{
+ {
+ Name: ".github/workflows/git.yml",
+ Addition: 1,
+ Deletion: 1,
+ },
+ {
+ Name: "cli/go-git/go.mod",
+ Addition: 4,
+ Deletion: 4,
+ },
+ },
+ expected: " .github/workflows/git.yml | 2 +-\n cli/go-git/go.mod | 8 ++++----\n",
+ },
+ {
+ description: "three files changed",
+ input: []FileStat{
+ {
+ Name: ".github/workflows/git.yml",
+ Addition: 3,
+ Deletion: 3,
+ },
+ {
+ Name: "worktree.go",
+ Addition: 107,
+ },
+ {
+ Name: "worktree_test.go",
+ Addition: 75,
+ },
+ },
+ expected: " .github/workflows/git.yml | 6 +++---\n" +
+ " worktree.go | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n" +
+ " worktree_test.go | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
+ },
+ {
+ description: "three files changed with deletions and additions",
+ input: []FileStat{
+ {
+ Name: ".github/workflows/git.yml",
+ Addition: 3,
+ Deletion: 3,
+ },
+ {
+ Name: "worktree.go",
+ Addition: 107,
+ Deletion: 217,
+ },
+ {
+ Name: "worktree_test.go",
+ Addition: 75,
+ Deletion: 275,
+ },
+ },
+ expected: " .github/workflows/git.yml | 6 +++---\n" +
+ " worktree.go | 324 ++++++++++++++++++-----------------------------------\n" +
+ " worktree_test.go | 350 ++++++++++++-----------------------------------------\n",
+ },
+ }
+
+ for _, tc := range testCases {
+ c.Log("Executing test cases:", tc.description)
+ c.Assert(printStat(tc.input), Equals, tc.expected)
+ }
+}