summaryrefslogtreecommitdiffstats
path: root/pkg/commands/files_test.go
diff options
context:
space:
mode:
authorDerTeta <derteta@gmx.de>2021-08-21 21:14:35 +0200
committerJesse Duffield <jessedduffield@gmail.com>2021-12-06 22:37:28 +1100
commit14d9e776be401ffc6d27cf4ef9f21a41cd203f41 (patch)
treebd0d1fc5edd788699b3b12187caea66b8f1a4a8e /pkg/commands/files_test.go
parentca88620e8fd68df4cec86007679665ccdda5c0e7 (diff)
Use `DiffContextSize` in `ShowFileDiffStr`
Diffstat (limited to 'pkg/commands/files_test.go')
-rw-r--r--pkg/commands/files_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go
index acbdde8cc..a16c52a7d 100644
--- a/pkg/commands/files_test.go
+++ b/pkg/commands/files_test.go
@@ -441,6 +441,59 @@ func TestGitCommandDiff(t *testing.T) {
}
}
+// TestGitCommandShowFileDiff is a function.
+func TestGitCommandShowFileDiff(t *testing.T) {
+ type scenario struct {
+ testName string
+ command func(string, ...string) *exec.Cmd
+ from string
+ to string
+ reverse bool
+ plain bool
+ contextSize int
+ }
+
+ scenarios := []scenario{
+ {
+ "Default case",
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, args)
+
+ return secureexec.Command("echo")
+ },
+ "1234567890",
+ "0987654321",
+ false,
+ false,
+ 3,
+ },
+ {
+ "Show diff with custom context size",
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=123", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, args)
+
+ return secureexec.Command("echo")
+ },
+ "1234567890",
+ "0987654321",
+ false,
+ false,
+ 123,
+ },
+ }
+
+ for _, s := range scenarios {
+ t.Run(s.testName, func(t *testing.T) {
+ gitCmd := NewDummyGitCommand()
+ gitCmd.OSCommand.Command = s.command
+ gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
+ gitCmd.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
+ })
+ }
+}
+
// TestGitCommandCheckoutFile is a function.
func TestGitCommandCheckoutFile(t *testing.T) {
type scenario struct {