-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy patheditor_test.go
66 lines (60 loc) · 1.13 KB
/
editor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"testing"
)
func TestGetEditor(t *testing.T) {
tt := []struct {
Name string
EditorEnv string
Cmd string
Args []string
}{
{
Name: "default",
Cmd: "nano",
},
{
Name: "vim",
EditorEnv: "vim",
Cmd: "vim",
},
{
Name: "vim with flag",
EditorEnv: "vim --foo",
Cmd: "vim",
Args: []string{"--foo"},
},
{
Name: "code",
EditorEnv: "code -w",
Cmd: "code",
Args: []string{"-w"},
},
}
for _, tc := range tt {
t.Run(tc.Name, func(t *testing.T) {
var err error
switch tc.EditorEnv {
case "":
err = os.Unsetenv("EDITOR")
default:
err = os.Setenv("EDITOR", tc.EditorEnv)
}
if err != nil {
t.Logf("could not (un)set env: %v", err)
t.FailNow()
}
cmd, args := getEditor()
if cmd != tc.Cmd {
t.Logf("cmd is incorrect: want %q but got %q", tc.Cmd, cmd)
t.FailNow()
}
if argStr, tcArgStr := fmt.Sprint(args), fmt.Sprint(tc.Args); argStr != tcArgStr {
t.Logf("args are incorrect: want %q but got %q", tcArgStr, argStr)
t.FailNow()
}
})
}
}