generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd_test.go
60 lines (46 loc) · 1.13 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
package traft
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewCmdI64(t *testing.T) {
ta := require.New(t)
ta.Equal(&Cmd{
Op: "foo",
Key: "key",
Value: &Cmd_VI64{3},
}, NewCmdI64("foo", "key", 3))
}
func TestCmd_Interfering(t *testing.T) {
ta := require.New(t)
cases := []struct {
a, b *Cmd
want bool
}{
{nil, nil, false},
{nil, NewCmdI64("bar", "x", 4), false},
{NewCmdI64("foo", "x", 3), NewCmdI64("bar", "x", 4), false},
{NewCmdI64("foo", "x", 3), NewCmdI64("foo", "x", 4), false},
{NewCmdI64("set", "x", 3), NewCmdI64("set", "y", 4), false},
{NewCmdI64("set", "x", 3), NewCmdI64("set", "x", 4), true},
}
for i, c := range cases {
ta.Equal(c.want, c.a.Interfering(c.b), "%d-th: case: %+v", i+1, c)
ta.Equal(c.want, c.b.Interfering(c.a), "%d-th: case: %+v", i+1, c)
}
}
func Test_cstr(t *testing.T) {
ta := require.New(t)
cases := []struct {
input cstr
want *Cmd
}{
{"x=3", NewCmdI64("set", "x", 3)},
{"y=4", NewCmdI64("set", "y", 4)},
{"", nil},
}
for i, c := range cases {
got := c.input.ToCmd()
ta.Equal(c.want, got, "%d-th: case: %+v", i+1, c)
}
}