-
Notifications
You must be signed in to change notification settings - Fork 22
/
command_test.go
62 lines (58 loc) · 1.02 KB
/
command_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
package main
import "testing"
var findCommandTests = []struct {
in string
out string
}{
{"pref", "pref"},
{"prefixs", "prefixsuffix"},
{"prefix", ""},
{"suffixes", ""},
{"prefixd", "prefixdiffsuffix"},
}
func TestFindCommand(t *testing.T) {
bk := WaptyCommands
defer func() { WaptyCommands = bk }()
var out string
WaptyCommands = []*Command{
{
Name: "prefixsuffix",
Run: func(_ ...string) {
out = "prefixsuffix"
},
},
{
Name: "prefixdiffsuffix",
Run: func(_ ...string) {
out = "prefixdiffsuffix"
},
},
{
Name: "pref",
Run: func(_ ...string) {
out = "pref"
},
},
{
Name: "suffix",
Run: func(_ ...string) {
out = "suffix"
},
},
}
for _, tt := range findCommandTests {
out = ""
c, e := FindCommand(tt.in)
if e != nil {
if tt.out != "" {
t.Errorf("Expected command <%s> but got error: <%s> instead", tt.out, e.Error())
continue
}
continue
}
c.Run()
if tt.out != out {
t.Errorf("Expected <%s> but got <%s>", tt.out, out)
}
}
}