diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-15 01:12:06 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-15 01:31:23 -0400 |
commit | 8d20e9218ece5927d786d6e2fac5c50572fb9c81 (patch) | |
tree | e4cdf0ba821dccbb510f169c7731ae78ce987830 /config/bindings_test.go | |
parent | d274bf926c79ec834afcac00dab3f95f8bd5325f (diff) | |
download | aerc-8d20e9218ece5927d786d6e2fac5c50572fb9c81.tar.gz |
Implement key bindings subsystem
Which is not yet rigged up
Diffstat (limited to 'config/bindings_test.go')
-rw-r--r-- | config/bindings_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/config/bindings_test.go b/config/bindings_test.go new file mode 100644 index 00000000..1d1cbfe2 --- /dev/null +++ b/config/bindings_test.go @@ -0,0 +1,61 @@ +package config + +import ( + "fmt" + "testing" + + "github.com/gdamore/tcell" + "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.KeyRune, 'a'}, + }, BINDING_INCOMPLETE, "") + test([]KeyStroke{ + {tcell.KeyRune, 'a'}, + {tcell.KeyRune, 'b'}, + {tcell.KeyRune, 'c'}, + }, BINDING_FOUND, ":abc") + test([]KeyStroke{ + {tcell.KeyRune, 'c'}, + {tcell.KeyRune, 'b'}, + {tcell.KeyRune, 'a'}, + }, BINDING_FOUND, ":cba") + test([]KeyStroke{ + {tcell.KeyRune, 'f'}, + {tcell.KeyRune, 'o'}, + }, BINDING_INCOMPLETE, "") + test([]KeyStroke{ + {tcell.KeyRune, '4'}, + {tcell.KeyRune, '0'}, + {tcell.KeyRune, '4'}, + }, BINDING_NOT_FOUND, "") + + add("<C-a>", "c-a") + test([]KeyStroke{ + {tcell.KeyCtrlA, 0}, + }, BINDING_FOUND, "c-a") +} |