2021-04-10 11:40:42 +10:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-12-31 10:24:53 +11:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
2021-04-10 11:40:42 +10:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-02 10:34:33 +11:00
|
|
|
func TestGitCommandStashDrop(t *testing.T) {
|
2021-12-31 10:24:53 +11:00
|
|
|
runner := oscommands.NewFakeRunner(t).
|
2022-01-03 15:15:26 +11:00
|
|
|
ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil)
|
2021-12-31 10:24:53 +11:00
|
|
|
gitCmd := NewDummyGitCommandWithRunner(runner)
|
2021-04-10 11:40:42 +10:00
|
|
|
|
2022-01-02 10:34:33 +11:00
|
|
|
assert.NoError(t, gitCmd.Stash.Drop(1))
|
|
|
|
runner.CheckForMissingCalls()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitCommandStashApply(t *testing.T) {
|
|
|
|
runner := oscommands.NewFakeRunner(t).
|
|
|
|
ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil)
|
|
|
|
gitCmd := NewDummyGitCommandWithRunner(runner)
|
|
|
|
|
|
|
|
assert.NoError(t, gitCmd.Stash.Apply(1))
|
|
|
|
runner.CheckForMissingCalls()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitCommandStashPop(t *testing.T) {
|
|
|
|
runner := oscommands.NewFakeRunner(t).
|
|
|
|
ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil)
|
|
|
|
gitCmd := NewDummyGitCommandWithRunner(runner)
|
|
|
|
|
|
|
|
assert.NoError(t, gitCmd.Stash.Pop(1))
|
2021-12-31 10:24:53 +11:00
|
|
|
runner.CheckForMissingCalls()
|
2021-04-10 11:40:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGitCommandStashSave(t *testing.T) {
|
2021-12-31 10:24:53 +11:00
|
|
|
runner := oscommands.NewFakeRunner(t).
|
2022-01-03 15:15:26 +11:00
|
|
|
ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil)
|
2021-12-31 10:24:53 +11:00
|
|
|
gitCmd := NewDummyGitCommandWithRunner(runner)
|
2021-04-10 11:40:42 +10:00
|
|
|
|
2022-01-02 10:34:33 +11:00
|
|
|
assert.NoError(t, gitCmd.Stash.Save("A stash message"))
|
2021-12-31 10:24:53 +11:00
|
|
|
runner.CheckForMissingCalls()
|
2021-04-10 11:40:42 +10:00
|
|
|
}
|
2021-09-11 00:47:50 +02:00
|
|
|
|
2022-01-05 11:57:32 +11:00
|
|
|
func TestGitCommandShowStashEntryCmdObj(t *testing.T) {
|
2021-09-11 00:47:50 +02:00
|
|
|
type scenario struct {
|
|
|
|
testName string
|
|
|
|
index int
|
|
|
|
contextSize int
|
|
|
|
expected string
|
|
|
|
}
|
|
|
|
|
|
|
|
scenarios := []scenario{
|
|
|
|
{
|
|
|
|
testName: "Default case",
|
|
|
|
index: 5,
|
|
|
|
contextSize: 3,
|
|
|
|
expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Show diff with custom context size",
|
|
|
|
index: 5,
|
|
|
|
contextSize: 77,
|
|
|
|
expected: "git stash show -p --stat --color=always --unified=77 stash@{5}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
t.Run(s.testName, func(t *testing.T) {
|
|
|
|
gitCmd := NewDummyGitCommand()
|
2021-12-29 11:41:33 +11:00
|
|
|
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
2022-01-02 10:34:33 +11:00
|
|
|
cmdStr := gitCmd.Stash.ShowStashEntryCmdObj(s.index).ToString()
|
2021-09-11 00:47:50 +02:00
|
|
|
assert.Equal(t, s.expected, cmdStr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|