-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_test.go
105 lines (101 loc) · 1.62 KB
/
key_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
package tcellterm
import (
"testing"
"github.com/gdamore/tcell/v2"
"github.com/stretchr/testify/assert"
)
func TestKey(t *testing.T) {
tests := []struct {
name string
event *tcell.EventKey
expected string
}{
{
name: "rune",
event: tcell.NewEventKey(
tcell.KeyRune,
'j',
tcell.ModNone,
),
expected: "j",
},
{
name: "F1",
event: tcell.NewEventKey(
tcell.KeyF1,
0,
tcell.ModNone,
),
expected: "\x1bOP",
},
{
name: "Shift-right",
event: tcell.NewEventKey(
tcell.KeyRight,
0,
tcell.ModShift,
),
expected: "\x1b[1;2C",
},
{
name: "Ctrl-Shift-right",
event: tcell.NewEventKey(
tcell.KeyRight,
0,
tcell.ModShift|tcell.ModCtrl,
),
expected: "\x1b[1;6C",
},
{
name: "Alt-Shift-right",
event: tcell.NewEventKey(
tcell.KeyRight,
0,
tcell.ModShift|tcell.ModAlt,
),
expected: "\x1b[1;4C",
},
{
name: "rune + mod alt",
event: tcell.NewEventKey(
tcell.KeyRune,
'j',
tcell.ModAlt,
),
expected: "\x1Bj",
},
{
name: "rune + mod ctrl",
event: tcell.NewEventKey(
tcell.KeyCtrlJ,
0x0A,
tcell.ModCtrl,
),
expected: "\n",
},
{
name: "shift + f5",
event: tcell.NewEventKey(
tcell.KeyF5,
0,
tcell.ModShift,
),
expected: "\x1B[15;2~",
},
{
name: "shift + arrow",
event: tcell.NewEventKey(
tcell.KeyRight,
0,
tcell.ModShift,
),
expected: "\x1B[1;2C",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := keyCode(test.event)
assert.Equal(t, test.expected, actual)
})
}
}