-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg_test.go
91 lines (84 loc) · 2.06 KB
/
arg_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"testing"
a "github.com/bayashi/actually"
)
const RULE = "irir_test_rule"
const DEFAULT_RULE = RULE + "_default"
func TestGetDefaultRule(t *testing.T) {
t.Setenv(ENV_KEY_IRIR_DEFAULT_RULE, RULE)
a.Got(getDefaultRule()).Expect(RULE).Same(t)
}
func TestTargetRule(t *testing.T) {
for name, tt := range map[string]struct {
args []string
expect string
}{
"no arg, then set default rule": {
args: []string{},
expect: DEFAULT_RULE,
},
"blank arg, then set default rule": {
args: []string{""},
expect: DEFAULT_RULE,
},
"just one normal rule": {
args: []string{RULE},
expect: RULE,
},
"just one normal rule with wrap command": {
args: []string{RULE, "--", "ls", "-lah"},
expect: RULE,
},
"no rule with wrap command, then set default rule": {
args: []string{"--", "ls", "-lah"},
expect: DEFAULT_RULE,
},
"blank rule with wrap command, then set default rule": {
args: []string{"", "--", "ls", "-lah"},
expect: DEFAULT_RULE,
},
} {
t.Setenv(ENV_KEY_IRIR_DEFAULT_RULE, DEFAULT_RULE)
t.Run(name, func(t *testing.T) {
o := &options{}
o.targetRule(tt.args)
a.Got(o.rule).Expect(tt.expect).Same(t)
})
}
}
func TestSetWrapCommand(t *testing.T) {
for name, tt := range map[string]struct {
args []string
expectCmdName string
expectCmdArgs []string
}{
"no wrap command": {
args: []string{},
expectCmdName: "",
expectCmdArgs: nil,
},
"no wrap command, just only rule": {
args: []string{"rule"},
expectCmdName: "",
expectCmdArgs: nil,
},
"wrap command with rule": {
args: []string{"rule", "--", "ls", "-la"},
expectCmdName: "ls",
expectCmdArgs: []string{"-la"},
},
"wrap command without rule": {
args: []string{"--", "ls", "-la"},
expectCmdName: "ls",
expectCmdArgs: []string{"-la"},
},
} {
t.Run(name, func(t *testing.T) {
o := &options{}
o.setWrapCommand(tt.args)
a.Got(o.wrapCmdName).Expect(tt.expectCmdName).Same(t)
a.Got(o.wrapCmdArgs).Expect(tt.expectCmdArgs).Same(t)
})
}
}