-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
defaultActions_test.go
68 lines (61 loc) · 1.67 KB
/
defaultActions_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
67
68
package carapace
import (
"strings"
"testing"
"github.com/spf13/cobra"
)
func TestActionImport(t *testing.T) {
s := `
{
"version": "unknown",
"nospace": "",
"values": [
{
"value": "positional1",
"display": "positional1",
"description": "",
"style": "",
"tag": "first"
},
{
"value": "p1",
"display": "p1",
"description": "",
"style": "",
"tag": "first"
}
]
}`
assertEqual(t, ActionValues("positional1", "p1").Tag("first").Invoke(Context{}), ActionImport([]byte(s)).Invoke(Context{}))
}
func TestActionFlags(t *testing.T) {
cmd := &cobra.Command{}
cmd.Flags().BoolP("alpha", "a", false, "")
cmd.Flags().BoolP("beta", "b", false, "")
cmd.Flag("alpha").Changed = true
a := actionFlags(cmd).Invoke(Context{Value: "-a"})
assertEqual(t, ActionValuesDescribed("b", "", "h", "help for this command").Tag("flags").NoSpace().Invoke(Context{}).Prefix("-a"), a)
}
func TestActionExecCommandEnv(t *testing.T) {
ActionExecCommand("env")(func(output []byte) Action {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.Contains(line, "carapace_TestActionExecCommand") {
t.Error("should not contain env carapace_TestActionExecCommand")
}
}
return ActionValues()
}).Invoke(Context{})
c := Context{}
c.Setenv("carapace_TestActionExecCommand", "test")
ActionExecCommand("env")(func(output []byte) Action {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if line == "carapace_TestActionExecCommand=test" {
return ActionValues()
}
}
t.Error("should contain env carapace_TestActionExecCommand=test")
return ActionValues()
}).Invoke(c)
}