-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_test.go
133 lines (126 loc) · 2.51 KB
/
event_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package nyne
import (
"fmt"
"testing"
"9fans.net/go/acme"
)
func TestBuiltin(t *testing.T) {
testCases := []struct {
given []byte
expected Text
}{
{[]byte("New"), New},
{[]byte("Zerox"), Zerox},
{[]byte("Get"), Get},
{[]byte("Put"), Put},
{[]byte("Del"), Del},
{[]byte("bla"), "bla"},
}
for _, tc := range testCases {
t.Run(string(tc.given), func(t *testing.T) {
text := NewText(tc.given)
if text != tc.expected {
t.Fatalf("expected text %s, got %s",
tc.expected, text)
}
})
}
}
func TestOrigin(t *testing.T) {
testCases := []struct {
given rune
expected Origin
}{
{0x0, DelOrigin},
{'E', BodyOrTag},
{'F', WindowFiles},
{'K', Keyboard},
{'M', Mouse},
}
for _, tc := range testCases {
t.Run(string(tc.given), func(t *testing.T) {
origin := NewOrigin(tc.given)
if origin != tc.expected {
t.Fatalf("expected origin %d, got %d",
tc.expected, origin)
}
})
}
}
func TestAction(t *testing.T) {
testCases := []struct {
given rune
expected Action
}{
{'D', BodyDelete},
{'d', TagDelete},
{'I', BodyInsert},
{'i', TagInsert},
{'L', B3Body},
{'l', B3Tag},
{'X', B2Body},
{'x', B2Tag},
{0x0, DelAction},
}
for _, tc := range testCases {
t.Run(string(tc.given), func(t *testing.T) {
action := NewAction(tc.given)
if action != tc.expected {
t.Fatalf("expected action '%c', got '%c'",
tc.expected, action)
}
})
}
}
func TestFlag(t *testing.T) {
testCases := []struct {
given int
action Action
expected Flag
}{
{1, B2Body | B2Tag, IsBuiltin},
{2, B2Body | B2Tag, IsNull},
{8, B2Body | B2Tag, HasChordedArg},
{1, B3Body | B3Tag, NoReloadNeeded},
{2, B3Body | B3Tag, PostExpandFollows},
{4, B3Body | B3Tag, IsFileOrWindow},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("action=%d flag=%d", tc.action, tc.given), func(t *testing.T) {
flag := NewFlag(tc.action, tc.given)
if flag != tc.expected {
t.Fatalf("expected flag %d, got %d",
tc.expected, flag)
}
})
}
}
func TestNewEvent(t *testing.T) {
rawEvent := &acme.Event{
C1: 'E',
C2: 'x',
Q0: 0,
Q1: 8,
OrigQ0: 0,
OrigQ1: 0,
Flag: 8,
Nb: 8,
Nr: 0,
Text: []byte("echo"),
Arg: []byte("hello"),
Loc: []byte{},
}
event, err := NewEvent(rawEvent, 1, "/tmp/testfile")
if err != nil {
t.Fatal(err)
}
if event.Origin != BodyOrTag {
t.Fatal(event.Origin)
}
if event.Action != B2Tag {
t.Fatal(event.Action)
}
if event.Flag != HasChordedArg {
t.Fatal(event.Flag)
}
}