diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2021-08-03 21:38:03 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2021-08-03 21:42:14 +0900 |
commit | 4f66093335e5a0d370cf43b3fc637c0795376334 (patch) | |
tree | 0f71e0ee748ff19133f5545492a4ddeb7f5f35b7 /pkg/commands/files_test.go | |
parent | d626bcac0029267d3f45223198902f5cb78d9dc1 (diff) |
introduce edit command template to open a specifig line of a file
Diffstat (limited to 'pkg/commands/files_test.go')
-rw-r--r-- | pkg/commands/files_test.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index fd4b9f69f..46ccda947 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -742,6 +742,7 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) { func TestEditFileCmdStr(t *testing.T) { type scenario struct { filename string + configEditor string configEditCommand string command func(string, ...string) *exec.Cmd getenv func(string) string @@ -753,6 +754,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { return secureexec.Command("exit", "1") }, @@ -769,6 +771,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "nano", + "{{editor}} {{filename}}", func(name string, args ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -787,6 +790,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -805,6 +809,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -826,6 +831,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -848,6 +854,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -866,6 +873,7 @@ func TestEditFileCmdStr(t *testing.T) { { "file/with space", "", + "{{editor}} {{filename}}", func(name string, args ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -881,14 +889,34 @@ func TestEditFileCmdStr(t *testing.T) { assert.Equal(t, "vi \"file/with space\"", cmdStr) }, }, + { + "open file/at line", + "vim", + "{{editor}} +{{line}} {{filename}}", + func(name string, args ...string) *exec.Cmd { + assert.Equal(t, "which", name) + return secureexec.Command("echo") + }, + func(env string) string { + return "" + }, + func(cf string) (string, error) { + return "", nil + }, + func(cmdStr string, err error) { + assert.NoError(t, err) + assert.Equal(t, "vim +1 \"open file/at line\"", cmdStr) + }, + }, } for _, s := range scenarios { gitCmd := NewDummyGitCommand() + gitCmd.Config.GetUserConfig().OS.Editor = s.configEditor gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand gitCmd.OSCommand.Command = s.command gitCmd.OSCommand.Getenv = s.getenv gitCmd.getGitConfigValue = s.getGitConfigValue - s.test(gitCmd.EditFileCmdStr(s.filename)) + s.test(gitCmd.EditFileCmdStr(s.filename, 1)) } } |