-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
104 lines (89 loc) · 1.67 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
package cuckooc
import (
"reflect"
"testing"
)
func Test_newInstruction(t *testing.T) {
tests := []struct {
cmd string
filter string
action string
args []string
err bool
}{
{
cmd: "test create 1 2 3 4 ",
filter: "test",
action: "create",
args: []string{"1", "2", "3", "4"},
},
{
cmd: "test set x Y z",
filter: "test",
action: "set",
args: []string{"x", "Y", "z"},
},
{
cmd: "test set x Y z",
filter: "test",
action: "set",
args: []string{"x", "Y", "z"},
},
{
cmd: "test set x Y z",
filter: "test",
action: "set",
args: []string{"x", "Y", "z"},
},
{
cmd: "test ",
err: true,
},
}
for _, c := range tests {
i, err := parseCommand(c.cmd, nil)
if err != nil {
if c.err {
continue
}
t.Fatalf("unexpected error: %v", err)
}
if i.Filter != c.filter {
t.Fatalf("expected %s filter but got %s", c.filter, i.Filter)
}
if i.Action != c.action {
t.Fatalf("expected %s action but got %s", c.action, i.Action)
}
if !reflect.DeepEqual(i.Args, c.args) {
t.Fatalf("expected %v args but got %v", c.args, i.Args)
}
}
}
func TestCommand_readCommands(t *testing.T) {
tests := []struct {
s string
ss []string
}{
{
ss: nil,
},
{
s: "test new",
ss: []string{"test new"},
},
{
s: "test new\n test1 set x a b c",
ss: []string{"test new", " test1 set x a b c"},
},
{
s: "test new\ntest1 set x a b c",
ss: []string{"test new", "test1 set x a b c"},
},
}
for _, c := range tests {
ss := readCommands([]byte(c.s))
if !reflect.DeepEqual(c.ss, ss) {
t.Fatalf("expected %v but got %v", c.ss, ss)
}
}
}