diff options
author | Robin Jarry <robin@jarry.cc> | 2022-09-25 21:29:05 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-16 16:11:50 +0100 |
commit | 5109f8369db9c55684b3be76809627172b4a11e1 (patch) | |
tree | fcc10a960dcc5562756f52b940f9cbfc9af2d7c5 /config/binds_test.go | |
parent | b1e67ed16a6033d944c6e47c28d076b00868604c (diff) | |
download | aerc-5109f8369db9c55684b3be76809627172b4a11e1.tar.gz |
config: rename bindings -> binds
For consistency with binds.conf
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'config/binds_test.go')
-rw-r--r-- | config/binds_test.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/config/binds_test.go b/config/binds_test.go new file mode 100644 index 00000000..dab3b9f1 --- /dev/null +++ b/config/binds_test.go @@ -0,0 +1,76 @@ +package config + +import ( + "fmt" + "testing" + + "github.com/gdamore/tcell/v2" + "github.com/stretchr/testify/assert" +) + +func TestGetBinding(t *testing.T) { + assert := assert.New(t) + + bindings := NewKeyBindings() + add := func(binding, cmd string) { + b, _ := ParseBinding(binding, cmd) + bindings.Add(b) + } + + add("abc", ":abc") + add("cba", ":cba") + add("foo", ":foo") + add("bar", ":bar") + + test := func(input []KeyStroke, result int, output string) { + _output, _ := ParseKeyStrokes(output) + r, out := bindings.GetBinding(input) + assert.Equal(result, int(r), fmt.Sprintf( + "%s: Expected result %d, got %d", output, result, r)) + assert.Equal(_output, out, fmt.Sprintf( + "%s: Expected output %v, got %v", output, _output, out)) + } + + test([]KeyStroke{ + {tcell.ModNone, tcell.KeyRune, 'a'}, + }, BINDING_INCOMPLETE, "") + test([]KeyStroke{ + {tcell.ModNone, tcell.KeyRune, 'a'}, + {tcell.ModNone, tcell.KeyRune, 'b'}, + {tcell.ModNone, tcell.KeyRune, 'c'}, + }, BINDING_FOUND, ":abc") + test([]KeyStroke{ + {tcell.ModNone, tcell.KeyRune, 'c'}, + {tcell.ModNone, tcell.KeyRune, 'b'}, + {tcell.ModNone, tcell.KeyRune, 'a'}, + }, BINDING_FOUND, ":cba") + test([]KeyStroke{ + {tcell.ModNone, tcell.KeyRune, 'f'}, + {tcell.ModNone, tcell.KeyRune, 'o'}, + }, BINDING_INCOMPLETE, "") + test([]KeyStroke{ + {tcell.ModNone, tcell.KeyRune, '4'}, + {tcell.ModNone, tcell.KeyRune, '0'}, + {tcell.ModNone, tcell.KeyRune, '4'}, + }, BINDING_NOT_FOUND, "") + + add("<C-a>", "c-a") + add("<C-Down>", ":next") + add("<C-PgUp>", ":prev") + add("<C-Enter>", ":open") + test([]KeyStroke{ + {tcell.ModCtrl, tcell.KeyCtrlA, 0}, + }, BINDING_FOUND, "c-a") + test([]KeyStroke{ + {tcell.ModCtrl, tcell.KeyDown, 0}, + }, BINDING_FOUND, ":next") + test([]KeyStroke{ + {tcell.ModCtrl, tcell.KeyPgUp, 0}, + }, BINDING_FOUND, ":prev") + test([]KeyStroke{ + {tcell.ModCtrl, tcell.KeyPgDn, 0}, + }, BINDING_NOT_FOUND, "") + test([]KeyStroke{ + {tcell.ModCtrl, tcell.KeyEnter, 0}, + }, BINDING_FOUND, ":open") +} |