-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathkeymap_test.go
More file actions
63 lines (56 loc) · 1.66 KB
/
Copy pathkeymap_test.go
File metadata and controls
63 lines (56 loc) · 1.66 KB
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
package jid
import (
"testing"
termbox "github.com/nsf/termbox-go"
"github.com/stretchr/testify/assert"
)
func TestParseKey(t *testing.T) {
tests := []struct {
input string
expected termbox.Key
ok bool
}{
{"ctrl+j", termbox.KeyCtrlJ, true},
{"ctrl+k", termbox.KeyCtrlK, true},
{"ctrl+a", termbox.KeyCtrlA, true},
{"ctrl+z", termbox.KeyCtrlZ, true},
{"up", termbox.KeyArrowUp, true},
{"down", termbox.KeyArrowDown, true},
{"left", termbox.KeyArrowLeft, true},
{"right", termbox.KeyArrowRight, true},
{"tab", termbox.KeyTab, true},
{"enter", termbox.KeyEnter, true},
{"esc", termbox.KeyEsc, true},
{"backspace", termbox.KeyBackspace2, true},
{"home", termbox.KeyHome, true},
{"end", termbox.KeyEnd, true},
{"pgup", termbox.KeyPgup, true},
{"pgdn", termbox.KeyPgdn, true},
{"f1", termbox.KeyF1, true},
{"f12", termbox.KeyF12, true},
// case insensitive
{"CTRL+J", termbox.KeyCtrlJ, true},
{"UP", termbox.KeyArrowUp, true},
// with whitespace
{" ctrl+j ", termbox.KeyCtrlJ, true},
// invalid
{"invalid", 0, false},
{"ctrl+1", 0, false},
{"", 0, false},
}
for _, tt := range tests {
k, ok := ParseKey(tt.input)
assert.Equal(t, tt.ok, ok, "ParseKey(%q) ok", tt.input)
if tt.ok {
assert.Equal(t, tt.expected, k, "ParseKey(%q) key", tt.input)
}
}
}
func TestResolveKey(t *testing.T) {
// valid configured key
assert.Equal(t, termbox.KeyCtrlJ, resolveKey("ctrl+j", "ctrl+k"))
// invalid configured key → fall back to default
assert.Equal(t, termbox.KeyCtrlK, resolveKey("invalid", "ctrl+k"))
// empty configured key → fall back to default
assert.Equal(t, termbox.KeyArrowUp, resolveKey("", "up"))
}