mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-04 20:26:08 +00:00
chore(key): add Matches test
This commit is contained in:
@@ -2,6 +2,8 @@ package key
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
)
|
||||
|
||||
func TestBinding_Enabled(t *testing.T) {
|
||||
@@ -24,3 +26,44 @@ func TestBinding_Enabled(t *testing.T) {
|
||||
t.Errorf("expected key not to be Enabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatches(t *testing.T) {
|
||||
cases := []struct {
|
||||
key tea.KeyMsg
|
||||
bindings []Binding
|
||||
}{
|
||||
{
|
||||
key: tea.KeyPressMsg{Code: 'k', Text: "k"},
|
||||
bindings: []Binding{
|
||||
NewBinding(
|
||||
WithKeys("k", "up"),
|
||||
WithHelp("↑/k", "move up"),
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
key: tea.KeyPressMsg{Code: '/', Mod: tea.ModShift, Text: "?"},
|
||||
bindings: []Binding{
|
||||
NewBinding(
|
||||
WithKeys("?"),
|
||||
WithHelp("?", "search"),
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
key: tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl},
|
||||
bindings: []Binding{
|
||||
NewBinding(
|
||||
WithKeys("ctrl+a"),
|
||||
WithHelp("ctrl+a", "select all"),
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
if !Matches(c.key, c.bindings...) {
|
||||
t.Errorf("case %d: expected key (%q) to match binding(s)", i+1, c.key.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user