-
Notifications
You must be signed in to change notification settings - Fork 230
/
key_test.go
44 lines (38 loc) · 896 Bytes
/
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
package key
import (
"testing"
tea "github.com/charmbracelet/bubbletea"
)
func TestBinding_Enabled(t *testing.T) {
binding := NewBinding(
WithKeys("k", "up"),
WithHelp("↑/k", "move up"),
)
if !binding.Enabled() {
t.Errorf("expected key to be Enabled")
}
binding.SetEnabled(false)
if binding.Enabled() {
t.Errorf("expected key not to be Enabled")
}
binding.SetEnabled(true)
binding.Unbind()
if binding.Enabled() {
t.Errorf("expected key not to be Enabled")
}
}
func BenchmarkMatches(b *testing.B) {
msg1 := tea.KeyMsg(tea.Key{Type: tea.KeyRunes, Runes: []rune("c"), Alt: true})
msg2 := tea.KeyMsg(tea.Key{Type: tea.KeyEnter})
kb := NewBinding(WithKeys("alt+c"))
b.Run("success", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Matches(msg1, kb)
}
})
b.Run("fail", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Matches(msg2, kb)
}
})
}