-
Notifications
You must be signed in to change notification settings - Fork 21
/
cmd_test.go
80 lines (76 loc) · 1.71 KB
/
cmd_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
package ts3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCmd(t *testing.T) {
tests := map[string]struct {
cmd *Cmd
expect string
}{
"cmd": {
NewCmd("version"),
"version",
},
"arg": {
NewCmd("use").
WithArgs(NewArg("sid", 1)),
"use sid=1",
},
"args": {
NewCmd("use").
WithArgs(NewArg("sid", 1), NewArg("port", 1234)),
"use sid=1 port=1234",
},
"args-option": {
NewCmd("use").
WithArgs(NewArg("sid", 1), NewArg("port", 1234)).
WithOptions("-virtual"),
"use sid=1 port=1234 -virtual",
},
"options": {
NewCmd("serverlist").
WithOptions("-uid", "-short"),
"serverlist -uid -short",
},
"arg-group-single": {
NewCmd("servergroupdelperm").
WithArgs(
NewArg("sgid", 1),
NewArgGroup(NewArg("permid", 1), NewArg("permid", 2)),
),
"servergroupdelperm sgid=1 permid=1|permid=2",
},
"arg-group-multi": {
NewCmd("servergroupaddperm").
WithArgs(
NewArg("sgid", 1),
NewArgGroup(
NewArgSet(
NewArg("permid", 1),
NewArg("permvalue", 1),
NewArg("permnegated", 0),
NewArg("permskip", 0),
),
NewArgSet(
NewArg("permid", 2),
NewArg("permvalue", 2),
NewArg("permnegated", 1),
NewArg("permskip", 1),
),
),
),
"servergroupaddperm sgid=1 permid=1 permvalue=1 permnegated=0 permskip=0|permid=2 permvalue=2 permnegated=1 permskip=1",
},
"escaped-chars": {
NewCmd("servergroupadd").
WithArgs(NewArg("name", "Chars:\\/ |\a\b\f\n\r\t\v")),
`servergroupadd name=Chars:\\\/\s\p\a\b\f\n\r\t\v`,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.expect+"\n", tc.cmd.String())
})
}
}